Skip to content

Commit

Permalink
pgbouncer: add global query_timeout of 30s [todo:keep?]
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Nov 13, 2023
1 parent 48d4a9a commit 4d4bb3b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ IPL_GTFS_DB_POSTGREST_PASSWORD=password
PGBOUNCER_IMAGE=bitnami/pgbouncer:1
PGBOUNCER_POSTGRES_PORT=6432
PGBOUNCER_POSTGRES_USER=postgres
PGBOUNCER_QUERY_TIMEOUT_SECONDS=30

# gtfs-api variables
IPL_GTFS_API_PORT=4000
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ services:
# contains the latest import's DB name
- ./var/gtfs/pgbouncer-dsn.txt:/var/gtfs-pgbouncer-dsn.txt
- ./etc/reload-pgbouncer-databases.sh:/reload-pgbouncer-databases.sh
# custom init scripts, configuring pgbouncer in addition to $PGBOUNCER_*
- ./etc/pgbouncer-init.d:/docker-entrypoint-initdb.d
environment:
# Even if we define all upstream database connections "manually" using $PGBOUNCER_DSN_* (see below), the bitnami/pgbouncer Docker image expects 1 connection to be specified via $POSTGRESQL_*, which it implicitly adds to the `[database]` section of pgbouncer.ini. Note that the specified database credentials must be valid.
# However, the $POSTGRESQL_* env vars are *also* used to configure client access to pgbouncer: They get implicitly added to the generated userlist.txt, meaning that clients *must* use them (if there are no other user/password pairs defined, which we don't do) to connect to *any* exposed connection.
Expand All @@ -395,6 +397,8 @@ services:
# Geoserver fails to connect without this config
# see https://github.com/bitnami/containers/issues/25394#issuecomment-1457893192
PGBOUNCER_IGNORE_STARTUP_PARAMETERS: extra_float_digits
# picked up by /docker-entrypoint-initdb.d/20-query_timeout.sh
PGBOUNCER_QUERY_TIMEOUT_SECONDS: ${PGBOUNCER_QUERY_TIMEOUT_SECONDS:?missing/empty $PGBOUNCER_QUERY_TIMEOUT_SECONDS}

# upsteam connections
# see also https://www.pgbouncer.org/config.html#section-databases
Expand Down
11 changes: 11 additions & 0 deletions etc/pgbouncer-init.d/20-query_timeout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e
set -u
set -x # todo: remove?

ini-file set --ignore-inline-comments \
--section 'pgbouncer' \
--key 'query_timeout' \
--value "${PGBOUNCER_QUERY_TIMEOUT_SECONDS:?missing/empty env var $PGBOUNCER_QUERY_TIMEOUT_SECONDS}" \
"$PGBOUNCER_CONF_FILE"

0 comments on commit 4d4bb3b

Please sign in to comment.