doc/internal/pgsql_advanced_query_logging_architecture.md
v3.0_pgsql_advanced_loggingThe PostgreSQL logging pipeline now supports advanced query events logging with the same operational model already used by MySQL:
stats and/or stats_historystats_pgsql_global and PrometheusThis implementation is additive. Existing PostgreSQL file-based events log and audit log behavior remains available.
PgSQL_Logger::log_request() builds a PgSQL_Event from session/backend state.pgsql-eventslog_buffer_history_size > 0, the event is deep-copied and inserted into the PostgreSQL events circular buffer.Implemented in:
lib/PgSQL_Logger.cppinclude/PgSQL_Logger.hppA dedicated PgSQL_Logger_CircularBuffer provides:
Runtime resizing is wired in PostgreSQL thread variable refresh:
PgSQL_Thread::refresh_variables() applies eventslog_buffer_history_size changes to the live circular buffer.Implemented in:
include/PgSQL_Logger.hpplib/PgSQL_Logger.cpplib/PgSQL_Thread.cppPgSQL_Logger::processEvents(SQLite3DB* statsdb, SQLite3DB* statsdb_disk) drains the buffer and persists events to:
stats_pgsql_query_events when statsdb != nullptrhistory_pgsql_query_events when statsdb_disk != nullptrBehavior:
pgsql-eventslog_table_memory_size0x...), matching MySQL table stylesqlstate and textual error persisted for failed queriesImplemented in:
lib/PgSQL_Logger.cppstats.stats_pgsql_query_events
Columns:
idthread_idusernamedatabasestart_timeend_timequery_digestqueryserverclientevent_typehidextra_infoaffected_rowsrows_sentclient_stmt_namesqlstateerrorImplemented in:
include/ProxySQL_Admin_Tables_Definitions.hlib/Admin_Bootstrap.cppstats_history.history_pgsql_query_events
Columns match stats_pgsql_query_events.
Indexes:
idx_history_pgsql_query_events_start_time on start_timeidx_history_pgsql_query_events_query_digest on query_digestImplemented in:
include/ProxySQL_Statistics.hpplib/ProxySQL_Statistics.cppPostgreSQL-specific dump commands are now available:
DUMP PGSQL EVENTSLOG FROM BUFFER TO MEMORYDUMP PGSQL EVENTSLOG FROM BUFFER TO DISKDUMP PGSQL EVENTSLOG FROM BUFFER TO BOTHCommand handling executes GloPgSQL_Logger->processEvents(...) with the selected sink targets.
These commands are exposed by the shared Admin module and are available from both Admin protocol endpoints:
60326132Implemented in:
lib/Admin_Handler.cppPostgreSQL thread variables used by advanced logging:
pgsql-eventslog_buffer_history_sizepgsql-eventslog_table_memory_sizepgsql-eventslog_buffer_max_query_lengthAdmin scheduling variable:
admin-stats_pgsql_eventslog_sync_buffer_to_diskImplemented in:
include/PgSQL_Thread.hinclude/proxysql_structs.hinclude/proxysql_admin.hlib/ProxySQL_Admin.cppAdmin main loop now periodically flushes PostgreSQL buffered events to history_pgsql_query_events when:
stats_pgsql_eventslog_sync_buffer_to_disk > 0The same scheduler loop now also invokes MySQL buffered events dump to disk based on stats_mysql_eventslog_sync_buffer_to_disk, ensuring symmetric behavior across both protocols.
Implemented in:
lib/ProxySQL_Admin.cppPostgreSQL logger tracks:
Implemented in:
include/PgSQL_Logger.hpplib/PgSQL_Logger.cppMetrics are exported to stats_pgsql_global with PgSQL_Logger_ prefix.
Implemented in:
lib/ProxySQL_Admin_Stats.cppPrometheus metric family proxysql_pgsql_logger_* is exposed through the serial metrics updater path.
Implemented in:
lib/PgSQL_Logger.cpplib/ProxySQL_Admin.cppDUMP EVENTSLOG ... remains MySQL behavior for compatibility.DUMP PGSQL EVENTSLOG ....sqlstate + error (textual message).database column naming.include/PgSQL_Logger.hpplib/PgSQL_Logger.cpplib/PgSQL_Thread.cpplib/Admin_Handler.cpplib/ProxySQL_Admin.cppinclude/ProxySQL_Admin_Tables_Definitions.hinclude/ProxySQL_Statistics.hpplib/Admin_Bootstrap.cpplib/ProxySQL_Statistics.cpplib/ProxySQL_Admin_Stats.cppImplemented acceptance validation via TAP test:
test/tap/tests/pgsql_query_logging_memory-t.cpptest/tap/tests/pgsql_query_logging_autodump-t.cppCoverage:
stats_pgsql_query_events, history_pgsql_query_events)sqlstate capture for representative PostgreSQL errorserror capture for error rowshistory_pgsql_query_events via admin-stats_pgsql_eventslog_sync_buffer_to_diskTAP group registration:
test/tap/groups/groups.json (pgsql_query_logging_memory-t, pgsql_query_logging_autodump-t)