pg_log_statements
pg_log_statements · Enables log_statement=all selectively for chosen PostgreSQL backend processes or newly started backends matching connection filters.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100431 | pg_log_statements | pg_log_statements | 0.0.2 | STAT | PostgreSQL | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16
Usage
Sources:
pg_log_statements selectively forces log_statement=all for named server processes or for newly authenticated sessions matching a filter. It changes server-log behavior; it does not provide a queryable statement-history table.
Core Workflow
Preload the library, restart PostgreSQL, install the SQL functions, and immediately restrict their execution to an audit administrator.
PID mode uses pgls_start(integer) and pgls_stop(integer). Filter mode accepts application_name, user_name, hostname, ip_address, or database_name and affects only sessions created after the filter is installed. pgls_start_debug() and pgls_stop_debug() toggle authentication-field logging. Because pgls_state() and pgls_conf() return anonymous records, callers must supply column definitions.
Security and Logging Caveats
The extension functions contain no privilege check and receive public execute permission unless revoked. An untrusted user could enable statement logging for other sessions, expose SQL text and embedded secrets to server logs, and generate substantial log volume. Grant execution only to an audited administrator and secure log storage, retention, and access.
PID changes take effect when the target backend next reaches a hooked executor or utility event. Enabling forces log_statement to all; disabling forces it to none rather than restoring a previous session value. Filters are stored in shared memory, are limited in count and value length by the implementation, and disappear on restart. The cataloged extension version is 0.0.2 even though newer repository metadata mentions 0.0.4; match behavior and SQL to the installed package. Upstream reports validation through PostgreSQL 16, so separately test later majors.