From cc1d93d08b752f958553008705e18294482616d9 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 23 Jan 2026 09:17:41 +0000 Subject: [PATCH 1/2] implement admin command 'PROXYSQL FLUSH STATS' for DEBUG builds --- include/proxysql_admin.h | 7 +++++++ lib/Admin_Handler.cpp | 26 ++++++++++++++++++++++++++ lib/ProxySQL_Admin.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index d359a1879..d600f391c 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -845,5 +845,12 @@ class ProxySQL_Admin { // FLUSH LOGS void flush_logs(); + +#ifdef DEBUG + // FLUSH STATS + void flush_stats(); // Reset all statistics + void flush_mysql_stats(); // Reset MySQL statistics only + void flush_pgsql_stats(); // Reset PostgreSQL statistics only +#endif // DEBUG }; #endif /* __CLASS_PROXYSQL_ADMIN_H */ diff --git a/lib/Admin_Handler.cpp b/lib/Admin_Handler.cpp index 288ca2a85..52485e87f 100644 --- a/lib/Admin_Handler.cpp +++ b/lib/Admin_Handler.cpp @@ -776,6 +776,32 @@ bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_ return false; } +#ifdef DEBUG + if (query_no_space_length == strlen("PROXYSQL FLUSH STATS") && !strncasecmp("PROXYSQL FLUSH STATS", query_no_space, query_no_space_length)) { + proxy_info("Received PROXYSQL FLUSH STATS command\n"); + ProxySQL_Admin *SPA = (ProxySQL_Admin *)pa; + SPA->flush_stats(); + SPA->send_ok_msg_to_client(sess, NULL, 0, query_no_space); + return false; + } + + if (query_no_space_length == strlen("PROXYSQL FLUSH MYSQL STATS") && !strncasecmp("PROXYSQL FLUSH MYSQL STATS", query_no_space, query_no_space_length)) { + proxy_info("Received PROXYSQL FLUSH MYSQL STATS command\n"); + ProxySQL_Admin *SPA = (ProxySQL_Admin *)pa; + SPA->flush_mysql_stats(); + SPA->send_ok_msg_to_client(sess, NULL, 0, query_no_space); + return false; + } + + if (query_no_space_length == strlen("PROXYSQL FLUSH PGSQL STATS") && !strncasecmp("PROXYSQL FLUSH PGSQL STATS", query_no_space, query_no_space_length)) { + proxy_info("Received PROXYSQL FLUSH PGSQL STATS command\n"); + ProxySQL_Admin *SPA = (ProxySQL_Admin *)pa; + SPA->flush_pgsql_stats(); + SPA->send_ok_msg_to_client(sess, NULL, 0, query_no_space); + return false; + } +#endif // DEBUG + if (strcasecmp("PROXYSQL RELOAD TLS",query_no_space) == 0) { proxy_info("Received %s command\n", query_no_space); ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index ebd2a2301..adf0a19f0 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -1106,6 +1106,46 @@ void ProxySQL_Admin::flush_logs() { proxy_debug(PROXY_DEBUG_ADMIN, 1, "Running PROXYSQL FLUSH LOGS\n"); } +#ifdef DEBUG +void ProxySQL_Admin::flush_stats() { + flush_mysql_stats(); + flush_pgsql_stats(); +} + +void ProxySQL_Admin::flush_mysql_stats() { + if (!GloMyQPro || !GloMTH || !MyHGM) { + proxy_info("MySQL statistics flush skipped: MySQL modules not initialized\n"); + return; + } + // Reset MySQL query digest statistics + stats___mysql_query_digests_v2(true, false, false); + // Reset MySQL error statistics + stats___mysql_errors(true); + // Reset MySQL connection pool statistics + stats___mysql_connection_pool(true); + // Reset MySQL client host cache + stats___mysql_client_host_cache(true); + + proxy_info("MySQL statistics flushed successfully\n"); +} + +void ProxySQL_Admin::flush_pgsql_stats() { + if (!GloPgQPro || !GloPTH || !PgHGM) { + proxy_info("PgSQL statistics flush skipped: PgSQL modules not initialized\n"); + return; + } + // Reset PostgreSQL query digest statistics + stats___pgsql_query_digests_v2(true, false, false); + // Reset PostgreSQL error statistics + stats___pgsql_errors(true); + // Reset PostgreSQL connection pool statistics + stats___pgsql_connection_pool(true); + // Reset PostgreSQL client host cache + stats___pgsql_client_host_cache(true); + + proxy_info("PgSQL statistics flushed successfully\n"); +} +#endif // DEBUG // Explicitly instantiate the required template class and member functions template void ProxySQL_Admin::send_ok_msg_to_client(MySQL_Session*, char const*, int, char const*); From 2b0c741892da3e39c941355c65b1d37254278f13 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Thu, 5 Feb 2026 13:51:39 +0000 Subject: [PATCH 2/2] Add TAP test for FLUSH STATS commands Add tests for PROXYSQL FLUSH STATS, PROXYSQL FLUSH MYSQL STATS, and PROXYSQL FLUSH PGSQL STATS admin commands. --- test/tap/tests/admin_various_commands2-t.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/tap/tests/admin_various_commands2-t.cpp b/test/tap/tests/admin_various_commands2-t.cpp index a412abc27..658a7cc3a 100644 --- a/test/tap/tests/admin_various_commands2-t.cpp +++ b/test/tap/tests/admin_various_commands2-t.cpp @@ -27,6 +27,9 @@ std::vector queries = { "PROXYSQL FLUSH LOGS", "PROXYSQL FLUSH QUERY CACHE", "PROXYSQL FLUSH CONFIGDB", + "PROXYSQL FLUSH STATS", + "PROXYSQL FLUSH MYSQL STATS", + "PROXYSQL FLUSH PGSQL STATS", "PROXYSQLTEST 21", "PROXYSQLTEST 21 10", "PROXYSQLTEST 41",