Skip to content

pg_grab_statement

Record detailed SQL statements from successfully committed transactions.

pg_grab_statement · Record detailed SQL statements from successfully committed transactions.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100126pg_grab_statementpg_grab_statement1.0STATGPL-2.0C

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.

CREATE EXTENSION pg_grab_statement;
LOAD 'pg_grab_statement';
SELECT transaction, query_number, username, query_source
FROM grab.statements
ORDER BY transaction, query_number;

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.

Table reader