Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ba5af97
feat-wip: Add replication lag support for PostgreSQL monitoring
JavierJF Feb 19, 2026
d18fd15
feat: Improve error report for TAP utility function 'CHECK_EXT_VAL'
JavierJF Feb 24, 2026
cbce305
feat-wip: Add initial version of TAP test for replication_lag
JavierJF Feb 20, 2026
b14f882
fix: compilation of 'cpp-dotenv' for newer CMake versions
JavierJF Feb 24, 2026
b7e98f1
feat: add new TAP group infra for PostgreSQL replication testing
JavierJF Feb 24, 2026
86590fc
test: add 'test_pgsql_replication_lag-t.cpp' to new 'pgsql-repl' TAP …
JavierJF Feb 24, 2026
4103d69
feat: disable 'pt-heartbeat' support for PostgreSQL
JavierJF Feb 24, 2026
a4ea3b2
Merge branch 'v3.0' of github.com:sysown/proxysql into v3.0-pgsql_mon…
JavierJF Feb 24, 2026
36348fa
fix: minor escaping issues with 'pgsql-repl' infra scripts
JavierJF Feb 25, 2026
35254fa
fix: typo in 'pgsql-repl' infra script message
JavierJF Feb 25, 2026
0132075
fix: simplified expression in 'test_pgsql_replication_lag' TAP scripts
JavierJF Feb 25, 2026
ff729a6
chore: disable 'pt-heartbeat' in 'PgSQL_Threads_Handler::get_variable'
JavierJF Feb 25, 2026
5f347c1
chore: remove test cert files incorrectly pushed to TAP dir
JavierJF Feb 25, 2026
26c6eab
fix: improve error reporting for sqlite3 TAP utils
JavierJF Feb 25, 2026
c4fc60b
fix: address security and logic issues in PostgreSQL replication lag …
renecannao Mar 6, 2026
16f8837
Merge branch 'v3.0' into v3.0-pgsql_monitor_repl_lag
renecannao Mar 6, 2026
f45173b
fix: make cmake3 discovery in test deps portable
renecannao Mar 6, 2026
1911b02
feat: temporarily disable pgsql monitor replication lag group_by_host
renecannao Mar 6, 2026
ff1398e
fix: plumb real hostgroup_id for pgsql replication lag monitoring
renecannao Mar 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/PgSQL_Monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#define MONITOR_SQLITE_TABLE_PGSQL_SERVER_READ_ONLY_LOG "CREATE TABLE pgsql_server_read_only_log ( hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , time_start_us INT NOT NULL DEFAULT 0 , success_time_us INT DEFAULT 0 , read_only INT DEFAULT 1 , error VARCHAR , PRIMARY KEY (hostname, port, time_start_us))"

#define MONITOR_SQLITE_TABLE_PGSQL_SERVER_REPLICATION_LAG_LOG "CREATE TABLE pgsql_server_replication_lag_log ( hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , time_start_us INT NOT NULL DEFAULT 0 , success_time_us INT DEFAULT 0 , repl_lag INT DEFAULT 0 , error VARCHAR , PRIMARY KEY (hostname, port, time_start_us))"

Check failure on line 19 in include/PgSQL_Monitor.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this macro by "const", "constexpr" or an "enum".

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AZyQ4zI0kv9arOIsq09j&open=AZyQ4zI0kv9arOIsq09j&pullRequest=5422

#define MONITOR_SQLITE_TABLE_PGSQL_SERVERS "CREATE TABLE pgsql_servers (hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306 , status INT CHECK (status IN (0, 1, 2, 3, 4)) NOT NULL DEFAULT 0 , use_ssl INT CHECK (use_ssl IN(0,1)) NOT NULL DEFAULT 0 , PRIMARY KEY (hostname, port) )"

#define MONITOR_SQLITE_TABLE_PROXYSQL_SERVERS "CREATE TABLE proxysql_servers (hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 6032 , weight INT CHECK (weight >= 0) NOT NULL DEFAULT 0 , comment VARCHAR NOT NULL DEFAULT '' , PRIMARY KEY (hostname, port) )"
Expand All @@ -39,6 +41,8 @@
uint64_t ping_check_OK { 0 };
uint64_t readonly_check_ERR { 0 };
uint64_t readonly_check_OK { 0 };
uint64_t repl_lag_check_ERR { 0 };
uint64_t repl_lag_check_OK { 0 };
uint64_t ssl_connections_OK { 0 };
uint64_t non_ssl_connections_OK { 0 };
///////////////////////////////////////////////////////////////////////////
Expand All @@ -56,6 +60,10 @@
const_cast<char*>("pgsql_server_read_only_log"),
const_cast<char*>(MONITOR_SQLITE_TABLE_PGSQL_SERVER_READ_ONLY_LOG)
},
{
const_cast<char*>("pgsql_server_replication_lag_log"),

Check failure on line 64 in include/PgSQL_Monitor.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

const_cast removing const qualification from the type of a pointer may lead to an undefined behaviour.

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AZyQ4zI0kv9arOIsq09k&open=AZyQ4zI0kv9arOIsq09k&pullRequest=5422
const_cast<char*>(MONITOR_SQLITE_TABLE_PGSQL_SERVER_REPLICATION_LAG_LOG)

Check failure on line 65 in include/PgSQL_Monitor.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

const_cast removing const qualification from the type of a pointer may lead to an undefined behaviour.

See more on https://sonarcloud.io/project/issues?id=sysown_proxysql&issues=AZyQ4zI0kv9arOIsq09l&open=AZyQ4zI0kv9arOIsq09l&pullRequest=5422
},
};

std::vector<table_def_t> tables_defs_monitor_internal {
Expand Down
1 change: 1 addition & 0 deletions include/PgSQL_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ class PgSQL_Threads_Handler
bool monitor_replication_lag_group_by_host;
//! How frequently a replication lag check is performed. Unit: 'ms'.
int monitor_replication_lag_interval;
int monitor_replication_lag_interval_window;
//! Read only check timeout. Unit: 'ms'.
int monitor_replication_lag_timeout;
int monitor_replication_lag_count;
Expand Down
11 changes: 11 additions & 0 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ enum PROXYSQL_MYSQL_ERR {
ER_PROXYSQL_CONNECT_TIMEOUT = 9020,
ER_PROXYSQL_READONLY_TIMEOUT = 9021,
ER_PROXYSQL_FAST_FORWARD_CONN_CREATE = 9022,
ER_PROXYSQL_REPL_LAG_TIMEOUT = 9023,
};

enum proxysql_session_type {
Expand Down Expand Up @@ -1205,6 +1206,11 @@ __thread int pgsql_thread___monitor_read_only_interval;
__thread int pgsql_thread___monitor_read_only_interval_window;
__thread int pgsql_thread___monitor_read_only_timeout;
__thread int pgsql_thread___monitor_read_only_max_timeout_count;
__thread int pgsql_thread___monitor_replication_lag_interval;
__thread int pgsql_thread___monitor_replication_lag_interval_window;
__thread int pgsql_thread___monitor_replication_lag_timeout;
__thread int pgsql_thread___monitor_replication_lag_count;
__thread char* pgsql_thread___monitor_replication_lag_use_percona_heartbeat;
__thread bool pgsql_thread___monitor_writer_is_also_reader;
__thread int pgsql_thread___monitor_threads;
__thread char* pgsql_thread___monitor_username;
Expand Down Expand Up @@ -1527,6 +1533,11 @@ extern __thread int pgsql_thread___monitor_ping_timeout;
extern __thread int pgsql_thread___monitor_read_only_interval;
extern __thread int pgsql_thread___monitor_read_only_interval_window;
extern __thread int pgsql_thread___monitor_read_only_timeout;
extern __thread int pgsql_thread___monitor_replication_lag_interval;
extern __thread int pgsql_thread___monitor_replication_lag_interval_window;
extern __thread int pgsql_thread___monitor_replication_lag_timeout;
extern __thread int pgsql_thread___monitor_replication_lag_count;
extern __thread char* pgsql_thread___monitor_replication_lag_use_percona_heartbeat;
extern __thread int pgsql_thread___monitor_read_only_max_timeout_count;
extern __thread bool pgsql_thread___monitor_writer_is_also_reader;
extern __thread int pgsql_thread___monitor_threads;
Expand Down
6 changes: 3 additions & 3 deletions lib/PgSQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ void PgSQL_HostGroups_Manager::replication_lag_action_inner(PgSQL_HGC *myhgc, co
) {
// always increase the counter
mysrvc->cur_replication_lag_count += 1;
if (mysrvc->cur_replication_lag_count >= (unsigned int)mysql_thread___monitor_replication_lag_count) {
if (mysrvc->cur_replication_lag_count >= (unsigned int)pgsql_thread___monitor_replication_lag_count) {
proxy_warning("Shunning server %s:%d from HG %u with replication lag of %d second, count number: '%d'\n", address, port, myhgc->hid, current_replication_lag, mysrvc->cur_replication_lag_count);
mysrvc->status=MYSQL_SERVER_STATUS_SHUNNED_REPLICATION_LAG;
} else {
Expand All @@ -2678,7 +2678,7 @@ void PgSQL_HostGroups_Manager::replication_lag_action_inner(PgSQL_HGC *myhgc, co
myhgc->hid,
current_replication_lag,
mysrvc->cur_replication_lag_count,
mysql_thread___monitor_replication_lag_count
pgsql_thread___monitor_replication_lag_count
);
}
} else {
Expand Down Expand Up @@ -2716,7 +2716,7 @@ void PgSQL_HostGroups_Manager::replication_lag_action(const std::list<replicatio
const unsigned int port = std::get<PgSQL_REPLICATION_LAG_SERVER_T::PG_RLS_PORT>(server);
const int current_replication_lag = std::get<PgSQL_REPLICATION_LAG_SERVER_T::PG_RLS_CURRENT_REPLICATION_LAG>(server);

if (mysql_thread___monitor_replication_lag_group_by_host == false) {
if (/* pgsql_thread___monitor_replication_lag_group_by_host == */ false) { // feature currently not enabled
// legacy check. 1 check per server per hostgroup
PgSQL_HGC *myhgc = MyHGC_find(hid);
replication_lag_action_inner(myhgc,address.c_str(),port,current_replication_lag);
Expand Down
Loading