Cara Cek DB yang banyak mengkonsumsi disk
π Query utama (per database)
SELECT
table_schema AS database_name,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS size_mb
FROM information_schema.tables
GROUP BY table_schema
ORDER BY size_mb DESC;
Output:
-
database_nameβ nama DB -
size_mbβ total size (data + index)
π Lebih detail (per table dalam DB tertentu)
Kalau mau drill-down:
SELECT
table_name,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS size_mb
FROM information_schema.tables
WHERE table_schema = 'nama_database'
ORDER BY size_mb DESC;
π Ini penting untuk identifikasi:
-
tabel paling βrakusβ
-
kandidat cleanup / archiving
β οΈ Realita di Azure MySQL (important)
Kalau kamu pakai Microsoft Azure β disk usage yang dihitung di alert bukan cuma data MySQL, tapi termasuk:
-
binary log (binlog)
-
undo log
-
temp tables
-
system overhead
Jadi sering kejadian:
DB size cuma 60β70% tapi disk sudah 90% π
π₯ Quick check tambahan (binlog)
Cek apakah binlog jadi biang masalah:
SHOW BINARY LOGS;
Kalau size besar:
-
cek retention:
SHOW VARIABLES LIKE 'expire_logs_days';
SHOW VARIABLES LIKE 'binlog_expire_logs_seconds';
π Next action (practical, no BS)
Kalau disk tinggal 10%, jangan cuma analisaβlangsung mitigate:
1. Fast relief
-
purge binlog (kalau aman):
PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY;
2. Medium fix
-
cleanup data lama (log table, audit, session, dll)
-
archive ke storage lain (Blob / S3 equivalent)
3. Long-term
-
aktifkan auto-rotation binlog
-
setup monitoring:
-
Azure Metrics (storage percent)
-
alert threshold 70% (bukan 90%)
-
No Comments