query_postgres
Execute read-only SQL SELECT queries against PostgreSQL to retrieve data, with automatic row limits and safeguards against long-running scans.
Instructions
Execute a read-only SQL SELECT query against PostgreSQL. Use the metadata discovery tools (list_postgres_databases, list_postgres_schemas, list_postgres_tables, list_postgres_columns) first to explore available data before constructing queries. Only SELECT is allowed; LIMIT is auto-appended if missing. Queries are cancelled if they run too long, so avoid full-table scans. For approximate row counts — "how many rows / records does table X have", overviews, or summarizing several tables — do NOT run exact SELECT COUNT(*) (it scans the whole table and can take many seconds on a large one). Instead read the planner estimate, which is effectively instant regardless of table size: SELECT reltuples::bigint AS estimate FROM pg_class WHERE relname = '<table>'. Use exact COUNT(*) only when the user explicitly needs an exact count of a known-small or filtered result.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sql": "<sql>"
},
"name": "query_postgres"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL SELECT query to execute | |
| limit | No | Maximum rows to return (default: 100). Pass -1 for unlimited — no cap, returns every matching row. |