SHOW FULL PROCESSLIST;
- Look for queries with high
Time
values (e.g.,>5s
). - Identify queries stuck in "Sending data", "Copying to tmp table", or "Waiting for table lock".
SELECT * FROM information_schema.PROCESSLIST WHERE TIME > 5;
- Shows queries running for longer than 5 seconds.
SELECT table_name, data_length, index_length, data_free
FROM information_schema.tables
WHERE table_schema = 'your_database_name';
- If
data_free
is large, the table may be fragmented.
OPTIMIZE TABLE tbl_entries, tbl_entries_data_411, tbl_entries_data_409, tbl_entries_data_412;
- Reclaims unused space & defragments indexes.
- Run periodically if tables experience frequent updates/deletes.
ANALYZE TABLE tbl_entries, tbl_entries_data_411, tbl_entries_data_409, tbl_entries_data_412;
- Ensures MariaDB selects the best index for queries.
📌 Run weekly via cron job
crontab -e
Add:
0 0 * * 0 mysql -u root -p'password' -e "OPTIMIZE TABLE tbl_entries, tbl_entries_data_411, tbl_entries_data_409, tbl_entries_data_412;"
- Runs every Sunday at midnight.
- Only enable if tables change frequently.
SELECT query, total_latency, exec_count
FROM sys.statement_analysis
ORDER BY total_latency DESC
LIMIT 5;
- Shows queries consuming the most resources.
SHOW ENGINE INNODB STATUS;
- Look for "Waiting for table lock" or "Pending writes".
KILL <ID>;
- Get the query
ID
fromSHOW FULL PROCESSLIST;
and terminate it.
✅ Run SHOW FULL PROCESSLIST;
to monitor live queries.
✅ Use OPTIMIZE TABLE
if performance degrades.
✅ Don't overuse OPTIMIZE TABLE
—only when necessary.
✅ Consider Redis caching for frequently run queries.
✅ Monitor data_free
to check if indexes need rebuilding.
- Queries slow? →
SHOW FULL PROCESSLIST;
- Index fragmentation? →
SELECT table_name, data_free FROM information_schema.tables;
- Fix fragmentation? →
OPTIMIZE TABLE tbl_name;
- MariaDB picking wrong indexes? →
ANALYZE TABLE tbl_name;
- Recurring optimization? → Use a cron job if needed.