-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[bitnami/pgbouncer] support $PGBOUNCER_DSN_${i}_FILE env vars #51830
Conversation
Hi @derhuerst, Thank you so much for your contribution. I would like to inform you that we are currently addressing a related issue internally #20874 and we are considering your pull request implementation. That being said, I'm placing this PR on hold and we will reach out to you as soon as we have updates to share. Appreciate your contribution! |
FYI: I'm currently building a much more generalised approach with a completely separate code base: Generate pgbouncer's config from etcd, and reload it whenever an etcd key/value has changed. Will update this post with source code soon. |
Hi @derhuerst, Thanks for your contribution and for using our products. it is possible to configure multiple backend database connections in pgbouncer by using the combination of some of the environment variables already availables: one or more pg1:
image: docker.io/bitnami/postgresql:14
volumes:
- 'pg1_data:/bitnami/postgresql'
environment:
- POSTGRESQL_PASSWORD=bitnami123
- POSTGRESQL_DATABASE=db1
pg2:
image: docker.io/bitnami/postgresql:15
volumes:
- 'pg2_data:/bitnami/postgresql'
environment:
- POSTGRESQL_PASSWORD=bitnami456
- POSTGRESQL_DATABASE=db2
pg3:
image: docker.io/bitnami/postgresql:14
volumes:
- 'pg3_data:/bitnami/postgresql'
environment:
- POSTGRESQL_PASSWORD=bitnami789
- POSTGRESQL_DATABASE=db3
pgbouncer:
image: docker.io/bitnami/pgbouncer:1
ports:
- 6432:6432
volumes:
- './userlists.txt:/bitnami/userlists.txt'
environment:
- POSTGRESQL_HOST=pg1
- ALLOW_EMPTY_PASSWORD=yes
- PGBOUNCER_AUTH_TYPE=trust
- PGBOUNCER_USERLIST_FILE=/bitnami/userlists.txt
- PGBOUNCER_DSN_0=pg2=host=pg2 port=5432 dbname=db2
- PGBOUNCER_DSN_1=pg3=host=pg3 port=5432 dbname=db3
volumes:
pg1_data:
driver: local
pg2_data:
driver: local
pg3_data:
driver: local Notice you need to provide at least one database connection using the default
In the same way, you can check that the content of your local
Could you give us more details about your specific use case? According to our investigation, you don't need to provide any sensible data in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! Just a minor comment here
bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh
Outdated
Show resolved
Hide resolved
As per my investigation, restarting the service is not needed to update PgBouncer's config. You can simply mount both the |
Signed-off-by: Jannis R <mail@jannisr.de>
Yes, true, it is technically possible, but not a feasible option for me, because it would require having this config generation logic in a another service/component; This would defeat the purpose of using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi @derhuerst, Can you fix the DCO issues so we can merge your changes? |
Signed-off-by: Jannis R <mail@jannisr.de>
Thanks for your contribution! |
@derhuerst we have just released |
I can confirm that it works as intended. Thanks. |
Description of the change
This PR is a follow-up of #14323, which has added
$PGBOUNCER_DSN_${i}
to support multiple upstream connections.I was surprised to find (undocumented!) support for them, but expected the variables to work like (almost) all other pgbouncer-related env vars: I should be able to use
$PGBOUNCER_DSN_${i}_FILE
to reference a file containing the value of$PGBOUNCER_DSN_${i}
! This PR adds support for such_FILE
env vars.Benefits
Configuring pgbouncer programmatically is really tricky apparently. In the past several days, I have experimented with multiple ways to define
n > 1
upstream connections dynamically in a Docker-Compose-based setup. Within one Compose service, I want to re-configure the (upstream) PostgreSQL database that other services are supposed to access, without changing (i.e. restarting) the latter ones.With the option to specify that a specific connection's config should be read from a file, I can mount that file into the pgbouncer container, and execute
/opt/bitnami/scripts/pgbouncer/setup.sh
(it deletes files, e.g. thepidfile
, but that is another topic, I might submit a follow-up PR for this) andpsql -p 6432 -U pgbouncer -c RELOAD
, in order to apply the newly configured connection.Possible drawbacks
The design is quite complex, and
bitnami/pgbouncer
's env var handling becomes another bit more complex, and its API surface another bit larger.The cleanest solution might be to write either
bitnami/pgbouncer
already avoids so many gotchas that I would run into again, so I figured this is not a good approach. –, orHowever, given that these alternative approaches require much more work and that they might cause significant maintenance burden (because they're standalone projects, whereas this project is likely to be maintained by anyone using pgbouncer within containers), I have refrained from pursuing them, and submit this PR in the hope that you consider it a useful contribution. 😄
Applicable issues
Additional information
I have also checked out AWS Labs' pgbouncer fork, but neither its query routing feature seems capable of this (as a query routing function can only route to a upstream "target" that has been defined statically in
pgbouncer.ini
) nor its "fast switchover" feature (because it seems to be closely tied to how PG clusters work).