Skip to content

Commit

Permalink
Pgbouncer: bpatch, build, install and configure (#173)
Browse files Browse the repository at this point in the history
use following environment variables to enable and control it:
PGBOUNCER_CONFIGURATION controls content of /etc/pgbouncer/pgbouncer.ini
PGBOUNCER_AUTHENTICATION controls content of /etc/pgbouncer/userlist.txt
  • Loading branch information
CyberDem0n committed Jul 18, 2017
1 parent c8ad5fe commit 81c51b0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
11 changes: 10 additions & 1 deletion postgres-appliance/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \
# Install PostgreSQL
ENV PGVERSION=9.6 PGOLDVERSIONS="9.3 9.4 9.5"
RUN export DEBIAN_FRONTEND=noninteractive \
&& export BUILD_PACKAGES="gcc libc6-dev dpkg-dev make pgxnclient libedit-dev zlib1g-dev libssl-dev libselinux1-dev libkrb5-dev libxslt1-dev libxml2-dev libpam0g-dev libcurl4-openssl-dev libprotobuf-c-dev liblwgeom-dev pkg-config libproj-dev libevent-dev" \
&& export BUILD_PACKAGES="devscripts build-essential pgxnclient libedit-dev zlib1g-dev libssl-dev libselinux1-dev libkrb5-dev libxslt1-dev libxml2-dev libpam0g-dev libcurl4-openssl-dev libprotobuf-c-dev liblwgeom-dev pkg-config libproj-dev libevent-dev" \

# Add PGDG repositories
&& export DISTRIB_CODENAME=$(sed -n 's/DISTRIB_CODENAME=//p' /etc/lsb-release) \
Expand Down Expand Up @@ -93,6 +93,15 @@ RUN export DEBIAN_FRONTEND=noninteractive \

&& apt-get install -y skytools3-ticker \

# patch, build and install pgbouncer
&& mkdir pgbouncer && cd pgbouncer \
&& apt-get source pgbouncer \
&& cd $(ls -d pgbouncer-*) \
&& curl -sL https://github.com/pgbouncer/pgbouncer/pull/127.diff | patch -p1 \
&& debuild -b -uc -us \
&& dpkg -i ../pgbouncer_*.deb \
&& cd ../.. \

# install pam_oauth2.so
&& export PAM_OAUTH_COMMIT=bed1f8d31840d1fda49365921449112a7421b8ca \
&& export JSMN_COMMIT=1682c32e9ae5990ddd0f0e907270a0f6dde5cbe9 \
Expand Down
29 changes: 28 additions & 1 deletion postgres-appliance/configure_spilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def parse_args():
sections = ['all', 'patroni', 'patronictl', 'certificate', 'wal-e', 'crontab', 'ldap', 'pam-oauth2']
sections = ['all', 'patroni', 'patronictl', 'certificate', 'wal-e', 'crontab', 'ldap', 'pam-oauth2', 'pgbouncer']
argp = argparse.ArgumentParser(description='Configures Spilo',
epilog="Choose from the following sections:\n\t{}".format('\n\t'.join(sections)),
formatter_class=argparse.RawDescriptionHelpFormatter)
Expand Down Expand Up @@ -466,6 +466,31 @@ def write_pam_oauth2_configuration(placeholders, overwrite):
write_file(pam_oauth2_config, '/etc/pam.d/postgresql', overwrite)


def write_pgbouncer_configuration(placeholders, overwrite):
pgbouncer_config = placeholders.get('PGBOUNCER_CONFIGURATION')
if not pgbouncer_config:
return logging.info('No PGBOUNCER_CONFIGURATION was specified, skipping')

write_file(pgbouncer_config, '/etc/pgbouncer/pgbouncer.ini', overwrite)

pgbouncer_auth = placeholders.get('PGBOUNCER_AUTHENTICATION') or placeholders.get('PGBOUNCER_AUTH')
if pgbouncer_auth:
write_file(pgbouncer_auth, '/etc/pgbouncer/userlist.txt', overwrite)

supervisord_config = """\
[program:pgbouncer]
user=postgres
autostart=1
priority=500
directory=/
command=env -i /usr/sbin/pgbouncer -d /etc/pgbouncer/pgbouncer.ini
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
redirect_stderr=true
"""
write_file(supervisord_config, '/etc/supervisor/conf.d/pgbouncer.conf', overwrite)


def main():
debug = os.environ.get('DEBUG', '') in ['1', 'true', 'on', 'ON']
args = parse_args()
Expand Down Expand Up @@ -520,6 +545,8 @@ def main():
write_ldap_configuration(placeholders, args['force'])
elif section == 'pam-oauth2':
write_pam_oauth2_configuration(placeholders, args['force'])
elif section == 'pgbouncer':
write_pgbouncer_configuration(placeholders, args['force'])
else:
raise Exception('Unknown section: {}'.format(section))

Expand Down

0 comments on commit 81c51b0

Please sign in to comment.