From 731ba8c75ab2a44f7c3d3bafae13e6a71781dbe7 Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 27 Jan 2023 19:38:03 +0300 Subject: [PATCH] [bitnami/pgbouncer] Socket+log options and few connections (#14323) * Socket+log options and few connections Add passing socket & log options, and passing as much as needs connections to pgbouncer via DATABASE_0_DSN, DATABASE_1_DSN, and so on in pgbouncer `[databases]` list: ```ini [databases] foodb = host=host1.example.com port=5432 bardb = host=localhost dbname=bazdb * = host=foo ``` it will look like (in docker-compose.yml): ```yml pgbouncer: image: bitnami/pgbouncer environment: - DATABASE0_DSN=foodb=host=host1.example.com port=5432 - DATABASE1_DSN=bardb=host=localhost dbname=bazdb - DATABASE2_DSN=*=host=foo ``` Dont forget to remove spaces before and after **=** sign. So you can now pass 2, 5 and even 100 connections. Signed-off-by: Sergey * Add stats_period Signed-off-by: Sergey * Update libpgbouncer.sh Signed-off-by: Sergey * Update pgbouncer-env.sh Signed-off-by: Sergey * Update libpgbouncer.sh Signed-off-by: Sergey * Update libpgbouncer.sh Signed-off-by: Sergey * Update libpgbouncer.sh Signed-off-by: Sergey * Update pgbouncer-env.sh Signed-off-by: Sergey * Update pgbouncer-env.sh Signed-off-by: Sergey * Update pgbouncer-env.sh Signed-off-by: Sergey * Update libpgbouncer.sh Signed-off-by: corico44 <42420333+corico44@users.noreply.github.com> * Update pgbouncer-env.sh Signed-off-by: corico44 <42420333+corico44@users.noreply.github.com> * Delete unnecessary line Signed-off-by: corico44 <42420333+corico44@users.noreply.github.com> * Fix lint errors Signed-off-by: corico44 <42420333+corico44@users.noreply.github.com> --------- Signed-off-by: Sergey Signed-off-by: corico44 <42420333+corico44@users.noreply.github.com> Co-authored-by: corico44 <42420333+corico44@users.noreply.github.com> --- .../opt/bitnami/scripts/libpgbouncer.sh | 30 +++++++++++++++++ .../opt/bitnami/scripts/pgbouncer-env.sh | 33 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh index 9b1a0ca4cc0f..0a46e33293e2 100644 --- a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh +++ b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh @@ -206,9 +206,25 @@ pgbouncer_initialize() { database_value+=" connect_query='${PGBOUNCER_CONNECT_QUERY}'" fi ini-file set --section "databases" --key "$PGBOUNCER_DATABASE" --value "$database_value" "$PGBOUNCER_CONF_FILE" + + i=0; + while true; VAR_NAME="PGBOUNCER_DSN_${i}"; + do + if [ -z "${!VAR_NAME+x}" ]; then + break; + else + dsn=${!VAR_NAME}; + ini-file set --section databases --key "$(echo "$dsn" | cut -d = -f 1)" --value "$(echo "$dsn" | cut -d = -f 2-)" "$PGBOUNCER_CONF_FILE"; + i=$(( "$i" + 1 )); + fi; + done; + local -r -a key_value_pairs=( "listen_port:${PGBOUNCER_PORT}" "listen_addr:${PGBOUNCER_LISTEN_ADDRESS}" + "unix_socket_dir:${PGBOUNCER_SOCKET_DIR}" + "unix_socket_mode:${PGBOUNCER_SOCKET_MODE}" + "unix_socket_group:${PGBOUNCER_SOCKET_GROUP}" "auth_file:${PGBOUNCER_AUTH_FILE}" "auth_type:${PGBOUNCER_AUTH_TYPE}" "auth_query:${PGBOUNCER_AUTH_QUERY}" @@ -232,6 +248,20 @@ pgbouncer_initialize() { "min_pool_size:${PGBOUNCER_MIN_POOL_SIZE}" "reserve_pool_size:${PGBOUNCER_RESERVE_POOL_SIZE}" "ignore_startup_parameters:${PGBOUNCER_IGNORE_STARTUP_PARAMETERS}" + "log_connections:${PGBOUNCER_LOG_CONNECTIONS}" + "log_disconnections:${PGBOUNCER_LOG_DISCONNECTIONS}" + "log_pooler_errors:${PGBOUNCER_LOG_POOLER_ERRORS}" + "log_stats:${PGBOUNCER_LOG_STATS}" + "stats_period:${PGBOUNCER_STATS_PERIOD}" + "server_lifetime:${PGBOUNCER_SERVER_LIFETIME}" + "server_idle_timeout:${PGBOUNCER_SERVER_IDLE_TIMEOUT}" + "server_connect_timeout:${PGBOUNCER_SERVER_CONNECT_TIMEOUT}" + "server_login_retry:${PGBOUNCER_SERVER_LOGIN_RETRY}" + "client_login_timeout:${PGBOUNCER_CLIENT_LOGIN_TIMEOUT}" + "autodb_idle_timeout:${PGBOUNCER_AUTODB_IDLE_TIMEOUT}" + "query_timeout:${PGBOUNCER_QUERY_TIMEOUT}" + "query_wait_timeout:${PGBOUNCER_QUERY_WAIT_TIMEOUT}" + "client_idle_timeout:${PGBOUNCER_CLIENT_IDLE_TIMEOUT}" ) for pair in "${key_value_pairs[@]}"; do local key value diff --git a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/pgbouncer-env.sh b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/pgbouncer-env.sh index b3091b960266..8f603cc76335 100644 --- a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/pgbouncer-env.sh +++ b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/pgbouncer-env.sh @@ -65,6 +65,18 @@ pgbouncer_env_vars=( PGBOUNCER_FORCE_INITSCRIPTS PGBOUNCER_DAEMON_USER PGBOUNCER_DAEMON_GROUP + PGBOUNCER_STATS_PERIOD + PGBOUNCER_LOG_CONNECTIONS + PGBOUNCER_LOG_DISCONNECTIONS + PGBOUNCER_LOG_POOLER_ERRORS + PGBOUNCER_LOG_STATS + PGBOUNCER_SERVER_LIFETIME + PGBOUNCER_SERVER_CONNECT_TIMEOUT + PGBOUNCER_SERVER_LOGIN_RETRY + PGBOUNCER_CLIENT_LOGIN_TIMEOUT + PGBOUNCER_AUTODB_IDLE_TIMEOUT + PGBOUNCER_QUERY_TIMEOUT + PGBOUNCER_CLIENT_IDLE_TIMEOUT ) for env_var in "${pgbouncer_env_vars[@]}"; do file_env_var="${env_var}_FILE" @@ -114,6 +126,7 @@ export PGBOUNCER_MIN_POOL_SIZE="${PGBOUNCER_MIN_POOL_SIZE:-}" export PGBOUNCER_RESERVE_POOL_SIZE="${PGBOUNCER_RESERVE_POOL_SIZE:-}" export PGBOUNCER_IGNORE_STARTUP_PARAMETERS="${PGBOUNCER_IGNORE_STARTUP_PARAMETERS:-}" export PGBOUNCER_EXTRA_FLAGS="${PGBOUNCER_EXTRA_FLAGS:-}" +export PGBOUNCER_STATS_PERIOD="${PGBOUNCER_STATS_PERIOD:-60}" # Client TLS settings export PGBOUNCER_CLIENT_TLS_SSLMODE="${PGBOUNCER_CLIENT_TLS_SSLMODE:-disable}" @@ -130,6 +143,21 @@ export PGBOUNCER_SERVER_TLS_KEY_FILE="${PGBOUNCER_SERVER_TLS_KEY_FILE:-}" export PGBOUNCER_SERVER_TLS_PROTOCOLS="${PGBOUNCER_SERVER_TLS_PROTOCOLS:-secure}" export PGBOUNCER_SERVER_TLS_CIPHERS="${PGBOUNCER_SERVER_TLS_CIPHERS:-fast}" +# Logging settings +export PGBOUNCER_LOG_CONNECTIONS="${PGBOUNCER_LOG_CONNECTIONS:-}" +export PGBOUNCER_LOG_DISCONNECTIONS="${PGBOUNCER_LOG_DISCONNECTIONS:-}" +export PGBOUNCER_LOG_POOLER_ERRORS="${PGBOUNCER_LOG_POOLER_ERRORS:-}" +export PGBOUNCER_LOG_STATS="${PGBOUNCER_LOG_STATS:-1}" + +# Timeout settings +export PGBOUNCER_SERVER_LIFETIME="${PGBOUNCER_SERVER_LIFETIME:-}" +export PGBOUNCER_SERVER_CONNECT_TIMEOUT="${PGBOUNCER_SERVER_CONNECT_TIMEOUT:-}" +export PGBOUNCER_SERVER_LOGIN_RETRY="${PGBOUNCER_SERVER_LOGIN_RETRY:-}" +export PGBOUNCER_CLIENT_LOGIN_TIMEOUT="${PGBOUNCER_CLIENT_LOGIN_TIMEOUT:-}" +export PGBOUNCER_AUTODB_IDLE_TIMEOUT="${PGBOUNCER_AUTODB_IDLE_TIMEOUT:-}" +export PGBOUNCER_QUERY_TIMEOUT="${PGBOUNCER_QUERY_TIMEOUT:-}" +export PGBOUNCER_CLIENT_IDLE_TIMEOUT="${PGBOUNCER_CLIENT_IDLE_TIMEOUT:-}" + # PostgreSQL backend settings export POSTGRESQL_USERNAME="${POSTGRESQL_USERNAME:-postgres}" export POSTGRESQL_PASSWORD="${POSTGRESQL_PASSWORD:-}" @@ -141,6 +169,11 @@ export PGBOUNCER_SET_DATABASE_PASSWORD="${PGBOUNCER_SET_DATABASE_PASSWORD:-no}" export PGBOUNCER_CONNECT_QUERY="${PGBOUNCER_CONNECT_QUERY:-}" export PGBOUNCER_FORCE_INITSCRIPTS="${PGBOUNCER_FORCE_INITSCRIPTS:-false}" +# Socket settings +export PGBOUNCER_SOCKET_DIR="${PGBOUNCER_SOCKET_DIR:-/tmp/}" +export PGBOUNCER_SOCKET_MODE="${PGBOUNCER_SOCKET_MODE:-0777}" +export PGBOUNCER_SOCKET_GROUP="${PGBOUNCER_SOCKET_GROUP:-}" + # System settings export PGBOUNCER_DAEMON_USER="${PGBOUNCER_DAEMON_USER:-pgbouncer}" export PGBOUNCER_DAEMON_GROUP="${PGBOUNCER_DAEMON_GROUP:-pgbouncer}"