From b100235fbdf04fe3ce387f2188f624dba13c565c Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Wed, 18 Feb 2026 09:38:53 +0000 Subject: [PATCH] Add PGSQL eventslog dump commands and periodic disk sync scheduling --- lib/Admin_Handler.cpp | 27 +++++++++++++++++++++++++++ lib/ProxySQL_Admin.cpp | 20 ++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/Admin_Handler.cpp b/lib/Admin_Handler.cpp index d36bb3566..6f299f262 100644 --- a/lib/Admin_Handler.cpp +++ b/lib/Admin_Handler.cpp @@ -3190,6 +3190,33 @@ void admin_session_handler(S* sess, void *_pa, PtrSize_t *pkt) { goto __run_query; } + if (!strncasecmp("DUMP PGSQL EVENTSLOG ", query_no_space, strlen("DUMP PGSQL EVENTSLOG "))) { + int num_rows = 0; + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received command DUMP PGSQL EVENTSLOG: %s\n", query_no_space); + proxy_info("Received command DUMP PGSQL EVENTSLOG: %s\n", query_no_space); + + std::map> commandMap = { + {"DUMP PGSQL EVENTSLOG FROM BUFFER TO MEMORY", {SPA->statsdb, nullptr}}, + {"DUMP PGSQL EVENTSLOG FROM BUFFER TO DISK", {nullptr, SPA->statsdb_disk}}, + {"DUMP PGSQL EVENTSLOG FROM BUFFER TO BOTH", {SPA->statsdb, SPA->statsdb_disk}} + }; + + string s = string(query_no_space); + auto it = commandMap.find(s); + if (it != commandMap.end()) { + if (GloPgSQL_Logger != nullptr) { + num_rows = GloPgSQL_Logger->processEvents(it->second.first, it->second.second); + } + SPA->send_ok_msg_to_client(sess, NULL, num_rows, query_no_space); + } else { + proxy_warning("Received invalid command DUMP PGSQL EVENTSLOG: %s\n", query_no_space); + const string err_msg = "Invalid DUMP PGSQL EVENTSLOG command"; + SPA->send_error_msg_to_client(sess, const_cast(err_msg.c_str())); + } + run_query = false; + goto __run_query; + } + // handle special queries from Cluster // for bug #1188 , ProxySQL Admin needs to know the exact query diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 7523aaace..b09781280 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -2511,6 +2511,26 @@ __end_while_pool: curtime2 = curtime2/1000; proxy_info("Automatically saved stats_mysql_query_digest to disk: %llums to write %d entries\n", curtime2-curtime1, r1); } + if (GloProxyStats->MySQL_Logger_dump_eventslog_timetoget(curtime)) { + if (GloMyLogger != nullptr) { + unsigned long long curtime1 = monotonic_time(); + int r1 = GloMyLogger->processEvents(nullptr, SPA->statsdb_disk); + unsigned long long curtime2 = monotonic_time(); + curtime1 = curtime1 / 1000; + curtime2 = curtime2 / 1000; + proxy_info("Automatically dumped MySQL eventslog buffer to disk: %llums to write %d entries\n", curtime2 - curtime1, r1); + } + } + if (GloProxyStats->PgSQL_Logger_dump_eventslog_timetoget(curtime)) { + if (GloPgSQL_Logger != nullptr) { + unsigned long long curtime1 = monotonic_time(); + int r1 = GloPgSQL_Logger->processEvents(nullptr, SPA->statsdb_disk); + unsigned long long curtime2 = monotonic_time(); + curtime1 = curtime1 / 1000; + curtime2 = curtime2 / 1000; + proxy_info("Automatically dumped PgSQL eventslog buffer to disk: %llums to write %d entries\n", curtime2 - curtime1, r1); + } + } if (GloProxyStats->system_cpu_timetoget(curtime)) { GloProxyStats->system_cpu_sets(); }