Skip to content

Commit 49b365e

Browse files
committed
Making changes to have osm2pgsql connections go through pgBouncer
1 parent 7633864 commit 49b365e

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ WORKDIR /app
7474
COPY . ./
7575

7676
RUN pip install --upgrade pip && pip install -r requirements.txt
77+
78+
# Expose pgBouncer port
79+
EXPOSE 6432

docker/db.py

+2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ def get_db_conn_string() -> str:
9696
conn_string : str
9797
"""
9898
if os.environ['USE_PGBOUNCER'] == 'true':
99+
LOGGER.debug('Using pgBouncer connection string')
99100
conn_string = os.environ['PGOSM_CONN_PGBOUNCER']
100101
else:
102+
LOGGER.debug('Using direct to Postgres connection string (non-admin)')
101103
conn_string = os.environ['PGOSM_CONN']
102104

103105
return conn_string

docker/osm2pgsql_recommendation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_recommended_script(system_ram_gb: float,
8989
LOGGER.debug(f'Generic command to run: {osm2pgsql_cmd}')
9090

9191
# Replace generic connection string with specific conn string
92-
conn_string = db.connection_string()
92+
conn_string = db.get_db_conn_string()
9393
osm2pgsql_cmd = osm2pgsql_cmd.replace('-d $PGOSM_CONN', f'-d {conn_string}')
9494
# Warning: Do not print() this string any more! Includes password
9595
return osm2pgsql_cmd

docker/pgbouncer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
auth_file = /etc/pgbouncer/userlist.txt
2323
logfile = /var/log/pgbouncer/pgbouncer.log
2424
pidfile = /var/run/pgbouncer/pgbouncer.pid
25-
admin_users = postgres
25+
admin_users = {pg_user}
2626
max_client_conn = 300
2727
default_pool_size = {pgbouncer_pool_size}
2828
max_prepared_statements = 500
29+
pool_mode = transaction
2930
"""
3031
"""str : Shell of pgbouncer.ini used to configure pgBouncer."""
3132

@@ -59,6 +60,7 @@ def setup(pgbouncer_pool_size: int):
5960
pgbouncer_ini = PGBOUNCER_INI_TEMPLATE.format(pg_host=db_parts['pg_host'],
6061
pg_port=db_parts['pg_port'],
6162
pg_db=db_parts['pg_db'],
63+
pg_user=db_parts['pg_user'],
6264
pgbouncer_pool_size=pgbouncer_pool_size
6365
)
6466

0 commit comments

Comments
 (0)