Juan Uys

Add logging to PostgresQL on Docker


Normally, in docker-compose.yml I would just configure a database like this:

  image: postgres:9.4

However, to customise the image, we use our own Dockerfile:

FROM postgres:9.4
ADD config.sh /docker-entrypoint-initdb.d/

The contents of config.sh:

perl -pi -e "s/#log_statement = 'none'/log_statement = 'all'/g" \

And docker-compose.yml now becomes:

  build: location/of/new/docker/file

Link your app, launch the stack, and start seeing log statements on STDIN:

db_1         | LOG:  statement: BEGIN
db_1         | LOG:  statement: SELECT etc etc
Copyright © 2002-2024 Juan Uys, (source code for this website). Updates via RSS, Mastodon or newsletter 💌.