pg_grab_statement
pg_grab_statement · Record detailed SQL statements from successfully committed transactions.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100126 | pg_grab_statement | pg_grab_statement | 1.0 | STAT | GPL-2.0 | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
pg_grab_statement records detailed statements from successfully committed transactions. It hooks executor start and end and writes directly to the unlogged table grab.statement_log; the view grab.statements resolves user and query-type details.
A session can use LOAD; cluster-wide capture requires shared_preload_libraries, while role or database defaults may use session_preload_libraries. Upstream measured roughly 10–15 percent overhead in a SELECT-only benchmark, so benchmark the real workload.
Captured rows include query text, parameter values, parameter types, user IDs, and timing. Restrict access and retention because secrets and personal data can be recorded. The table is unlogged and can be truncated after a crash, so it is not an audit ledger. The project uses old PostgreSQL internals and has no current compatibility matrix; validate hooks, prepared statements, failed transactions, crash behavior, and storage growth on the exact server release.