Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rueian/pgbroker
A golang library for building PostgreSQL proxy
https://github.com/rueian/pgbroker
golang pg postgresql protocol proxy
Last synced: 3 months ago
JSON representation
A golang library for building PostgreSQL proxy
- Host: GitHub
- URL: https://github.com/rueian/pgbroker
- Owner: rueian
- License: mit
- Created: 2019-03-03T17:37:29.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-21T14:33:46.000Z (8 months ago)
- Last Synced: 2024-10-14T07:11:48.090Z (4 months ago)
- Topics: golang, pg, postgresql, protocol, proxy
- Language: Go
- Size: 58.6 KB
- Stars: 30
- Watchers: 3
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# pgbroker
pgbroker is a golang library for building PostgreSQL proxy, which makes it easy to support from simple query logging to complex dynamic database mappings from an external resource controller and modification on data transferred between client and pg in streaming or per message manner.
## Usage
### static proxy
One example usage of pgbroker is just simple mapping multiple pg instances into one entry for centralizing management.
Please checkout the https://github.com/rueian/pgbroker-static project.
It is a production ready postgres proxy configured by a yaml file, and it is also has a pre-build docker image.
```shell
docker pull rueian/pgbroker-static:latest
```### dynamic proxy
By implementing the `PGResolver` interface, the proxy is able to acquire different connections based on the client's `StartupMessage`.
```golang
type PGResolver interface {
GetPGConn(ctx context.Context, clientAddr net.Addr, parameters map[string]string) (net.Conn, error)
}
```Please check out the https://github.com/rueian/godemand-example project, which uses godemand as an external http resource controller for dynamic pg mapping.
In this way, the external resource controller is able to do any change to the postgres before connection estiblished, including creating new postgres instance on the fly.
### data modification
pgbroker provides `MessageHandler` and `StreamCallback` for each postgres protocol v3 messages. Developers can use them to easily modify the data transferred between client and pg in streaming or per message manner.
It is useful when implementing such as data obfuscation and permission control.