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();
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.
Similar Modules
MySQL Replication Status Check
Script to check MySQL/MariaDB replication lag and alert if it exceeds threshold.
sql
·
Intermediate
DB Connection Pool Monitor
Query to check active connections, idle connections and pool usage in PostgreSQL.
sql
·
Intermediate
Cursor-based Pagination Query
Implement cursor-based (keyset) pagination in SQL — faster than OFFSET for large tables.
sql
·
Intermediate