pg_stat_statements
Identify the top queries by cumulative execution time for database performance auditing. Shows normalised query text, execution statistics, and block I/O metrics.
Instructions
Return the top N most expensive queries from pg_stat_statements.
Best starting point for a performance audit — shows which query patterns cost the most cumulative time across the application.
Returns: {"rows": [{query, calls, total_exec_sec, mean_exec_sec, max_exec_sec, total_rows, shared_blks_hit, shared_blks_read}], "row_count": N}
Query text uses $1/$2 placeholders (pg_stat_statements normalises literals). Requires the pg_stat_statements extension (enabled by default on RDS, Cloud SQL, Supabase; otherwise: CREATE EXTENSION pg_stat_statements).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |