Databases sql Advanced

Slow Query Logger Setup

Enable and configure PostgreSQL slow query logging with pg_stat_statements.

sql
-- postgresql.conf
log_min_duration_statement = 500
log_statement = 'none'

-- Enable extension
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

-- Top 10 slowest queries
SELECT query, calls, mean_exec_time::int || 'ms' AS avg
FROM pg_stat_statements
ORDER BY mean_exec_time DESC LIMIT 10;

Prerequisites

  • PostgreSQL >= 13
  • pg_stat_statements

Pro Tips

  • → Reload config with SELECT pg_reload_conf();

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
sql
Level
Advanced
Read time
4 min
Published
Mar 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.