get_slow_queries
Identify and analyze slow PostgreSQL queries using pg_stat_statements to optimize database performance by revealing top time-consuming queries with execution metrics.
Instructions
Retrieve slow queries from PostgreSQL using pg_stat_statements.
Returns the top N slowest queries ordered by total execution time. Requires the pg_stat_statements extension to be enabled.
Note: This tool focuses on user/application queries only. System catalog queries (pg_catalog, information_schema, pg_toast) are automatically excluded.
The results include:
Query text (normalized)
Total execution time
Number of calls
Mean execution time
Rows returned
Shared buffer hits/reads for cache analysis
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of slow queries to return (default: 10) | |
| min_calls | No | Minimum number of calls for a query to be included (default: 1) | |
| min_total_time_ms | No | Minimum total execution time in milliseconds (default: 0) | |
| order_by | No | Column to order results by | total_time |