Memory Leak Detection
Overview
ProxySQL includes jemalloc, a memory allocator compiled with profiling capabilities. Since version 1.4.0, memory profiling is enabled by default, but deactivated, allowing the activation at runtime.
Activating the Memory Profiler
To enable memory profiling at runtime, connect to ProxySQL's Admin interface and execute:
PROXYSQL MEMPROFILE START
This initiates the generation of profile dumps named proxysql.<pid>.<seq>.i<iseq>.heap in:
- The current working directory (if ProxySQL runs in foreground with
-for--foregroundflag) - The datadir (default:
/var/lib/proxysql) when running as a background process or via init script
To stop profiling, ProxySQL must be restarted.
Reporting Memory Leaks
Follow these steps when reporting suspected leaks:
- Start ProxySQL with profiling enabled
- Collect sufficient memory dumps to demonstrate a representative amount of memory consumption
- Create a tarball containing the generated dumps
- Submit an issue on the ProxySQL GitHub repository using the issue template
Legacy Configuration (Pre-v1.4.0)
Using Init Script
Add this environment variable before process startup in /etc/init.d/proxysql:
export MALLOC_CONF="xmalloc:true,lg_tcache_max:16,purge:decay,prof:true,prof_leak:true,lg_prof_sample:18,lg_prof_interval:30"
Without Init Script
Set the environment variable when launching ProxySQL:
MALLOC_CONF="xmalloc:true,lg_tcache_max:16,purge:decay,prof:true,prof_leak:true,lg_prof_sample:18,lg_prof_interval:30" \
proxysql -f -c /etc/proxysql.cnf
Retained Memory vs. Leaks
High virtual memory with low resident memory typically indicates jemalloc's normal retention
behavior, not a leak. This appears in stats_memory_metrics when jemalloc_retained exceeds
jemalloc_resident.
To disable retention, start ProxySQL with:
MALLOC_CONF="retain:false"
This setting cannot be changed at runtime.