-
Notifications
You must be signed in to change notification settings - Fork 861
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
Released pool connections should reset state before being reused #279
Comments
I think there is a bit of a difference between the typical uses Rails ActiveRecord and pgbouncer and the pgx conn pool. AFAIK, ActiveRecord allocates connections on a thread basis, so there are not frequent acquire and release cycles, but in pgx every query called through the pool is a separate acquire/release cycle. pgbouncer is designed for multiple simultaneous applications that logically have different types of connections. but in pgx all connections are logically the same. But I wanted to see if it could be done so I created a proof-of-concept in branch First, we can't use The bigger problem is performance. Running tests with https://github.com/jackc/go_db_bench found that light-weight queries took 3x longer. 60,000ns vs 20,000ns. This was running against localhost. Obviously, the relative overhead would be reduced when doing more work than a single query selecting a single value, but it's quite significant overhead for simple queries. |
The v4 connection pool now supports an after release hook. |
Excellent, thanks! |
@mvrhov I'm not sure if there's a good way for pgx to provide that functionality. If the pool had a Assuming this desired functionality is in the context of a web application, I would probably consider using middleware to acquire a connection, set it up, and make it available for downstream HTTP handlers and release the connection when they return. |
The usual way used by pgpool and pgbouncer is to call
DISCARD ALL
on the connection when it is returned to the pool. ORMs such as ActiveRecord also do this. This is to ensure that cursors, temporary tables etc. are not inherited by the next connection.I see that releasing calls
ROLLBACK
and that listens are also closed, but I don't see any other cleanup. It's worth noting thatDISCARD ALL
includes an internal call equivalent toUNLISTEN *
.The text was updated successfully, but these errors were encountered: