TheRobotLearns Platform · ProxySQL: from first install to production
Admin Commands, Operation Modes, and Runtime Propagation
Learning objectives
- Use Admin commands to reload config, flush logs/caches, and reopen configdb.
- Choose STOP/START/RESTART to control mode, expecting non-smooth client transitions.
- Differentiate PROXYSQL SHUTDOWN and KILL from STOP/START/RESTART mode commands.
- Propagate in-memory config to runtime with LOAD FROM MEMORY and verify runtime_* tables.
- Predict rule-hit counters reset after loading PostgreSQL rules to runtime.
- Separate ordinary Admin commands from debug-build and Jemalloc-specific commands.
Flush logs, caches, and configdb
You deployed a new configdb file and want ProxySQL to reopen it. PROXYSQL FLUSH CONFIGDB reopens the configdb file. A new configdb file must be valid, because supplying an invalid configdb file causes undefined behavior.
The Admin interface uses MySQL or PostgreSQL protocol for SQL commands. ProxySQL parses those queries for ProxySQL-specific commands. When appropriate, ProxySQL sends the query to its embedded SQLite3 engine. SQLite3 syntax differs from MySQL and PostgreSQL, so not all commands work; USE is accepted but does not change the default schema.
Run PROXYSQL FLUSH CONFIGDB to reopen the configdb file. Run PROXYSQL FLUSH QUERY CACHE to clear the current query cache. Run PROXYSQL FLUSH LOGS to perform a log rotation. Run PROXYSQL FLUSH MYSQL CLIENT HOSTS to clear the Client Error Limit host cache.
Default access uses admin with admin credentials for read-write access to all tables. The stats user with stats credentials has read-only access to statistics tables. The default admin user can connect only locally. Credentials are configurable through admin-admin_credentials and admin-stats_credentials.
Takeaway: Run PROXYSQL FLUSH CONFIGDB, PROXYSQL FLUSH QUERY CACHE, PROXYSQL FLUSH LOGS, or PROXYSQL FLUSH MYSQL CLIENT HOSTS for the matching config or cache action.
STOP changes mode without killing
You need ProxySQL to keep only the Admin module running, without exiting the process. PROXYSQL STOP relaunches the main process and changes the operating mode to only the Admin module. PROXYSQL START changes the operating mode to all modules running. PROXYSQL RESTART relaunches the main process and returns to the same status.
These three commands cover two module modes. Mode A has all modules running. Mode B has only the Admin module running.
PROXYSQL STOP moves the instance from A to B. PROXYSQL START moves it back to A. PROXYSQL RESTART leaves the status unchanged, which is useful for major configuration changes that would otherwise require a process restart.
Clients do not see a smooth change between these two modes. When PROXYSQL STOP is received, client connections are terminated immediately. PROXYSQL STOP, PROXYSQL START, and PROXYSQL RESTART are less disruptive than PROXYSQL KILL or PROXYSQL SHUTDOWN, because PROXYSQL STOP brings down all ProxySQL except the Admin module.
Use PROXYSQL PAUSE and PROXYSQL RESUME when you need to stop ProxySQL without disrupting traffic. PROXYSQL PAUSE immediately shuts down the listeners, so no new connections are allowed. It sets mysql-wait_timeout to 0; idle connections not in a transaction close immediately.
Active transactions continue until commit, rollback, or mysql-max_transaction_time is reached. PROXYSQL RESUME resumes the previous mysql-wait_timeout value and starts the listeners.
Takeaway: PROXYSQL STOP and PROXYSQL START switch between only Admin and all modules, but PROXYSQL STOP ends client connections.
SHUTDOWN versus KILL and STOP
ProxySQL lists PROXYSQL STOP, PROXYSQL START, and PROXYSQL RESTART as commands dedicated to changing ProxySQL operating mode, and lists PROXYSQL SHUTDOWN and PROXYSQL KILL as commands for shutdown.
PROXYSQL STOP relaunches the main process and changes the status to only the Admin module. PROXYSQL START changes the operating mode to all modules running. PROXYSQL RESTART relaunches the main process and returns to the same status; it is useful for major configuration changes that otherwise would require a process restart.
PROXYSQL SHUTDOWN exits the process gracefully. Since version 2.1, this command behaves like PROXYSQL KILL. The motivation for this change was to simplify the exit process and avoid potential errors that could lead to a non-clean exit. PROXYSQL KILL exits the process immediately with exit code 0. Non-zero exit codes could lead to undesired process restarts when ProxySQL is started as a service.
PROXYSQL SHUTDOWN SLOW is only for testing purposes. It performs a graceful shutdown: all modules are shut down, then the process exits. This command was introduced in v2.1 as a rename for PROXYSQL SHUTDOWN.
Takeaway: PROXYSQL SHUTDOWN and PROXYSQL KILL are the shutdown commands, while PROXYSQL STOP, PROXYSQL START, and PROXYSQL RESTART change the operating mode.
Load MEMORY into runtime
You update main.mysql_users. ProxySQL uses in-memory data structures at runtime to store user information. LOAD MYSQL USERS FROM MEMORY propagates the contents of main.mysql_users into those data structures. Similar commands propagate configuration into the different layers.
main is the in-memory configuration database. It also holds several runtime_* tables. Those tables are populated with the current runtime configuration ProxySQL is using.
disk is a disk-based mirror of main, without the runtime_* tables. Across restarts, main is not persisted. It is loaded either from disk or from the config file, based on startup flags and whether an on-disk database exists.
The stats schema contains runtime metrics collected from the proxy. Its metrics include the number of times each query rule was matched and the currently running queries.
The flush, mode, and shutdown command groups are listed as Admin CLI commands. PROXYSQL MEMPROFILE START activates the Jemalloc memory profiler, and PROXYSQL MEMPROFILE STOP disables it, when ProxySQL is compiled with Jemalloc support.
In DEBUG builds, PROXYSQL GCOV DUMP dumps the current content of gcda and gcno profile files. PROXYSQL GCOV RESET resets code coverage profiles. Debug-only schemas, myhgm and monitor_internal, are enabled only in debug builds.
Takeaway: Use LOAD MYSQL USERS FROM MEMORY to move main configuration into runtime; runtime_* tables and stats show current runtime state.
Reload users and switch modes
SHOW DATABASES;
LOAD MYSQL USERS FROM MEMORY;
PROXYSQL STOP;
PROXYSQL START;
PROXYSQL FLUSH LOGS;This admin-interface SQL lists schemas, propagates user configuration, switches modes, and rotates logs. SHOW DATABASES returns five schemas: main, disk, stats, monitor, and stats_history. LOAD MYSQL USERS FROM MEMORY propagates main.mysql_users into the in-memory data structures ProxySQL uses at runtime for user information. PROXYSQL STOP relaunches the main process and changes the operating mode to only the Admin module. When PROXYSQL STOP is received, client connections are terminated immediately. PROXYSQL START changes the operating mode to all modules running. PROXYSQL FLUSH LOGS performs a log rotation.
Try it: config_layer_sim
Connect to the ProxySQL Admin interface. Run SHOW DATABASES to list the schemas. Update main.mysql_users, then run LOAD MYSQL USERS FROM MEMORY. Run PROXYSQL STOP; client connections are terminated immediately. Run PROXYSQL START. Run PROXYSQL FLUSH LOGS to rotate logs.
Sources
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.