-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Postgres: DISCARD ALL #73
Comments
Might be nice to have a look at other pooling solutions (r2d2, deadpool, sqlx) and see if/how they support this. (Note that previously we recommended that LISTEN queries should probably be issued on non-pooled connections, through |
PgBouncer has it configurable ( It’s really not about the LISTEN, but all (currently 9) resources this releases. Another nice thing is that it fails if the connection is inside a transaction, so it helps automatically check that you’re closing them correctly. I think it needs to be configurable, otherwise you loose the ability to share use prepared statements etc. Choose your own isolation level... |
I was referring mostly to Rust crates. I'm unlikely to have time for this any time soon unless someone is willing to pay for it. Will review hooks for this in the connection manager trait, though. |
Yes, I think hooks are key rather than supporting every single possible reset query. Then one can subclass the postgres manager and do what they want. |
#89 added a way to customize connections at the start of the lifetime rather than the end, which should help with this. |
Issue djc#73 was looking to make a "DISCARD ALL" query possible when a connection is returned to the pool. Because async drop isn't a thing, this isn't really possible at the moment. However, we can use the `is_valid` method on the `ManagedConnection` trait to discard all session state before yielding the connection. This PR makes it possible to change the query used within the `is_valid` method call in `bb8_postgres`. To make configuring the validation query a little easier, I added a new postgres connection manager builder helper type. Let me know if you're :+1: or :-1: on that. This also includes an example called buidler.rs that shows how someone could use `DISCARD ALL` as a validation query. It then prints a few things to show that session state was indeed cleared between checkouts. ``` $ cargo run --example builder ... The current connection PID: 86445 BB8 says, "beep boop" The current connection PID: 86445 After DISCARD ALL on checkout, BB8 says, "" ```
Would be nice if bb8-postgres supported calling
DISCARD ALL
after the connection is returned to the pool, so it's guaranteed to be "pristine" on the next checkout.Unless I'm missing something, there isn't even a "post check-in" hook in bb8 right now, only
test_on_check_out
. I suppose that could be used, but the best is to do it early, release the resources (e.g.UNLISTEN
) and reduce the latency on checkout (assumingtest_on_checkout
is false).The text was updated successfully, but these errors were encountered: