Skip to content

How to turn on SQL statement logging in postgres

Christopher Keith edited this page Dec 7, 2022 · 11 revisions

Docker

Using knex

  • Add DEBUG=knex:query to the packages/server/.env file
  • Run docker compose up -d to reload the changes
  • Run docker compose logs app -f -t to see the log

Using postgres

  • Modify docker-compose.yml so that the services.postgres.environment array contains the following new entry: - POSTGRESQL_PGAUDIT_LOG=all
  • Run docker compose up -d to reload Postgres container
  • Run docker compose logs postgres -f -t
  • Hit the "Browse Grants" tab to verify that the SQL statements are being logged

WSL / Ubuntu

sudo nano /etc/postgresql/14/main/postgresql.conf

Add:
image

chris@2018-ck-nuc:~/github/usdr-gost$ sudo service postgresql stop
* Stopping PostgreSQL 14 database server [ OK ]
chris@2018-ck-nuc:~/github/usdr-gost$ sudo service postgresql start
* Starting PostgreSQL 14 database server [ OK ]
chris@2018-ck-nuc:~/github/usdr-gost$

sudo nano /var/log/postgresql/???

Reference: https://stackoverflow.com/questions/722221/how-to-log-postgresql-queries