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.
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.