When you're using PostgreSQL for local development it's sometimes important to get an insight into ALL SQL that happens on the PostgreSQL server. Especially if you're trying to debug all the transaction action too.

To do this on OSX where you have PostgreSQL installed with Homebrew you have to do the following:

1. Locate the right postgresql.conf file. On my computer this is in /opt/boxen/homebrew/var/postgres/ but that might vary depending on how you set up Homebrew. Another easier way is to just start psql and ask there:

$ psql
psql (9.4.0)
Type "help" for help.

peterbe=# show config_file;
                   config_file
--------------------------------------------------
 /opt/boxen/homebrew/var/postgres/postgresql.conf
(1 row)

peterbe=#

Open that file in your favorite editor.

2. Look for a line that looks like this:

#log_statement = 'all'                   # none, ddl, mod, all

Uncomment that line.

3. Now if you can't remember how to restart PostgreSQL on your system you can ask brew:

$ brew info postgresql

Towards the end you'll see some files that look something like this:

$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

4. To locate where PostgreSQL dumps all logging, you have to look to how Homebrew set it up. You can do that by opening ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist. You'll find something like this:

<key>StandardErrorPath</key>
  <string>/opt/boxen/homebrew/var/postgres/server.log</string>

That's it. You can now see all SQL going on by running:

$ tail -f /opt/boxen/homebrew/var/postgres/server.log

Remember to reverse this config change when you're done debugging because that server.log file can quickly grow to an insane size since it's probably not log rotated.

Happy SQL debuggin'!

UPDATE Dec 2018

Another way to use Homebrew to restart PostgreSQL is with the command:

$ brew services restart postgresql

UPDATE Apr 2025

Use pg_stat_statements instead.

Great intro here: "Query Optimization in Postgres with pg_stat_statements".

Comments

Karol

Nice! Thank you so much!

Your email will never ever be published.

Previous:
Visual speed comparison of AngularJS and ReactJS July 20, 2015 Web development, AngularJS, JavaScript
Next:
Some tips on learning React August 4, 2015 React, JavaScript
Related by category:
fnm is much faster than nvm. December 28, 2023 macOS
Inspecting the index size in PostgreSQL April 21, 2025 PostgreSQL
Be careful with Date.toLocaleDateString() in JavaScript May 8, 2023 macOS
The 3 queries I use with pg_stat_statements to analyze slow PostgreSQL queries September 30, 2024 PostgreSQL
Related by keyword:
Adding client-to-server sync to PissueTracker March 20, 2025 React, JavaScript, Bun
Connecting with psycopg2 without a username and password February 24, 2011 Python
UPPER vs. ILIKE April 19, 2010 Web development
How I performance test PostgreSQL locally on macOS December 10, 2018 Web development, PostgreSQL, macOS