The Multi-Layer Configuration System
Overview
ProxySQL is designed for maximal uptime and dynamic reconfiguration. To achieve this, it employs a sophisticated multi-layer configuration system that allows administrators to modify almost every aspect of the proxy at runtime without requiring a restart or dropping active connections.
Why Multi-Layer?
Traditional software often requires a restart to reload a configuration file. This is unacceptable for a high-availability proxy. ProxySQL's system solves this by providing:
- Dynamic Changes: Apply configuration updates instantly to the processing threads.
- Safety: A "staging" area (Memory) to verify SQL-based configuration before making it active.
- Persistence: Ensure that runtime changes survive a reboot.
- Version Control: The ability to revert to a previous persistent state if a runtime change causes issues.
The Four Layers
1. RUNTIME
The Runtime layer represents the internal data structures used by the ProxySQL worker threads. This is the only layer that actively affects the behavior of the proxy. When a thread needs to know a variable value or a routing rule, it looks here.
- Access: Read-only via
statsorruntime_tables. - Modification: Only via
LOAD ... TO RUNTIMEcommands.
2. MEMORY (Main)
The Memory layer (also known as the main database) is an in-memory SQLite database. It serves as the primary interface for administrators. You use standard SQL (INSERT, UPDATE, DELETE) to modify tables in this layer.
- Access: Read/Write via the Admin interface.
- Modification: Standard SQL statements.
- Persistence: NOT persistent. Changes here are lost on restart unless saved to DISK.
3. DISK
The Disk layer is a persistent SQLite database stored on the local file system (typically proxysql.db). On startup, ProxySQL populates the Memory layer from this database.
- Access: Via
diskschema in Admin or direct SQLite client. - Modification: Only via
SAVE ... TO DISKcommands (or direct SQLite editing, though not recommended).
4. CONFIG FILE
The Configuration File (proxysql.cnf) is a static text file. It is primarily used for the initial bootstrap of a fresh ProxySQL installation.
- Access: Standard text editor.
- Modification: Manual editing.
- Role: Overrides DISK only if ProxySQL is started with the
--initialor--reloadflags.
Configuration Workflow
Applying a Change
The typical workflow for modifying ProxySQL configuration is:
- Modify the MEMORY layer using SQL.
- Move changes to RUNTIME to make them active.
- Move changes to DISK to make them persistent.
Startup Flow
When ProxySQL starts, it follows this priority logic to populate the layers:
- DISK to MEMORY: Usually, ProxySQL loads the persistent state from the SQLite file into memory.
- MEMORY to RUNTIME: The loaded state is then pushed to the runtime structures.
- CONFIG FILE (Optional): If started with
--initial, the config file overwrites the disk database.
Moving Configuration Between Layers
Moving data between these layers is handled by specific Admin Commands.
- To activate changes:
LOAD <MODULE> TO RUNTIME - To persist changes:
SAVE <MODULE> TO DISK - To revert changes from disk:
LOAD <MODULE> FROM DISK - To inspect runtime state:
SAVE <MODULE> TO MEMORY(copies internal state back to SQLite for viewing)