TheRobotLearns Platform · ProxySQL: from first install to production
PostgreSQL Admin Path, Backends, and Monitoring
Learning objectives
- Connect to ProxySQL admin on PostgreSQL-compatible port 6132.
- Apply pgsql_* workflow by editing in memory, loading runtime, and saving disk persistence.
- Add pgsql_servers rows with hostgroup_id, hostname, and port, then load and save.
- Create a dedicated PostgreSQL account and configure pgsql-monitor_username, pgsql-monitor_password, and intervals.
- List active pgsql_* definitions in runtime tables after the matching LOAD command.
Connect through port 6132
You start a PostgreSQL configuration session by opening psql to ProxySQL itself. ProxySQL supports the PostgreSQL protocol, so you can use its connection pooling, query routing, and monitoring features through this Admin interface. ProxySQL exposes a PostgreSQL-compatible Admin interface on port 6132. All pgsql_ configuration commands run from that interface.
Before you configure backends, ProxySQL must already be installed and running. A PostgreSQL client must also be installed on your system. The PostgreSQL servers must be accessible from the ProxySQL server.
Backend servers use 5432 in the example, while ProxySQL listens for client PostgreSQL traffic on default port 6133. The 6132 port is only the Admin interface.
This command opens the Admin shell where you will run the pgsql_ commands:
psql -h 127.0.0.1 -p6132 -U admin -d adminIf you use 6133 here, you connect to ProxySQL as a PostgreSQL client, not to the Admin interface.
Takeaway: Connect to ProxySQL Admin for PostgreSQL on port 6132; reserve port 6133 for client traffic through ProxySQL.
Move pgsql_* changes live
You add a row to pgsql_servers, but ProxySQL keeps routing queries the old way. The row is in the in-memory table, not yet in the runtime configuration the running proxy uses.
ProxySQL uses a multi-layer configuration system. For PostgreSQL, its dedicated tables and variables begin with pgsql_, such as pgsql_servers, pgsql_users, and pgsql_query_rules. The admin commands for these objects are LOAD PGSQL ... TO RUNTIME and SAVE PGSQL ... TO DISK.
You make changes in the in-memory configuration tables. LOAD PGSQL ... TO RUNTIME applies those changes to the running proxy. SAVE PGSQL ... TO DISK persists changes across restarts.
After a matching LOAD command, the active forms appear in runtime tables, such as runtime_pgsql_servers. Changes to PostgreSQL tables must be loaded to runtime before they take effect.
These commands apply a server edit to the running proxy and persist it across restarts:
LOAD PGSQL SERVERS TO RUNTIME;
SAVE PGSQL SERVERS TO DISK;Regularly back up your ProxySQL configuration with SAVE PGSQL ... TO DISK.
Takeaway: Edit the in-memory pgsql_ table, run the matching LOAD PGSQL ... TO RUNTIME, then run SAVE PGSQL ... TO DISK if the change must survive restarts.
Add PostgreSQL backend rows
You want ProxySQL to route PostgreSQL traffic to your backend instances. You add each instance to the pgsql_servers table, specifying a hostgroup_id, a hostname, and a port.
The example uses three PostgreSQL servers, 10.0.0.1, 10.0.0.2, and 10.0.0.3, all running on default PostgreSQL port 5432. They are placed in hostgroup 1. A hostgroup is a routing destination. The hostgroup_id is that destination number.
This inserts three rows, and the SELECT returns them before you load or save:
INSERT INTO pgsql_servers (hostgroup_id, hostname, port) VALUES (1, '10.0.0.1', 5432);
INSERT INTO pgsql_servers (hostgroup_id, hostname, port) VALUES (1, '10.0.0.2', 5432);
INSERT INTO pgsql_servers (hostgroup_id, hostname, port) VALUES (1, '10.0.0.3', 5432);
SELECT * FROM pgsql_servers;These commands apply the edit and persist it:
LOAD PGSQL SERVERS TO RUNTIME;
SAVE PGSQL SERVERS TO DISK;The active server definitions appear in runtime_pgsql_servers after the matching LOAD command. If you skip LOAD PGSQL SERVERS TO RUNTIME, ProxySQL does not use the new backend.
Takeaway: Add backends by inserting hostgroup_id, hostname, and port into pgsql_servers, then load servers to runtime and save them to disk.
Give monitoring its own account
You add backend rows to pgsql_servers, and monitoring needs a dedicated PostgreSQL account and configured intervals before ProxySQL can track backend health. Set the credentials and reporting intervals in ProxySQL variables.
First, create a dedicated monitoring user in your primary PostgreSQL server. The example uses the name and password monitor, and grants CONNECT on the postgres database.
This creates the account and grants permission to connect:
CREATE USER monitor WITH PASSWORD 'monitor';
GRANT CONNECT ON DATABASE postgres TO monitor;Then set pgsql-monitor_username and pgsql-monitor_password in global_variables. Set pgsql-monitor_connect_interval and pgsql-monitor_ping_interval to 2000.
This updates the variables, then applies and persists them:
UPDATE global_variables SET variable_value = 'monitor' WHERE variable_name = 'pgsql-monitor_username';
UPDATE global_variables SET variable_value = 'monitor' WHERE variable_name = 'pgsql-monitor_password';
UPDATE global_variables SET variable_value = '2000' WHERE variable_name IN ('pgsql-monitor_connect_interval','pgsql-monitor_ping_interval');
LOAD PGSQL VARIABLES TO RUNTIME;
SAVE PGSQL VARIABLES TO DISK;After loading, ProxySQL can monitor backend health through the monitor schema. Check monitor.pgsql_server_connect_log and monitor.pgsql_server_ping_log. Use time_start_us DESC LIMIT 3 to see three recent rows.
Use a dedicated monitoring user, not an application user.
Takeaway: Create a dedicated PostgreSQL monitor user, set pgsql-monitor_username, pgsql-monitor_password, and the connect and ping intervals, then run LOAD PGSQL VARIABLES TO RUNTIME.
Add a PostgreSQL backend and confirm its runtime row
-- Run this in psql connected to ProxySQL Admin on port 6132.
INSERT INTO pgsql_servers (hostgroup_id, hostname, port) VALUES (1, '10.0.0.1', 5432);
SELECT * FROM pgsql_servers;
LOAD PGSQL SERVERS TO RUNTIME;
SELECT * FROM runtime_pgsql_servers;
SAVE PGSQL SERVERS TO DISK;The first command inserts a PostgreSQL backend into the in-memory pgsql_servers table with hostgroup_id 1, hostname 10.0.0.1, and port 5432. The next SELECT reads that in-memory table. LOAD PGSQL SERVERS TO RUNTIME applies the change to the running proxy. SELECT * FROM runtime_pgsql_servers returns the active form exposed in the matching runtime table. SAVE PGSQL SERVERS TO DISK persists the change across restarts.
Try it: config_layer_sim
Connect to ProxySQL Admin on port 6132 with psql -h 127.0.0.1 -p6132 -U admin -d admin. Insert 10.0.0.1 into pgsql_servers with hostgroup_id 1 and port 5432. Run SELECT * FROM pgsql_servers;; it returns the row you inserted. Run LOAD PGSQL SERVERS TO RUNTIME; to apply the change to the running proxy. Run SELECT * FROM runtime_pgsql_servers;; it returns the active form after the matching LOAD command. Run SAVE PGSQL SERVERS TO DISK; to persist it across restarts. Update pgsql-monitor_username and pgsql-monitor_password in global_variables to monitor. Update pgsql-monitor_connect_interval and pgsql-monitor_ping_interval in global_variables to 2000. Run LOAD PGSQL VARIABLES TO RUNTIME; and SAVE PGSQL VARIABLES TO DISK;. Check monitor.pgsql_server_connect_log ordered by time_start_us DESC LIMIT 3; it shows recent connect rows.
Sources
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- PostgreSQL Tables
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- PostgreSQL Tables
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
- How to Configure ProxySQL for PostgreSQL for the First Time
Do more with an account
- Graded quizzes is available on your account.
- Saving your progress is available on your account.
- Hands-on labs is available on your account.
- AI tutoring is available on your account.