From bb2d6721b64170326a18e8f180c38e763cf9e9b3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 29 Jan 2018 14:16:17 +0100 Subject: [PATCH 1/4] introduce PGBOUNCER_CONNECT_QUERY parameter to configure connect_query setting this is super useful for setting things like statement_timeout on backend connection initiation. --- bin/gen-pgbouncer-conf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/gen-pgbouncer-conf.sh b/bin/gen-pgbouncer-conf.sh index 54a289d..89803e2 100644 --- a/bin/gen-pgbouncer-conf.sh +++ b/bin/gen-pgbouncer-conf.sh @@ -93,7 +93,7 @@ EOFEOF EOFEOF cat >> /app/vendor/pgbouncer/pgbouncer.ini << EOFEOF -$CLIENT_DB_NAME= dbname=$DB_NAME port=610${n} +$CLIENT_DB_NAME= dbname=$DB_NAME port=610${n} connect_query='${PGBOUNCER_CONNECT_QUERY}' EOFEOF let "n += 1" From 23d19e44bb5c271c19303c1a127d4f268fd2f158 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 29 Jan 2018 15:32:12 +0100 Subject: [PATCH 2/4] document PGBOUNCER_CONNECT_QUERY in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8d72f3e..144b1af 100644 --- a/README.md +++ b/README.md @@ -146,5 +146,6 @@ and [stunnel](http://linux.die.net/man/8/stunnel) configurations to see what set - `ENABLE_STUNNEL_AMAZON_RDS_FIX` Default is unset. Set this var if you are connecting to an Amazon RDS instance of postgres. Adds `options = NO_TICKET` which is documented to make stunnel work correctly after a dyno resumes from sleep. Otherwise, the dyno will lose connectivity to RDS. - `PGBOUNCER_IGNORE_STARTUP_PARAMETERS` Adds parameters to ignore when pgbouncer is starting. Some postgres libraries, like Go's pq, append this parameter, making it impossible to use this buildpack. Default is empty and the most common ignored parameter is `extra_float_digits`. Multiple parameters can be seperated via commas. Example: `PGBOUNCER_IGNORE_STARTUP_PARAMETERS="extra_float_digits, some_other_param"` +- `PGBOUNCER_CONNECT_QUERY` The query to be executed on newly created connections. This is useful for setting things like `statement_timeout`. e.g. `PGBOUNCER_CONNECT_QUERY="set statement_timeout to 10000"` For more info, see [CONTRIBUTING.md](CONTRIBUTING.md) From 9ee3ed75ec6dac9851920c0e5f42b9376de72da3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 29 Jan 2018 15:38:50 +0100 Subject: [PATCH 3/4] escape single quotes in connect_query --- bin/gen-pgbouncer-conf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/gen-pgbouncer-conf.sh b/bin/gen-pgbouncer-conf.sh index 89803e2..7765d04 100644 --- a/bin/gen-pgbouncer-conf.sh +++ b/bin/gen-pgbouncer-conf.sh @@ -93,7 +93,7 @@ EOFEOF EOFEOF cat >> /app/vendor/pgbouncer/pgbouncer.ini << EOFEOF -$CLIENT_DB_NAME= dbname=$DB_NAME port=610${n} connect_query='${PGBOUNCER_CONNECT_QUERY}' +$CLIENT_DB_NAME= dbname=$DB_NAME port=610${n} connect_query='${PGBOUNCER_CONNECT_QUERY//\'/\'\'}' EOFEOF let "n += 1" From 028672bd72b444c6a1345d7ba3cc69d2e292c3f0 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 1 Feb 2018 15:23:20 +0100 Subject: [PATCH 4/4] handle empty connect_query more gracefully --- bin/gen-pgbouncer-conf.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/gen-pgbouncer-conf.sh b/bin/gen-pgbouncer-conf.sh index 7765d04..73f9003 100644 --- a/bin/gen-pgbouncer-conf.sh +++ b/bin/gen-pgbouncer-conf.sh @@ -92,8 +92,13 @@ EOFEOF "$DB_USER" "$DB_MD5_PASS" EOFEOF +CONNECT_QUERY_PARAM='' +if [[ "$PGBOUNCER_CONNECT_QUERY" ]]; then + CONNECT_QUERY_PARAM="connect_query='${PGBOUNCER_CONNECT_QUERY//\'/\'\'}'" +fi + cat >> /app/vendor/pgbouncer/pgbouncer.ini << EOFEOF -$CLIENT_DB_NAME= dbname=$DB_NAME port=610${n} connect_query='${PGBOUNCER_CONNECT_QUERY//\'/\'\'}' +$CLIENT_DB_NAME= dbname=$DB_NAME port=610${n} $CONNECT_QUERY_PARAM EOFEOF let "n += 1"