TheRobotLearns Platform · ProxySQL: from first install to production

Administering Cluster Nodes and Synchronization Behavior

  • about 25 min read

Learning objectives

  • Add a node to `proxysql_servers` and activate it with `LOAD PROXYSQL SERVERS TO RUNTIME`.
  • Apply admin commands to activate, persist, revert, inspect, and reset ProxySQL server lists.
  • Configure inter-node credentials and verify every cluster member accepts them.
  • Tune ProxySQL cluster sync thresholds for checksum checks and module diffs_before_sync.
  • Choose automatic persistence behavior and the MySQL server synchronization algorithm.

Make a node visible

You insert 10.0.0.5:6032 into proxysql_servers on one running node, yet the other ProxySQL instances do not know it as a cluster member. The row sits in the main database, and the active cluster module still uses the prior node list. ProxySQL Cluster keeps its node list in proxysql_servers, which defines the Core nodes of the cluster. Unlike other modules, managing these nodes needs specific commands to move the configuration from main into the active cluster module.

This adds a node and activates it on the edited node:

INSERT INTO proxysql_servers (hostname, port) VALUES ('10.0.0.5', 6032);
LOAD PROXYSQL SERVERS TO RUNTIME;

The INSERT uses hostname and port values for the node. LOAD PROXYSQL SERVERS TO RUNTIME is the Activate Nodes action. To let other ProxySQL instances know there is a new node, add that node to proxysql_servers on at least one existing node and issue the load command. The cluster will automatically detect the change and propagate the node list when admin-cluster_proxysql_servers_diffs_before_sync is met.

Takeaway: proxysql_servers defines Core nodes, and LOAD PROXYSQL SERVERS TO RUNTIME activates the inserted row.

Commands for the node list

You change proxysql_servers and need commands that activate, persist, revert, inspect, and reset the node list. ProxySQL gives separate actions for Activate Nodes, Persist Nodes, Revert from Disk, Inspect Runtime, and Reset from Config.

main is the editable place for proxysql_servers rows. LOAD PROXYSQL SERVERS TO RUNTIME activates those rows in the active cluster module. SAVE PROXYSQL SERVERS TO DISK persists the node list to the disk database. LOAD PROXYSQL SERVERS FROM DISK loads from the disk database. For Inspect Runtime, use SAVE PROXYSQL SERVERS TO MEMORY. For Reset from Config, use LOAD PROXYSQL SERVERS FROM CONFIG. The load step is needed because the cluster module does not read the main edit by itself.

This command set covers the five node-list actions:

LOAD PROXYSQL SERVERS TO RUNTIME;
SAVE PROXYSQL SERVERS TO DISK;
LOAD PROXYSQL SERVERS FROM DISK;
SAVE PROXYSQL SERVERS TO MEMORY;
LOAD PROXYSQL SERVERS FROM CONFIG;

For adding a node, the order starts with INSERT, then LOAD PROXYSQL SERVERS TO RUNTIME, then SAVE PROXYSQL SERVERS TO DISK. The load step makes the row visible to the cluster; the save step writes it to disk.

Takeaway: LOAD ... TO RUNTIME activates proxysql_servers, and SAVE ... TO DISK persists it.

Credentials nodes use

ProxySQL Cluster needs every node to connect to each other to perform health checks and pull configuration updates. The current node uses admin-cluster_username and admin-cluster_password to authenticate against other ProxySQL nodes. Both variables default to empty. The same credentials must be present in the admin-admin_credentials list of every node in the cluster. The cluster uses these credentials for those inter-node connections.

Start a new node only when it has the correct inter-node credentials. If one member is missing them, the credential requirement is not met. After that, add the node row to proxysql_servers on an active Core node and run LOAD PROXYSQL SERVERS TO RUNTIME.

These variables are Admin module settings, so LOAD ADMIN VARIABLES TO RUNTIME activates them and SAVE ADMIN VARIABLES TO DISK persists them. Check stats_proxysql_servers_checksums when verifying that peers see a new node.

This applies Admin variable changes and checks peer visibility:

LOAD ADMIN VARIABLES TO RUNTIME;
SAVE ADMIN VARIABLES TO DISK;
SELECT * FROM stats_proxysql_servers_checksums;

The SELECT queries the checksum table.

Takeaway: Set admin-cluster_username and admin-cluster_password, put the same credentials in admin-admin_credentials on every node, then check stats_proxysql_servers_checksums.

Tune sync checks and saves

You set admin-cluster_proxysql_servers_diffs_before_sync and admin-cluster_mysql_servers_diffs_before_sync, but the running cluster still uses the previous thresholds. Those variables are Admin module settings, so LOAD ADMIN VARIABLES TO RUNTIME activates them and SAVE ADMIN VARIABLES TO DISK persists them.

The synchronization threshold variables define a grace period before a local node synchronizes a module from a peer. admin-cluster_mysql_servers_diffs_before_sync and admin-cluster_proxysql_servers_diffs_before_sync default to 3. A nonzero threshold counts consecutive checksum mismatches before ProxySQL pulls the module from a peer. Disabling a checksum gate also forces that module's runtime diff threshold to 0.

Two interval variables control checksum comparisons. admin-cluster_check_interval_ms defaults to 1000 milliseconds and defines how often the cluster module compares checksums with peers. admin-cluster_check_status_frequency defaults to 10 and defines how many checksum checks must happen before a detailed SHOW MYSQL STATUS check is performed on peers.

For persistence, admin-cluster__save_to_disk defaults to true. When enabled, ProxySQL automatically runs the relevant SAVE ... TO DISK action after successfully fetching and loading configuration from a peer. For MySQL server synchronization, admin-cluster_mysql_servers_sync_algorithm defaults to 1 and synchronizes both runtime server state and mysql_servers_v2. Value 2 synchronizes only mysql_servers_v2. Value 3 selects 2 when ProxySQL starts with -M, otherwise 1. Changing the algorithm resets cluster checksums so the selected source is evaluated immediately.

Takeaway: Load Admin variables after changing cluster sync settings, and know that admin-cluster_mysql_servers_sync_algorithm values 1, 2, and 3 choose different MySQL sync behavior.

Add, activate, persist, and verify a node

INSERT INTO proxysql_servers (hostname, port) VALUES ('10.0.0.5', 6032);
LOAD PROXYSQL SERVERS TO RUNTIME;
SAVE PROXYSQL SERVERS TO DISK;
LOAD ADMIN VARIABLES TO RUNTIME;
SAVE ADMIN VARIABLES TO DISK;
SELECT * FROM stats_proxysql_servers_checksums;

INSERT INTO proxysql_servers adds the new node's hostname and port values to the Core node list in main. LOAD PROXYSQL SERVERS TO RUNTIME activates the row in the active cluster module. SAVE PROXYSQL SERVERS TO DISK writes the node list to the disk database. LOAD ADMIN VARIABLES TO RUNTIME activates changes made to Admin module variables. SAVE ADMIN VARIABLES TO DISK writes Admin variable settings to disk. SELECT * FROM stats_proxysql_servers_checksums queries the table used for checking whether peers see the node.

Try it: config_layer_sim

You run this exercise against ProxySQL Admin on one active Core node. Add 10.0.0.6:6032 to proxysql_servers, activate the list with LOAD PROXYSQL SERVERS TO RUNTIME, and persist it with SAVE PROXYSQL SERVERS TO DISK. Query stats_proxysql_servers_checksums to check whether peers see the node. If you changed Admin cluster variables, run LOAD ADMIN VARIABLES TO RUNTIME and SAVE ADMIN VARIABLES TO DISK.

Sources

Do more with an account

Administering Cluster Nodes and Synchronization Behavior — ProxySQL: from first install to production