github fabriziomello/pg_stat_log 0.1

one month ago

pg_stat_log v0.1

First official release of pg_stat_log, a PostgreSQL extension that collects cumulative statistics about log messages using the Custom Cumulative Stats API introduced in PostgreSQL 18.

What it does

Hooks into emit_log_hook to count log messages grouped by (backend_type, database, user, error level, SQLSTATE code). Exposes the data through the pg_stat_log view and the pg_stat_log_data() function. Statistics persist across clean restarts and are discarded after crash recovery, following standard PostgreSQL cumulative stats semantics.

Custom stats kind ID 28, registered on the PostgreSQL wiki.

Requirements

  • PostgreSQL 18 or later
  • Must be loaded via shared_preload_libraries

Features

  • pg_stat_log view with LEFT JOINs against pg_database and pg_roles for human-readable names
  • pg_stat_log_info() function exposing capacity metadata: max_entries, num_entries, n_dropped, stats_reset
  • pg_stat_log_reset() to clear all counters and reclaim slots (superuser-only)

Configuration

Parameter Type Default Context Description
pg_stat_log.enabled bool true SUSET Enable/disable collection at runtime
pg_stat_log.min_error_level enum warning SUSET Minimum severity to track
pg_stat_log.max_entries int 1024 POSTMASTER Max distinct combinations (requires restart)

Privileges

Function/View Access
pg_stat_log view pg_read_all_stats
pg_stat_log_data() pg_read_all_stats
pg_stat_log_info() pg_read_all_stats
pg_stat_log_reset() Superuser only

Compatibility

  • PostgreSQL 18 (primary target)
  • PostgreSQL 19 (with #if PG_VERSION_NUM compat guards for server_message_level_options and LWLockNewTrancheId API changes)

Acknowledgements

Thanks to Nikolay Samokhvalov for thorough code reviews, adversarial testing, and feature contributions including pg_stat_log_info(), n_dropped counter, and slot reclamation on reset.

Don't miss a new pg_stat_log release

NewReleases is sending notifications on new releases.