TheRobotLearns Platform · ProxySQL: from first install to production

RUNTIME, MEMORY, DISK, and LOAD/SAVE Workflow

  • about 15 min read

Learning objectives

  • Distinguish the RUNTIME, MEMORY, DISK, and CONFIG FILE layers by their mutability, persistence, and role in ProxySQL operation.
  • Apply the standard configuration workflow: edit MEMORY, use LOAD ... TO RUNTIME to activate changes, and use SAVE ... TO DISK to persist changes.
  • Use documented LOAD/SAVE forms for reverting from DISK or inspecting RUNTIME state, including LOAD ... FROM DISK and SAVE ... TO MEMORY.
  • Explain why the on-disk database is prioritized at startup over the configuration file unless `--initial` or `--reload` changes that behavior.
  • Predict that changes not loaded to RUNTIME are inactive, changes not saved to DISK are lost after restart, and runtime loads are where invalid settings may be reverted.

Why your MEMORY edit stays inactive

You run an UPDATE on the main table named mysql_servers, but the proxy workers still use the old routing state. The row changed in the MEMORY layer, an in-memory database exposed through the MySQL-compatible Admin interface. ProxySQL's RUNTIME layer holds the internal data structures used by worker threads. It is the only layer that actively affects proxy behavior. A thread looks there when it needs a variable value or routing rule.

RUNTIME cannot be modified directly. It changes only when you run a LOAD ... TO RUNTIME command. The MEMORY layer is a staging area: you modify tables with standard SQL, then load the area into RUNTIME.

MEMORY is not persistent. If you restart before SAVE ... TO DISK, those rows are lost. The DISK layer is a persistent SQLite database, usually proxysql.db, that survives restarts. The CONFIG FILE is proxysql.cnf, a static text file used mainly to bootstrap a fresh install.

To inspect the row you edited, run this query:

SELECT * FROM main.mysql_servers;

The result shows the MEMORY state; it does not show RUNTIME. ProxySQL activates those changes only when you load them to RUNTIME.

Takeaway: Edit main, activate with LOAD ... TO RUNTIME, and remember that workers read RUNTIME, not MEMORY.

How startup chooses DISK or CONFIG

You restart ProxySQL after editing proxysql.cnf, but the running state comes from proxysql.db instead. At startup, ProxySQL gives the disk database priority over the config file. When proxysql.db exists, ProxySQL ignores proxysql.cnf unless you start it with --initial or --reload.

Normally, ProxySQL loads persistent state from the DISK layer into MEMORY, then pushes that state into RUNTIME. The CONFIG FILE is proxysql.cnf, a static text file. It is primarily used for the initial bootstrap of a fresh ProxySQL installation. The config file overrides DISK only when ProxySQL starts with --initial or --reload.

A fresh start with --initial parses the config file, initializes the disk database, then loads the disk state into MEMORY and RUNTIME. Without --initial or --reload, the existing disk database remains the startup source, and the config file is ignored.

Takeaway: Startup uses DISK first when proxysql.db exists; CONFIG overrides DISK only with --initial or --reload.

Move changes: LOAD, SAVE, REVERT

You edited main.mysql_servers, but the proxy still uses the previous RUNTIME values. The activation step is LOAD ... TO RUNTIME; it activates in-memory settings immediately.

The workflow is: modify MEMORY with standard SQL, move changes to RUNTIME with LOAD ... TO RUNTIME, then move changes to DISK with SAVE ... TO DISK. SAVE ... TO DISK persists configuration to SQLite, which makes it survive a restart. Without that save, MEMORY changes are lost after restart.

LOAD ... FROM DISK reverts changes from disk. SAVE ... TO MEMORY copies internal state back to SQLite for viewing. This lets you inspect RUNTIME state through the SQLite-backed copy.

Validation happens during runtime loads, and invalid settings may be silently reverted. For example, a LOAD ... TO RUNTIME command may leave the running state unchanged when the loaded setting is invalid.

Takeaway: Use LOAD ... TO RUNTIME to activate, SAVE ... TO DISK to persist, LOAD ... FROM DISK to revert, and SAVE ... TO MEMORY to inspect RUNTIME state.

Three layer mistakes to predict

You query main.mysql_servers, see the edited row, and then check the running behavior. The running behavior still follows RUNTIME, because ProxySQL activates changes only after you load them to RUNTIME.

You restart ProxySQL after the same edit, and the row is gone. MEMORY is not persistent; any change you did not save to DISK is lost after restart. The next startup loads the disk database into MEMORY, then pushes it into RUNTIME.

When proxysql.db exists, ProxySQL ignores proxysql.cnf unless you start it with --initial or --reload. A change that is only in MEMORY is lost after restart because it was not saved to DISK.

Run LOAD ... TO RUNTIME to activate changes. Run LOAD ... FROM DISK to revert changes from disk. Run SAVE ... TO MEMORY to copy internal state back to SQLite for viewing.

Takeaway: Not loaded to RUNTIME, inactive; not saved to DISK, lost; existing DISK is prioritized over CONFIG unless --initial or --reload are used.

Edit, activate, persist, revert, inspect

-- Edit MEMORY with standard SQL against `main.mysql_servers`.
SELECT * FROM main.mysql_servers;
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
LOAD MYSQL SERVERS FROM DISK;
SAVE MYSQL SERVERS TO MEMORY;

The SELECT reads rows from the main MEMORY table named mysql_servers. The comment names the standard SQL edit step for that table. The LOAD MYSQL SERVERS TO RUNTIME statement follows the LOAD ... TO RUNTIME activation form. The SAVE MYSQL SERVERS TO DISK statement follows the SAVE ... TO DISK persistence form. The LOAD MYSQL SERVERS FROM DISK statement follows the LOAD ... FROM DISK revert-from-DISK form. The SAVE MYSQL SERVERS TO MEMORY statement follows the SAVE ... TO MEMORY viewing form, which copies internal state back to SQLite for viewing.

Sources

Do more with an account

RUNTIME, MEMORY, DISK, and LOAD/SAVE Workflow — ProxySQL: from first install to production