-
Notifications
You must be signed in to change notification settings - Fork 139
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
Add support for dynamic postgres connection config #219
base: master
Are you sure you want to change the base?
Conversation
Interesting idea. It flips the responsibilities around: Rather than changing the configuration a callback can be configured for providing the manager configuration. I do like the idea of that "configuration provider" but at the same time I wonder if it's really the right approach. e.g. let's say the database is being migrated, the connection URL has changed and connections using the old URL should be dropped asap. With that approach only new connections get to know about that configuration change and existing connections will stay pooled and reused over and over again. Unless the recycle method also calls I have to play with this a bit. I've toyed with replacing the entire manager but that would be a rather heavy change as it would mean that manager implementations tracking the created objects (such as the postgres one) would either need to reattach connections from other manager instances or upon changing the manager all existing connections need to be dropped when returned to the pool. I'm undecided if I'd rather make the manager non-replaceable and leave it to the manager implementation to support config changes. See also |
Hmm, for that use case the first thing that comes to mind is to put an optional "generation number" ( |
I was looking for this kind of change (with Google Cloud SQL in my case). I personally don't think there's a single policy that works for whether a config update should cause existing connections to be removed; this should be signalled separately, either here or by another mechanism. I was considering the possibility of just making the DB config be a |
Great insights. There doesn't seam to be one "right way" that should be hard coded. I think the best approach would be to let the object reference the configuration and/or manager that was used to create it. The I'm still intrigued by the idea of replacing the manager rather than just replacing the config. This would mean that managers like the one from |
2f4d3ba
to
b1cf396
Compare
Related to: If this lands the |
This adds support for providing a dynamic configuration for postgres pools that can provide a unique configuration for each new connection.
The motivating use case for this is AWS RDS IAM authentication, which uses a token that has a 15 minute expiry as the password. I have implemented this algorithm with the new hook provided in this PR and am currently testing it out.
This PR also depends on a small change in
tokio_postgres
to allow passing errors through cleanly. Once the approach in this PR has been reviewed, I'll submit that PR for review upstream.I'm pretty new to Rust, so please let me know if I'm approaching this wrong.