From ce9b79f61294781b68bed4203e6f680b28a246a5 Mon Sep 17 00:00:00 2001 From: Dan Milne Date: Wed, 19 Feb 2025 19:12:44 +1100 Subject: [PATCH] Clean up document and make config more generic --- multidb-pg-pgbouncer/README.md | 13 +++++++++++++ multidb-pg-pgbouncer/compose.yaml | 4 ++-- multidb-pg-pgbouncer/pgbouncer.ini | 5 ++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/multidb-pg-pgbouncer/README.md b/multidb-pg-pgbouncer/README.md index c581eb7..58515ad 100644 --- a/multidb-pg-pgbouncer/README.md +++ b/multidb-pg-pgbouncer/README.md @@ -1,5 +1,9 @@ # Multi Database PostgreSQL with PGBouncer +This Compose project will let you run multiple database within one PostgreSQL container. It's based on (Cristian Angulo)[https://dev.to/nietzscheson/multiples-postgres-databases-in-one-service-with-docker-compose-4fdf]'s post on the subject. + +It also starts up a PGBouncer. + ## ENV file Create a .env file with the following keys: @@ -26,3 +30,12 @@ Alternatively, bind mount a local directory for PostgreSQL to use. ## Logging This configuration will log to a mounted volume, using PostgreSQL logging, and not to Stderr / Docker logging as per the default image. + +## PGBouncer +Add PGBouncer accounts with: + +```bash +./generate-userlist pgb_admin >> userlist.txt +``` + +Update `pgbouncer.ini` adding the databases defined in POSTGRES_MULTIPLE_DATABASES to the `[databases]` section. \ No newline at end of file diff --git a/multidb-pg-pgbouncer/compose.yaml b/multidb-pg-pgbouncer/compose.yaml index 78fda09..6917133 100644 --- a/multidb-pg-pgbouncer/compose.yaml +++ b/multidb-pg-pgbouncer/compose.yaml @@ -1,5 +1,5 @@ services: - solid-pg: + postgres: restart: always image: postgres:17 environment: @@ -21,7 +21,7 @@ services: restart: always image: edoburu/pgbouncer:latest depends_on: - - solid-pg + - postgres ports: - "${HOST_IP}:6432:5432" volumes: diff --git a/multidb-pg-pgbouncer/pgbouncer.ini b/multidb-pg-pgbouncer/pgbouncer.ini index b7beef1..062a47d 100644 --- a/multidb-pg-pgbouncer/pgbouncer.ini +++ b/multidb-pg-pgbouncer/pgbouncer.ini @@ -1,12 +1,11 @@ [databases] -solid_cache = host=solid-pg port=5432 dbname=solid_cache user=postgres password=Zie6ioloo5ehi0oosei4fahg -solid_queue = host=solid-pg port=5432 dbname=solid_queue user=postgres password=Zie6ioloo5ehi0oosei4fahg +database1 = host=solid-pg port=5432 dbname=solid_cache user=postgres password=somepassword +database1 = host=solid-pg port=5432 dbname=solid_queue user=postgres password=somepassword [pgbouncer] listen_addr = 0.0.0.0 listen_port = 5432 -#auth_type = scram-sha-256 auth_type = md5 auth_file = /etc/pgbouncer/userlist.txt logfile = /var/log/pgbouncer/pgbouncer.log