Skip to content

Instantly share code, notes, and snippets.

@ericallam
Created June 10, 2011 18:35
Show Gist options
  • Save ericallam/1019446 to your computer and use it in GitHub Desktop.
Save ericallam/1019446 to your computer and use it in GitHub Desktop.
How to log all queries for a PostgreSQL homebrew install on OS X

Open the postgresql.conf config file:

$> mate /usr/local/var/postgres/postgresql.conf

Uncomment the line with 'log_destination' and set it to 'syslog'

log_destination = 'syslog'

Open the syslog config:

$> mate /etc/syslog.conf

And add this line:

local0.*    /var/log/postgresql

Then just restart syslog and postgresql

$> ps aux | grep syslog
$> sudo kill -2 PID

$> launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
$> launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist

Now you can tail the log file and see the queries that rails runs:

$> tail -f /var/log/postgresql
@nerdess
Copy link

nerdess commented Apr 2, 2016

thx! used your guide and logging works fine now. only restarting the syslog did not work so i restarted my whole computer instead :)

@meowgorithm
Copy link

I was able to log all queries by simply setting log_statement = 'all' the following in /usr/local/var/postgres/postgresql.conf. Quick and easy.

@JesseVelden
Copy link

JesseVelden commented Nov 10, 2021

In postgresql.conf: /opt/homebrew/var/postgres/postgresql.conf, set log_statement = 'all'.
Then restart using: brew services restart postgresql
And view the logs in the terminal by: tail -n 50 /opt/homebrew/var/log/postgres.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment