Run read-only SQL
pg_readonlyRun SELECT, WITH, VALUES, TABLE, SHOW, or EXPLAIN statements inside an always-rolled-back READ ONLY transaction to inspect PostgreSQL data without writes.
Instructions
Run one SQL statement inside a BEGIN READ ONLY transaction that is always rolled back, regardless of ALLOW_WRITES. Postgres rejects INSERT/UPDATE/DELETE/DDL there. Use this to read: SELECT, WITH ... SELECT, VALUES, TABLE, SHOW, EXPLAIN. Statements that escape or reshape the transaction are refused (SET, RESET, DO, CALL, PREPARE, EXECUTE, COPY, LOCK, transaction control and similar), as are calls to known out-of-transaction functions (dblink*, set_config, pg_read_file, lo_export, pg_terminate_backend, ...). These checks are best-effort and are NOT a security boundary: a function wrapper gets past them, and a function can write through its own connection. The DATABASE_URL role is the boundary, so do not auto-allow this tool unless that role is least-privilege. Use params for parameterized queries to avoid SQL injection. Params can be strings, numbers, booleans, null, arrays (for postgres arrays / ANY), or objects (for json/jsonb columns). Large result sets are truncated to POSTGRES_MAX_ROWS (default 1000) with a truncated: true flag; a result over POSTGRES_MAX_RESULT_BYTES fails instead, and a call past POSTGRES_QUERY_DEADLINE_MS has its backend terminated.
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": "pg_readonly"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | The SQL statement to execute. Hard cap of 1 MB. | |
| params | No | Positional parameters referenced as $1, $2, ... in the SQL. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | Yes | Result rows, capped at POSTGRES_MAX_ROWS. Values are whatever JSON type pg parsed the column into. | |
| fields | Yes | Result column descriptors, in select-list order. | |
| command | No | Postgres command tag (`INSERT`, `CREATE TABLE`, ...). Absent on the cursor path -- read absence as 'row-returning statement, command unknown'. | |
| rowCount | Yes | Rows AFFECTED for DML -- not necessarily rows.length -- and rows returned on the cursor path. Null when pg reported no count. | |
| truncated | No | Present and true only when the result hit POSTGRES_MAX_ROWS and rows were dropped. |