TheRobotLearns Platform · ProxySQL: from first install to production
Current Sessions, Query Digests, and Workload Statistics
Learning objectives
- Check current PostgreSQL sessions using stats_pgsql_processlist and SHOW PGSQL PROCESSLIST/ACTIVITY.
- Interpret stats_pgsql_query_digest fields to explain frequency, timing, row counts, and recency.
- Use stats_pgsql_query_digest_reset to fetch aggregates and zero their counters after SELECT.
- Review per-user PostgreSQL frontend connections and limits via stats_pgsql_users.
- Use stats_pgsql_query_events to inspect bounded in-memory successful/failed PostgreSQL SQLSTATE details.
- Locate command counters and query-rule hits to separate patterns from command types.
Find live metrics fast
You run SHOW DATABASES in the Admin interface and see stats. That schema contains runtime metrics collected from the internal functioning of the proxy. The metrics listed there include the number of times each query rule was matched and the currently running queries.
main is the in-memory configuration database. disk is the disk-based mirror of main, without the runtime_* information tables. monitor contains monitoring metrics related to the backend servers, such as minimum and maximum time for connecting or pinging. stats_history contains historical metrics used for longer running requirements, and its SHOW DATABASES entry shows /var/lib/proxysql/proxysql_stats.db.
This is the command you can use to list the schemas:
SHOW DATABASES;A small gotcha is that the embedded engine is SQLite3, so SQL syntax differs from MySQL or PostgreSQL. For example, the Admin interface accepts USE, but it does not change the default schema.
Takeaway: Start with stats for current proxy metrics such as running queries and query-rule matches.
Who can read stats
The Admin interface offers two admin user types, and one of them is read-only for statistics. The admin user has read-write access to all the tables. The stats user has read-only access to statistics tables, used for metrics pulling without exposing too much of the database.
The default credentials are admin with password admin, and stats with password stats. You can configure those credentials through admin-admin_credentials and admin-stats_credentials. For security reasons, the default admin user can only connect locally, regardless of its password.
The stats schema contains runtime metrics collected from the internal functioning of the proxy. The stats_history schema contains historical metrics used for longer running requirements, such as the Web UI and Firewall. The admin user can change all tables, and the stats user can only read statistics tables.
main remains the in-memory configuration database, and disk mirrors it without the runtime tables. monitor holds backend-server metrics, including the minimal and maximal time for connecting to a backend server or pinging it.
Takeaway: Use the read-only stats user for metrics tables, and reserve admin for full table access.
Separate current from history
stats and stats_history sit next to each other in the schema list, but their purposes differ. The stats schema contains runtime metrics collected from the internal functioning of the proxy. The stats_history schema contains historical metrics used for longer running requirements.
For the two metrics named in stats, the rule-match count and the currently running queries, stats is the live place to look. The historical schema is instead for longer running requirements, and Web UI and Firewall are named users of it. monitor is also different: it contains monitoring metrics related to the backend servers, such as the minimum and maximum time for connecting or pinging.
Think of stats as the counter panel in front of the proxy, and stats_history as the archive for longer requirements.
After a restart, main is not persisted; ProxySQL loads it from disk or from the config file, based on startup flags and the existence of an on-disk database.
Takeaway: Use stats for current rule matches and running queries, and stats_history for historical metrics.
Admin protocol SQLite caveat
You send queries to the Admin interface over the MySQL or PostgreSQL protocol, and ProxySQL parses them for commands specific to ProxySQL. If appropriate, ProxySQL sends those queries to the embedded SQLite3 engine to run them.
SQL syntax used by SQLite3 differs from MySQL or PostgreSQL, so not all commands work on SQLite3. The Admin interface accepts USE, but it does not change the default schema because that feature is not available in SQLite3. ProxySQL converts SHOW DATABASES into the equivalent SQLite3 command, so the schema list still appears.
The Admin interface uses two admin user types. The admin user has read-write access to all tables. The stats user has read-only access to statistics tables. The default admin user can only connect locally, regardless of its password.
After a restart, main is not persisted. ProxySQL loads it from disk or from the config file, based on startup flags and the existence of an on-disk database.
Takeaway: Expect SQLite3 behavior in the Admin interface, even when you connect over MySQL or PostgreSQL protocol.
List the Admin schemas
SHOW DATABASES;SHOW DATABASES lists main, disk, stats, monitor, and stats_history. The stats schema contains runtime metrics, including query-rule match counts and currently running queries. ProxySQL converts this command into the equivalent SQLite3 command for the Admin interface.
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.