pgwire
pgwire copied to clipboard
Example of using pgwire as a postgres proxy
Was looking at the examples and there isn't one that actually connects to a real postgres instance in the backend. For example to use pgwire as a proxy to a 'real' postgres server. i.e. maintaining different client sessions and forwarding them to a real postgres instance.
hi @osawyerr , it's possible to write such a proxy but we need to define the purpose of it so we can choose at which layer we will proxy the traffic. For example, we can write a Layer-4 proxy by simply forward any tcp traffic to backend, or a Layer-7 one that understands postgresql's protocol or even sql statements.
If I'm creating a basic Layer-7 example, I will let the proxy to finish the startup and forward further query traffic to backend. I will find time for that.
My vote is for Layer-7. Personally, I'd like to be able to fundamentally understand the request, execute the query, apply transforms to the result rows, then hand them back out.
I'll 3rd the request for a l7 proxy example, @sunng87 . My use case is an auth n/z aware proxy that can make authorization decisions based on the query. Even something as simple as how to connect to a backend postgres and forward/reply messages back and forth.
Let me do this in weekend if everything goes well.
Let me do this in weekend if everything goes well.
Thank you, looking forward to it!
I have an unfinished proxy example that uses tokio_postgres in SimpleQueryHandler
to forward requests to upstream. There is some residual work to convert data format from tokio_postgres
to pgwire
.
However, for a complete proxy solution, we will need to implement tokio layer for using pgwire
data format as client for finer and better control over messages. That's beyond my time budget for this project. I welcome contributors to join the development if you are interested in this feature.
I'll +1 this request.
My use case is to intercept every message and validate incoming queries. I wrote a Python version of this that worked by starting two async tasks, one that listened to the server and pushed to the client and another that listened to the client and pushed to the server. Thus I didn't need any sort of state machine.
We also need this for https://github.com/twentyhq/twenty
I've never tried Replit bounties but thought it could be an occasion to give it a shot... Let's see if it works! https://replit.com/bounties/@felix54/rust-postgres-proxy