pg_stat_log
pg_stat_log : Track cumulative PostgreSQL log message statistics by backend, database, user, level, and SQLSTATE.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 6040 | pg_stat_log | pg_stat_log | 0.3 |
STAT | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sLd-r | No | Yes | Yes | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pgelog logerrors pg_sqlog log_fdw pgaudit pgdisablelogerror pg_auth_mon pg_tracing pg_stat_backtrace pgfr_record |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 0.3 |
18 17 16 15 14 | pg_stat_log |
- |
| RPM | PGDG | 0.3 |
18 17 16 15 14 | pg_stat_log_$v |
- |
| DEB | PGDG | 0.2 |
18 17 16 15 14 | postgresql-$v-stat-log |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG 0.3 | N/A | N/A | N/A | N/A |
| el8.aarch64 | PGDG 0.3 | N/A | N/A | N/A | N/A |
| el9.x86_64 | PGDG 0.3 | N/A | N/A | N/A | N/A |
| el9.aarch64 | PGDG 0.3 | N/A | N/A | N/A | N/A |
| el10.x86_64 | PGDG 0.3 | N/A | N/A | N/A | N/A |
| el10.aarch64 | PGDG 0.3 | N/A | N/A | N/A | N/A |
| d12.x86_64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| d12.aarch64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| d13.x86_64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| d13.aarch64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| u22.x86_64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| u22.aarch64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| u24.x86_64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| u24.aarch64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| u26.x86_64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
| u26.aarch64 | PGDG 0.2 | N/A | N/A | N/A | N/A |
Source
github.com/fabriziomello/pg_stat_log
Install
Make sure PGDG repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
Create this extension with:
Usage
Sources:
pg_stat_log 0.3 collects PostgreSQL 18+ log-message counts by backend, database, role, severity and SQLSTATE, with optional grouping by query identifier. Add the library to the existing preload list and restart before creating the SQL extension. The default SQL grants allow pg_read_all_stats to inspect the counters.
Core Workflow
Operational Boundaries
The pg_stat_log view resolves names from pg_stat_log_data(). pg_stat_log_info() reports max_entries, num_entries, n_dropped and stats_reset; pg_stat_log_reset() clears counters and frees capacity, and is restricted by default. pg_stat_log.enabled and pg_stat_log.min_error_level control collection, with defaults true and warning. Only messages reaching the server log are counted: log_min_messages can filter messages before the hook runs, and caught exceptions are absent. Parallel-worker messages can count the same logical failure more than once.
pg_stat_log.compute_query_id defaults to off and requires restart to change; PostgreSQL’s compute_query_id must not be off. A missing query identifier appears as NULL. pg_stat_log.max_entries defaults to 1024, requires restart, and drops new combinations when full; inspect n_dropped. Changing this capacity resets all PostgreSQL cumulative statistics on the next start. Counters survive clean restarts, but drop telemetry does not, and crash recovery discards cumulative statistics.
Version 0.3 maps connection authentication, authorization and disconnection to PSL01, PSL02 and PSL03. Collection needs the corresponding server logging plus pg_stat_log.min_error_level = 'log' or lower; the role attribution is the login role.
Upstream releases 0.1 and 0.2 both install SQL version 0.1. Moving to 0.3 requires matching library files and a restart; the first start resets all PostgreSQL cumulative statistics. Then run ALTER EXTENSION pg_stat_log UPDATE TO '0.3' in each installed database. The update recreates the reporting view and function: drop and recreate dependent views and reapply custom grants; the default grants to pg_read_all_stats are restored.