-
Notifications
You must be signed in to change notification settings - Fork 27
/
run-pgbouncer.sh
executable file
·50 lines (41 loc) · 1.33 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
45
46
47
48
49
50
#!/bin/bash -e
export POSTGRESQL_HOST=${POSTGRES_SERVICE_HOST:-coreapi-postgres}
export POSTGRESQL_PORT=${POSTGRES_SERVICE_PORT:-5432}
export PGBOUNCER_DEFAULT_POOL_SIZE=${PGBOUNCER_DEFAULT_POOL_SIZE:-100}
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]
# https://pgbouncer.github.io/config.html
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 = ${PGBOUNCER_DEFAULT_POOL_SIZE}
# pgweb refuses to work with extra_float_digits
ignore_startup_parameters = extra_float_digits
log_connections = 0
log_disconnections = 0
log_pooler_errors = 1
stats_period = 60
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}