Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of using pgwire as a postgres proxy #80

Open
osawyerr opened this issue Apr 18, 2023 · 8 comments
Open

Example of using pgwire as a postgres proxy #80

osawyerr opened this issue Apr 18, 2023 · 8 comments

Comments

@osawyerr
Copy link

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.

@sunng87
Copy link
Owner

sunng87 commented Apr 19, 2023

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.

@lucasyvas
Copy link

lucasyvas commented Oct 28, 2023

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.

@batmilkyway
Copy link

batmilkyway commented Dec 5, 2023

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.

@sunng87
Copy link
Owner

sunng87 commented Dec 5, 2023

Let me do this in weekend if everything goes well.

@batmilkyway
Copy link

Let me do this in weekend if everything goes well.

Thank you, looking forward to it!

@sunng87
Copy link
Owner

sunng87 commented Dec 10, 2023

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.

@adriangb
Copy link

adriangb commented Mar 6, 2024

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.

@FelixMalfait
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants