Skip to content

Instantly share code, notes, and snippets.

@just3ws
Created September 15, 2017 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save just3ws/d928eb24017fdd2fb8febeebcd14de57 to your computer and use it in GitHub Desktop.
Save just3ws/d928eb24017fdd2fb8febeebcd14de57 to your computer and use it in GitHub Desktop.
Enable Logging Insight in Postgres
vim /usr/local/var/postgres/postgresql.conf

At the end of the file add...

shared_preload_libraries 'pg_stat_statements,auto_explain' # Add settings for extensions here

pg_stat_statements.track  top   # `top` track top-level statements (those issued directly by clients)
pg_stat_statements.max    10000
track_activity_query_size 2048

auto_explain.log_min_duration      3ms   # Exclude very fast trivial queries.
auto_explain.log_nested_statements true  # Statements inside functions.
auto_explain.log_analyze           false # Get actual times, too
brew services restart postgres
tail -F /usr/local/var/log/postgres.log

You can tweak the configuration or remove it entirely.

@just3ws
Copy link
Author

just3ws commented Sep 15, 2017

I have log_analyze disabled because it causes queries to be run twice. It's worth it when you need it through but recommend just enabling it when you explicitly want to get that granularity.

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