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.1 |
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.1 |
18 17 16 15 14 | pg_stat_log |
- |
| RPM | PGDG | 0.1 |
18 17 16 15 14 | pg_stat_log_$v |
- |
| DEB | PGDG | 0.1 |
18 17 16 15 14 | postgresql-$v-stat-log |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| el8.aarch64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| el9.x86_64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| el9.aarch64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| el10.x86_64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| el10.aarch64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| d12.x86_64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| d12.aarch64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| d13.x86_64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| d13.aarch64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| u22.x86_64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| u22.aarch64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| u24.x86_64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| u24.aarch64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| u26.x86_64 | PGDG 0.1 | N/A | N/A | N/A | N/A |
| u26.aarch64 | PGDG 0.1 | 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: README, SQL objects, control file
pg_stat_log collects cumulative statistics about PostgreSQL log messages. It hooks into emit_log_hook and counts messages by backend type, database, user, severity, SQLSTATE, and SQLSTATE condition name.
Enable
pg_stat_log requires PostgreSQL 18 or newer and must be preloaded:
Restart PostgreSQL, then create the extension:
View Statistics
The view exposes backend_type, database_oid, database_name, user_oid, user_name, elevel, sqlerrcode, sqlerrcode_name, and count.
Common Queries
Reset And Capacity
pg_stat_log_info() reports max_entries, num_entries, n_dropped, and stats_reset. Increase pg_stat_log.max_entries if n_dropped grows.
Configuration
Settings include pg_stat_log.enabled, pg_stat_log.min_error_level, and pg_stat_log.max_entries.
emit_log_hook only sees messages that reach the server log. log_min_messages therefore acts as a floor for what can be counted.