Explain query
explain_queryRetrieve the execution plan for a SQL query to identify performance bottlenecks. Optionally run with ANALYZE to capture I/O and buffer usage.
Instructions
Return the PostgreSQL execution plan for a query. By default uses EXPLAIN (FORMAT JSON) — plan only, the query is not executed. Set io=true to switch to EXPLAIN (ANALYZE, BUFFERS, TIMING) — runs the query and includes buffer + I/O timing per node (PG 19 additionally surfaces asynchronous-I/O block counts). Validated by the same safety allowlist as run_select, so writes / DDL are rejected.
Example: explain_query(sql='SELECT * FROM orders WHERE customer_id = 42', io=true)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| io | No | ||
| sql | Yes | ||
| database | No | Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| plan | Yes |