forked from fabric8-analytics/fabric8-analytics-pgbouncer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-pgbouncer.sh
executable file
·44 lines (35 loc) · 1.11 KB
/
run-pgbouncer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash -e
export POSTGRESQL_HOST=${POSTGRES_SERVICE_HOST:-coreapi-postgres}
export POSTGRESQL_PORT=${POSTGRES_SERVICE_PORT:-5432}
PGBOUNCER_DIR=/tmp/pgbouncer
USERLIST_TXT=${PGBOUNCER_DIR}/userlist.txt
PGBOUNCER_INI=${PGBOUNCER_DIR}/pgbouncer.ini
mkdir -p ${PGBOUNCER_DIR}
cat > ${USERLIST_TXT} << EOF
"${POSTGRESQL_USER}" "${POSTGRESQL_PASSWORD}"
EOF
cat > ${PGBOUNCER_INI} << EOF
[databases]
${POSTGRESQL_DATABASE} = host=${POSTGRESQL_HOST} port=${POSTGRESQL_PORT}
${POSTGRESQL_INITIAL_DATABASE} = host=${POSTGRESQL_HOST} port=${POSTGRESQL_PORT}
[pgbouncer]
pool_mode = transaction
listen_addr = *
listen_port = 5432
auth_file = ${USERLIST_TXT}
# TODO: we'll want to change this to "cert" or "hba"
auth_type = md5
admin_users = ${POSTGRESQL_USER}
max_client_conn = 10000
default_pool_size = 20
# pgweb refuses to work with extra_float_digits
ignore_startup_parameters = extra_float_digits
EOF
pg_user=$(id -u)
PG_USER_OPT=""
if [ $pg_user == "0" ]; then
chown pgbouncer:pgbouncer ${USERLIST_TXT}
chown pgbouncer:pgbouncer ${PGBOUNCER_INI}
PG_USER_OPT="-u pgbouncer"
fi
pgbouncer ${PG_USER_OPT} ${PGBOUNCER_INI}