Use SHOW STATUS, SHOW VARIABLES, and PERFORMANCE_SCHEMA queries to inspect MariaDB memory consumption per buffer, thread, and engine.
MariaDB keeps data in caches, buffers, and per-connection areas. Exceeding RAM limits causes swapping and slow queries. Regular checks help tune buffers and spot leaks.
Start the server with performance_schema=ON
and performance-schema-instrument='memory/%=ON'
. These flags activate the memory_%
summary tables.
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool%';
shows total buffer-pool memory. SHOW VARIABLES LIKE 'max_connections';
helps estimate per-thread memory.
memory_summary_global_by_event_name
lists every internal allocator, its current byte count, and the high-water mark. Sorting by CURRENT_NUMBER_OF_BYTES_USED
highlights large consumers.
innodb_buffer_pool_size
, query_cache_size
, tmp_table_size
, and max_connections
are the main tunables. Align totals with available RAM minus OS overhead.
The query below lists the five allocations that currently occupy the most RAM.
SELECT EVENT_NAME,
CURRENT_NUMBER_OF_BYTES_USED/1024/1024 AS mb_used,
HIGH_NUMBER_OF_BYTES_USED/1024/1024 AS mb_high
FROM performance_schema.memory_summary_global_by_event_name
ORDER BY CURRENT_NUMBER_OF_BYTES_USED DESC
LIMIT 5;
Multiply max_connections
by estimated per-thread buffers (≈4–6 MB) and add global caches such as innodb_buffer_pool_size
. Keep the sum below 80 % of total RAM.
1) Enable performance_schema
in staging first. 2) Graph key metrics—buffer pool, temp tables, and sort buffers—in Prometheus or Grafana. 3) Review after major workload or schema changes.
Mistake 1 – Ignoring per-connection buffers. Even with a small buffer pool, hundreds of connections can exhaust RAM. Lower max_connections
or use pooling.
Mistake 2 – Sampling only at startup. Memory grows with traffic. Schedule queries every minute and alert on spikes.
MariaDB docs: Performance Schema Memory, Server Status Variables.
Overhead is usually below 5 %. Limit enabled instruments to memory/%
to keep impact minimal.
Not directly. Memory instrumentation is per allocator. Combine with processlist or query logs to map heavy users.
Collect every 60 seconds in production. Lower-traffic systems can sample every 5 minutes.