get_slow_queries
Identify and analyze slow PostgreSQL queries using pg_stat_statements to optimize database performance by revealing execution times, call frequency, and cache efficiency 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.
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 |
Input Schema (JSON Schema)
{
"properties": {
"limit": {
"default": 10,
"description": "Maximum number of slow queries to return (default: 10)",
"maximum": 100,
"minimum": 1,
"type": "integer"
},
"min_calls": {
"default": 1,
"description": "Minimum number of calls for a query to be included (default: 1)",
"minimum": 1,
"type": "integer"
},
"min_total_time_ms": {
"default": 0,
"description": "Minimum total execution time in milliseconds (default: 0)",
"type": "number"
},
"order_by": {
"default": "total_time",
"description": "Column to order results by",
"enum": [
"total_time",
"mean_time",
"calls",
"rows"
],
"type": "string"
}
},
"required": [],
"type": "object"
}