On MacOS, how to turn on the detailed log of brew installed PostgreSQL

On MacOS, I installed PostgreSQL service with brew. Now I want it to log all the executed SQL statements.

Update PostgreSQL configuration

Open the file /usr/local/var/postgres/postgresql.conf, and add these lines to it:

log_statement = 'all'
log_directory = '/tmp/pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
logging_collector = on
log_min_error_statement = error

Please change the log_directory configuration to your own log directory.

Restart service

After the configuration, remember to restart the service so that the configuration can take effect.

brew services restart postgresql
Posted on 2023-03-08