From b7b48647298136608521c09f174f2176984bc044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 11 Jul 2025 13:06:37 +0200 Subject: [PATCH 1/6] Fix table definition for 'pgsql_replication_hostgroups' - Reduce 'check_type' range to uniquely supported check ('read_only'). - Added table upgrade procedure. - Fixed missing space in table definition (display for '\G'). --- include/PgSQL_HostGroups_Manager.h | 2 +- include/ProxySQL_Admin_Tables_Definitions.h | 7 +++-- include/proxysql_admin.h | 1 + lib/Admin_Bootstrap.cpp | 3 ++ lib/ProxySQL_Admin_Disk_Upgrade.cpp | 32 +++++++++++++++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/include/PgSQL_HostGroups_Manager.h b/include/PgSQL_HostGroups_Manager.h index ed1d4dcf6..bea625859 100644 --- a/include/PgSQL_HostGroups_Manager.h +++ b/include/PgSQL_HostGroups_Manager.h @@ -46,7 +46,7 @@ #define MYHGM_PgSQL_SERVERS "CREATE TABLE pgsql_servers ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 5432 , weight INT NOT NULL DEFAULT 1 , status INT NOT NULL DEFAULT 0 , compression INT NOT NULL DEFAULT 0 , max_connections INT NOT NULL DEFAULT 1000 , max_replication_lag INT NOT NULL DEFAULT 0 , use_ssl INT NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , mem_pointer INT NOT NULL DEFAULT 0 , PRIMARY KEY (hostgroup_id, hostname, port) )" #define MYHGM_PgSQL_SERVERS_INCOMING "CREATE TABLE pgsql_servers_incoming ( hostgroup_id INT NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 5432 , weight INT NOT NULL DEFAULT 1 , status INT NOT NULL DEFAULT 0 , compression INT NOT NULL DEFAULT 0 , max_connections INT NOT NULL DEFAULT 1000 , max_replication_lag INT NOT NULL DEFAULT 0 , use_ssl INT NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , PRIMARY KEY (hostgroup_id, hostname, port))" #endif /* DEBUG */ -#define MYHGM_PgSQL_REPLICATION_HOSTGROUPS "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only','innodb_read_only','super_read_only','read_only|innodb_read_only','read_only&innodb_read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '' , UNIQUE (reader_hostgroup))" +#define MYHGM_PgSQL_REPLICATION_HOSTGROUPS "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '' , UNIQUE (reader_hostgroup))" #define PGHGM_GEN_ADMIN_RUNTIME_SERVERS "SELECT hostgroup_id, hostname, port, CASE status WHEN 0 THEN \"ONLINE\" WHEN 1 THEN \"SHUNNED\" WHEN 2 THEN \"OFFLINE_SOFT\" WHEN 3 THEN \"OFFLINE_HARD\" WHEN 4 THEN \"SHUNNED\" END status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment FROM pgsql_servers ORDER BY hostgroup_id, hostname, port" diff --git a/include/ProxySQL_Admin_Tables_Definitions.h b/include/ProxySQL_Admin_Tables_Definitions.h index 7a5a5a3c3..c15818cdc 100644 --- a/include/ProxySQL_Admin_Tables_Definitions.h +++ b/include/ProxySQL_Admin_Tables_Definitions.h @@ -276,7 +276,10 @@ #define ADMIN_SQLITE_TABLE_PGSQL_FIREWALL_WHITELIST_SQLI_FINGERPRINTS "CREATE TABLE pgsql_firewall_whitelist_sqli_fingerprints (active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , fingerprint VARCHAR NOT NULL , PRIMARY KEY (fingerprint) )" #define ADMIN_SQLITE_TABLE_PGSQL_QUERY_RULES_FAST_ROUTING "CREATE TABLE pgsql_query_rules_fast_routing (username VARCHAR NOT NULL , database VARCHAR NOT NULL , flagIN INT NOT NULL DEFAULT 0 , destination_hostgroup INT CHECK (destination_hostgroup >= 0) NOT NULL , comment VARCHAR NOT NULL , PRIMARY KEY (username, database, flagIN) )" #define ADMIN_SQLITE_TABLE_PGSQL_HOSTGROUP_ATTRIBUTES "CREATE TABLE pgsql_hostgroup_attributes (hostgroup_id INT NOT NULL PRIMARY KEY , max_num_online_servers INT CHECK (max_num_online_servers>=0 AND max_num_online_servers <= 1000000) NOT NULL DEFAULT 1000000 , autocommit INT CHECK (autocommit IN (-1, 0, 1)) NOT NULL DEFAULT -1 , free_connections_pct INT CHECK (free_connections_pct >= 0 AND free_connections_pct <= 100) NOT NULL DEFAULT 10 , init_connect VARCHAR NOT NULL DEFAULT '' , multiplex INT CHECK (multiplex IN (0, 1)) NOT NULL DEFAULT 1 , connection_warming INT CHECK (connection_warming IN (0, 1)) NOT NULL DEFAULT 0 , throttle_connections_per_sec INT CHECK (throttle_connections_per_sec >= 1 AND throttle_connections_per_sec <= 1000000) NOT NULL DEFAULT 1000000 , ignore_session_variables VARCHAR CHECK (JSON_VALID(ignore_session_variables) OR ignore_session_variables = '') NOT NULL DEFAULT '' , hostgroup_settings VARCHAR CHECK (JSON_VALID(hostgroup_settings) OR hostgroup_settings = '') NOT NULL DEFAULT '' , servers_defaults VARCHAR CHECK (JSON_VALID(servers_defaults) OR servers_defaults = '') NOT NULL DEFAULT '' , comment VARCHAR NOT NULL DEFAULT '')" -#define ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only','innodb_read_only','super_read_only','read_only|innodb_read_only','read_only&innodb_read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '', UNIQUE (reader_hostgroup))" +#define ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS_V3_0_1 "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only','innodb_read_only','super_read_only','read_only|innodb_read_only','read_only&innodb_read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '', UNIQUE (reader_hostgroup))" +#define ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS_V3_0_2 "CREATE TABLE pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '' , UNIQUE (reader_hostgroup))" + +#define ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS_V3_0_2 #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_SERVERS "CREATE TABLE runtime_pgsql_servers (hostgroup_id INT CHECK (hostgroup_id>=0) NOT NULL DEFAULT 0 , hostname VARCHAR NOT NULL , port INT CHECK (port >= 0 AND port <= 65535) NOT NULL DEFAULT 5432 , status VARCHAR CHECK (UPPER(status) IN ('ONLINE','SHUNNED','OFFLINE_SOFT', 'OFFLINE_HARD')) NOT NULL DEFAULT 'ONLINE' , weight INT CHECK (weight >= 0 AND weight <=10000000) NOT NULL DEFAULT 1 , compression INT CHECK (compression IN(0,1)) NOT NULL DEFAULT 0 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000 , max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0 , use_ssl INT CHECK (use_ssl IN(0,1)) NOT NULL DEFAULT 0 , max_latency_ms INT UNSIGNED CHECK (max_latency_ms>=0) NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , PRIMARY KEY (hostgroup_id, hostname, port) )" #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_USERS "CREATE TABLE runtime_pgsql_users (username VARCHAR NOT NULL , password VARCHAR , active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , use_ssl INT CHECK (use_ssl IN (0,1)) NOT NULL DEFAULT 0 , default_hostgroup INT NOT NULL DEFAULT 0 , transaction_persistent INT CHECK (transaction_persistent IN (0,1)) NOT NULL DEFAULT 1 , fast_forward INT CHECK (fast_forward IN (0,1)) NOT NULL DEFAULT 0 , backend INT CHECK (backend IN (0,1)) NOT NULL DEFAULT 1 , frontend INT CHECK (frontend IN (0,1)) NOT NULL DEFAULT 1 , max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000 , attributes VARCHAR CHECK (JSON_VALID(attributes) OR attributes = '') NOT NULL DEFAULT '', comment VARCHAR NOT NULL DEFAULT '' , PRIMARY KEY (username, backend) , UNIQUE (username, frontend))" @@ -287,7 +290,7 @@ #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_FIREWALL_WHITELIST_SQLI_FINGERPRINTS "CREATE TABLE runtime_pgsql_firewall_whitelist_sqli_fingerprints (active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , fingerprint VARCHAR NOT NULL , PRIMARY KEY (fingerprint) )" #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_QUERY_RULES_FAST_ROUTING "CREATE TABLE runtime_pgsql_query_rules_fast_routing (username VARCHAR NOT NULL , database VARCHAR NOT NULL , flagIN INT NOT NULL DEFAULT 0 , destination_hostgroup INT CHECK (destination_hostgroup >= 0) NOT NULL , comment VARCHAR NOT NULL , PRIMARY KEY (username, database, flagIN) )" #define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_HOSTGROUP_ATTRIBUTES "CREATE TABLE runtime_pgsql_hostgroup_attributes (hostgroup_id INT NOT NULL PRIMARY KEY , max_num_online_servers INT CHECK (max_num_online_servers>=0 AND max_num_online_servers <= 1000000) NOT NULL DEFAULT 1000000 , autocommit INT CHECK (autocommit IN (-1, 0, 1)) NOT NULL DEFAULT -1 , free_connections_pct INT CHECK (free_connections_pct >= 0 AND free_connections_pct <= 100) NOT NULL DEFAULT 10 , init_connect VARCHAR NOT NULL DEFAULT '' , multiplex INT CHECK (multiplex IN (0, 1)) NOT NULL DEFAULT 1 , connection_warming INT CHECK (connection_warming IN (0, 1)) NOT NULL DEFAULT 0 , throttle_connections_per_sec INT CHECK (throttle_connections_per_sec >= 1 AND throttle_connections_per_sec <= 1000000) NOT NULL DEFAULT 1000000 , ignore_session_variables VARCHAR CHECK (JSON_VALID(ignore_session_variables) OR ignore_session_variables = '') NOT NULL DEFAULT '' , hostgroup_settings VARCHAR CHECK (JSON_VALID(hostgroup_settings) OR hostgroup_settings = '') NOT NULL DEFAULT '' , servers_defaults VARCHAR CHECK (JSON_VALID(servers_defaults) OR servers_defaults = '') NOT NULL DEFAULT '' , comment VARCHAR NOT NULL DEFAULT '')" -#define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_REPLICATION_HOSTGROUPS "CREATE TABLE runtime_pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only','innodb_read_only','super_read_only','read_only|innodb_read_only','read_only&innodb_read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '', UNIQUE (reader_hostgroup))" +#define ADMIN_SQLITE_TABLE_RUNTIME_PGSQL_REPLICATION_HOSTGROUPS "CREATE TABLE runtime_pgsql_replication_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>=0) , check_type VARCHAR CHECK (LOWER(check_type) IN ('read_only')) NOT NULL DEFAULT 'read_only' , comment VARCHAR NOT NULL DEFAULT '' , UNIQUE (reader_hostgroup))" #define STATS_SQLITE_TABLE_PGSQL_GLOBAL "CREATE TABLE stats_pgsql_global (Variable_Name VARCHAR NOT NULL PRIMARY KEY , Variable_Value VARCHAR NOT NULL)" #define STATS_SQLITE_TABLE_PGSQL_CONNECTION_POOL "CREATE TABLE stats_pgsql_connection_pool (hostgroup INT , srv_host VARCHAR , srv_port INT , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , MaxConnUsed INT , Queries INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT)" diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 0e54493ba..c33060004 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -425,6 +425,7 @@ class ProxySQL_Admin { void disk_upgrade_mysql_users(); void disk_upgrade_scheduler(); void disk_upgrade_rest_api_routes(); + void disk_upgrade_pgsql_replication_hostgroups(); #ifdef DEBUG template diff --git a/lib/Admin_Bootstrap.cpp b/lib/Admin_Bootstrap.cpp index 67dbdda97..843d06f30 100644 --- a/lib/Admin_Bootstrap.cpp +++ b/lib/Admin_Bootstrap.cpp @@ -726,6 +726,9 @@ bool ProxySQL_Admin::init(const bootstrap_info_t& bootstrap_info) { // upgrade restapi_routes if needed (upgrade from previous version) disk_upgrade_rest_api_routes(); + // upgrade pgsql_replication_hostgroups if needed (upgrade from previous version) + disk_upgrade_pgsql_replication_hostgroups(); + check_and_build_standard_tables(admindb, tables_defs_admin); check_and_build_standard_tables(configdb, tables_defs_config); check_and_build_standard_tables(statsdb, tables_defs_stats); diff --git a/lib/ProxySQL_Admin_Disk_Upgrade.cpp b/lib/ProxySQL_Admin_Disk_Upgrade.cpp index 6da7b8813..22036f229 100644 --- a/lib/ProxySQL_Admin_Disk_Upgrade.cpp +++ b/lib/ProxySQL_Admin_Disk_Upgrade.cpp @@ -608,3 +608,35 @@ void ProxySQL_Admin::disk_upgrade_rest_api_routes() { configdb->execute("PRAGMA foreign_keys = ON"); } + +void ProxySQL_Admin::disk_upgrade_pgsql_replication_hostgroups() { + configdb->execute("PRAGMA foreign_keys = OFF"); + + int rci = configdb->check_table_structure( + const_cast("pgsql_replication_hostgroups"), + const_cast(ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS_V3_0_1) + ); + + if (rci) { + // upgrade is required + proxy_warning("Detected version pre-3.0.2 of table 'pgsql_replication_hostgroups'\n"); + proxy_warning("ONLINE UPGRADE of table 'pgsql_replication_hostgroups' in progress\n"); + // drop any existing table with suffix _v301 + configdb->execute("DROP TABLE IF EXISTS pgsql_replication_hostgroups_v301"); + // rename current table to add suffix _v301 + configdb->execute("ALTER TABLE pgsql_replication_hostgroups RENAME TO pgsql_replication_hostgroups_v301"); + // create new table + configdb->build_table( + const_cast("pgsql_replication_hostgroups"), + const_cast(ADMIN_SQLITE_TABLE_PGSQL_REPLICATION_HOSTGROUPS), + false + ); + // copy fields from old table + configdb->execute( + "INSERT INTO pgsql_replication_hostgroups(writer_hostgroup, reader_hostgroup, check_type, comment)" + " SELECT writer_hostgroup, reader_hostgroup, 'read_only', comment FROM pgsql_replication_hostgroups_v301" + ); + } + + configdb->execute("PRAGMA foreign_keys = ON"); +} From 0de642559d9dacdbf326e45ed020bc34d1f44dc8 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Mon, 21 Jul 2025 13:27:09 +0500 Subject: [PATCH 2/6] Avoid crash when mirroring is set for PostgreSQL: show warning instead --- lib/PgSQL_Session.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/PgSQL_Session.cpp b/lib/PgSQL_Session.cpp index a66cf63b1..99c813461 100644 --- a/lib/PgSQL_Session.cpp +++ b/lib/PgSQL_Session.cpp @@ -2443,7 +2443,14 @@ __get_pkts_from_client: } } if (mirror == false) { - handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___create_mirror_session(); + if (qpo->mirror_hostgroup >= 0 || qpo->mirror_flagOUT >= 0) { + const char* query_text = CurrentQuery.get_digest_text(); + proxy_warning("ProxySQL does not currently support query mirroring for PostgreSQL. " + "The mirror flag(s) will be ignored, but other query rule conditions will still apply. " + "(mirror_hostgroup=%d, mirror_flagOUT=%d, query='%s')\n", + qpo->mirror_hostgroup, qpo->mirror_flagOUT, query_text ? query_text : ""); + } + //handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___create_mirror_session(); } if (autocommit_on_hostgroup >= 0) { From 8ddd2531bbb37dcfe87c471a66c438332cf46e6f Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 8 Aug 2025 08:26:16 +0000 Subject: [PATCH 3/6] bump version to 3.0.3 at the beginning of the development cycle --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 01aa57306..e34ff5629 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ O3 := -O3 -mtune=native ALL_DEBUG := $(O0) -ggdb -DDEBUG NO_DEBUG := $(O2) -ggdb DEBUG := $(ALL_DEBUG) -CURVER ?= 3.0.2 +CURVER ?= 3.0.3 #export DEBUG #export EXTRALINK export MAKE From 0a0336ecd1abf59d4ba36875ca26991b711b5bf0 Mon Sep 17 00:00:00 2001 From: Wazir Ahmed Date: Tue, 12 Aug 2025 08:27:30 +0530 Subject: [PATCH 4/6] fix: REST API server crash due to malformed multipart POST request - Disable POST preprocessing option in `libhttpserver`. - Validate `Context-Type` header in request handler for `POST /sync` Fixes #5072 Signed-off-by: Wazir Ahmed --- lib/ProxySQL_RESTAPI_Server.cpp | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/ProxySQL_RESTAPI_Server.cpp b/lib/ProxySQL_RESTAPI_Server.cpp index 9aebb337f..d9a697977 100644 --- a/lib/ProxySQL_RESTAPI_Server.cpp +++ b/lib/ProxySQL_RESTAPI_Server.cpp @@ -306,15 +306,32 @@ public: } const std::shared_ptr render_POST(const http_request& req) { - std::string params=req.get_content(); - + std::string req_path = req.get_path(); + std::string req_body = req.get_content(); + std::string content_type = req.get_header(http::http_utils::http_header_content_type); + + // validate Context-Type header + // reject unsupported content types + if (!content_type.empty() && + content_type.find("application/json") == std::string::npos && + content_type.find("text/json") == std::string::npos && + content_type.find("text/plain") == std::string::npos) { #ifdef DEBUG - const char* req_path { req.get_path().c_str() }; - const char* p_params { params.c_str() }; - proxy_debug(PROXY_DEBUG_RESTAPI, 1, "Processing POST - req: '%s', params: `%s`\n", req_path, p_params); + proxy_debug(PROXY_DEBUG_RESTAPI, 1, "Rejected POST - req: '%s', content-type: '%s', req_body: `%s`\n", + req_path.c_str(), content_type.c_str(), req_body.c_str()); #endif + auto response = std::shared_ptr(new string_response( + "{\"error\": \"Unsupported Content-Type\"}", + http::http_utils::http_unsupported_media_type + )); + add_headers(response); + return response; + } - return process_request(req, params); +#ifdef DEBUG + proxy_debug(PROXY_DEBUG_RESTAPI, 1, "Processing POST - req: '%s', params: `%s`\n", req_path.c_str(), req_body.c_str()); +#endif + return process_request(req, req_body); } }; @@ -352,9 +369,15 @@ ProxySQL_RESTAPI_Server::ProxySQL_RESTAPI_Server( // in the current mode concurrency on serving requests is low, and throughput is directly related with // the time required to execute the target script, since each of the calls are blocking. #if defined(__FreeBSD__) || defined(__APPLE__) - ws = std::unique_ptr(new webserver(create_webserver(p).start_method(http::http_utils::start_method_T::THREAD_PER_CONNECTION))); + ws = std::unique_ptr(new webserver( + create_webserver(p) + .no_post_process() + .start_method(http::http_utils::start_method_T::THREAD_PER_CONNECTION) + )); #else - ws = std::unique_ptr(new webserver(create_webserver(p))); + ws = std::unique_ptr(new webserver( + create_webserver(p).no_post_process() + )); #endif // NOTE: Enable for benchmarking purposes. In this mode each request will be served by it's own thread. // ws = std::unique_ptr(new webserver(create_webserver(p).start_method(http::http_utils::start_method_T::THREAD_PER_CONNECTION))); @@ -392,4 +415,3 @@ void ProxySQL_RESTAPI_Server::init() { void ProxySQL_RESTAPI_Server::print_version() { fprintf(stderr,"Standard ProxySQL REST API Server Handler rev. %s -- %s -- %s\n", PROXYSQL_RESTAPI_SERVER_VERSION, __FILE__, __TIMESTAMP__); } - From ae96637af953b3db9e2493d038740a4c35b9e152 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 22 Aug 2025 10:06:07 +0200 Subject: [PATCH 5/6] add GH Actions trigger for pgJDBC testing --- .github/workflows/CI-3p-pgjdbc.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/CI-3p-pgjdbc.yml diff --git a/.github/workflows/CI-3p-pgjdbc.yml b/.github/workflows/CI-3p-pgjdbc.yml new file mode 100644 index 000000000..d49aacee4 --- /dev/null +++ b/.github/workflows/CI-3p-pgjdbc.yml @@ -0,0 +1,29 @@ +name: CI-3p-pgjdbc +run-name: '${{ github.event.workflow_run && github.event.workflow_run.head_branch || github.ref_name }} ${{ github.workflow }} ${{ github.event.workflow_run && github.event.workflow_run.head_sha || github.sha }}' + +on: + workflow_dispatch: + inputs: + testtree: + description: 'proxysql_3p_testing treeish/branch/tag/hash' + default: main + type: string + workflow_run: + workflows: [ CI-trigger ] + types: [ completed ] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run && github.event.workflow_run.head_branch || github.ref_name }} + cancel-in-progress: true + +jobs: + run-pgsql: + if: | + (github.event.workflow_run && github.event.workflow_run.conclusion == 'success' || ! github.event.workflow_run) && + ! startsWith((github.event.workflow_run && github.event.workflow_run.head_branch || github.ref_name), 'v2.') + uses: sysown/proxysql/.github/workflows/ci-3p-pgjdbc.yml@GH-Actions + secrets: inherit + with: + trigger: ${{ toJson(github) }} + infradb: ${{ vars.MATRIX_3P_PGJDBC_infradb_pgsql }} + connector: ${{ vars.MATRIX_3P_PGJDBC_connector_pgsql }} From 8d8577b0ad5c637d57ee0956dfdc04cc2355d546 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Thu, 28 Aug 2025 15:52:50 +0500 Subject: [PATCH 6/6] Ensure PgSQL_Threads_Handler and PgSQL_HostGroups_Manager objects are released when ProxySQL shuts down or restarts. --- include/PgSQL_HostGroups_Manager.h | 6 ------ include/proxysql_glovars.hpp | 2 +- lib/PgSQL_HostGroups_Manager.cpp | 12 ++---------- lib/PgSQL_Thread.cpp | 4 ++-- lib/ProxySQL_GloVars.cpp | 1 + src/main.cpp | 22 +++++++++++++++++++++- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/include/PgSQL_HostGroups_Manager.h b/include/PgSQL_HostGroups_Manager.h index bea625859..1f44aaf11 100644 --- a/include/PgSQL_HostGroups_Manager.h +++ b/include/PgSQL_HostGroups_Manager.h @@ -557,12 +557,6 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager { SQLite3_result* incoming_pgsql_servers_v2; - std::thread *HGCU_thread; - - std::thread *GTID_syncer_thread; - //pthread_t GTID_syncer_thread_id; - //pthread_t HGCU_thread_id; - char rand_del[8]; pthread_mutex_t pgsql_errors_mutex; umap_pgsql_errors pgsql_errors_umap; diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index f758662d3..c5b52b2db 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -137,7 +137,7 @@ class ProxySQL_GlobalVariables { char* gr_bootstrap_ssl_key; char* gr_bootstrap_ssl_mode; pthread_mutex_t ext_glomth_mutex; - + pthread_mutex_t ext_glopth_mutex; bool ssl_keylog_enabled; } global; struct mysql { diff --git a/lib/PgSQL_HostGroups_Manager.cpp b/lib/PgSQL_HostGroups_Manager.cpp index 7aa3c9f17..47758aef4 100644 --- a/lib/PgSQL_HostGroups_Manager.cpp +++ b/lib/PgSQL_HostGroups_Manager.cpp @@ -740,19 +740,11 @@ PgSQL_HostGroups_Manager::PgSQL_HostGroups_Manager() { } void PgSQL_HostGroups_Manager::init() { - // gtid initialization; - //GTID_syncer_thread = new std::thread(>ID_syncer_run); - GTID_syncer_thread = nullptr; - - //pthread_create(>ID_syncer_thread_id, NULL, GTID_syncer_run , NULL); + // do nothing here } void PgSQL_HostGroups_Manager::shutdown() { - HGCU_thread->join(); - delete HGCU_thread; - ev_async_send(gtid_ev_loop, gtid_ev_async); - GTID_syncer_thread->join(); - delete GTID_syncer_thread; + // do nothing here } PgSQL_HostGroups_Manager::~PgSQL_HostGroups_Manager() { diff --git a/lib/PgSQL_Thread.cpp b/lib/PgSQL_Thread.cpp index 8461e891e..06ebdf870 100644 --- a/lib/PgSQL_Thread.cpp +++ b/lib/PgSQL_Thread.cpp @@ -3736,7 +3736,7 @@ void PgSQL_Thread::process_all_sessions() { } void PgSQL_Thread::refresh_variables() { - pthread_mutex_lock(&GloVars.global.ext_glomth_mutex); + pthread_mutex_lock(&GloVars.global.ext_glopth_mutex); if (GloPTH == NULL) { return; } @@ -3981,7 +3981,7 @@ void PgSQL_Thread::refresh_variables() { #endif // DEBUG */ GloPTH->wrunlock(); - pthread_mutex_unlock(&GloVars.global.ext_glomth_mutex); + pthread_mutex_unlock(&GloVars.global.ext_glopth_mutex); } PgSQL_Thread::PgSQL_Thread() { diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index 7273fd15b..c59c891b1 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -209,6 +209,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() : pthread_mutex_init(&global.start_mutex,NULL); pthread_mutex_init(&checksum_mutex,NULL); pthread_mutex_init(&global.ext_glomth_mutex,NULL); + pthread_mutex_init(&global.ext_glopth_mutex, NULL); epoch_version = 0; checksums_values.updates_cnt = 0; checksums_values.dumped_at = 0; diff --git a/src/main.cpp b/src/main.cpp index 3b79ae04c..71d25c40e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1248,6 +1248,16 @@ void ProxySQL_Main_shutdown_all_modules() { pthread_mutex_unlock(&GloVars.global.ext_glomth_mutex); #ifdef DEBUG std::cerr << "GloMTH shutdown in "; +#endif + } + if (GloPTH) { + cpu_timer t; + pthread_mutex_lock(&GloVars.global.ext_glopth_mutex); + delete GloPTH; + GloPTH = NULL; + pthread_mutex_unlock(&GloVars.global.ext_glopth_mutex); +#ifdef DEBUG + std::cerr << "GloPTH shutdown in "; #endif } if (GloMyLogger) { @@ -1277,12 +1287,22 @@ void ProxySQL_Main_shutdown_all_modules() { std::cerr << "GloAdmin shutdown in "; #endif } + if (MyHGM) { cpu_timer t; MyHGM->shutdown(); delete MyHGM; #ifdef DEBUG - std::cerr << "GloHGM shutdown in "; + std::cerr << "GloMyHGM shutdown in "; +#endif + } + if (PgHGM) + { + cpu_timer t; + PgHGM->shutdown(); + delete PgHGM; +#ifdef DEBUG + std::cerr << "GloPgHGM shutdown in "; #endif } if (GloMyStmt) {