ClickHouse System Log Disk Exhaustion
Problem
ClickHouse internal system log tables can fill a replica's disk if generated logs
outpace retention cleanup or obsolete log tables accumulate. This can cause
NOT_ENOUGH_SPACE failures across unrelated application tables. Check the actual
log retention configuration for the target deployment.
Context / Trigger Conditions
- Error message:
Code: 243. DB::Exception: Cannot reserve 1.00 MiB, not enough space. (NOT_ENOUGH_SPACE) - Symptoms: All writes fail simultaneously across multiple tables; reads may still work
- Sentry pattern: Multiple batch insert/commit failure issues appearing at the same time
- Diagnosis query:
SELECT database, formatReadableSize(sum(total_bytes)) FROM system.tables WHERE total_bytes > 0 GROUP BY database ORDER BY sum(total_bytes) DESC - Compare local disk pressure with the sizes of the system log tables before attributing the failure to them.
Solution
Diagnosis
-- Check database sizes
SELECT database, formatReadableSize(sum(total_bytes)) as size
FROM system.tables WHERE total_bytes > 0
GROUP BY database ORDER BY sum(total_bytes) DESC;
-- Find biggest system tables
SELECT name, formatReadableSize(total_bytes) as size
FROM system.tables
WHERE database = 'system' AND total_bytes > 100000000
ORDER BY total_bytes DESC LIMIT 20;
-- Check disk usage
SELECT name, formatReadableSize(free_space) as free, formatReadableSize(total_space) as total
FROM system.disks WHERE name = 'default';
Cleanup on self-hosted ClickHouse
Run the diagnostic queries on the affected replicas. Before removing logs, confirm
the target cluster, replica, table, data retention requirements, and cleanup
authorization with the platform owner.
If DDL fails because the disk is full, work with the platform owner to restore
disk capacity before issuing further DDL.
System log tables often partition by month. Inspect the affected table's active
partitions before choosing any to remove:
SELECT partition, formatReadableSize(sum(bytes_on_disk)) AS size
FROM system.parts
WHERE database = 'system' AND table = 'text_log' AND active
GROUP BY partition ORDER BY partition;
Prefer dropping only the oldest partitions approved for removal. Use SQL against
the affected replica so ClickHouse manages the table metadata and files.
Retention
For operator-managed clusters, check the server's log configuration and compare
it with SHOW CREATE TABLE on the affected replica. Make persistent retention
changes through the owning GitOps repository.
Funnelcake production's retention is configured in
divine-iac-coreconfig/k8s/applications/clickhouse-candidate/base/cluster.yaml.
It sets one day for text_log and trace_log, three days for query_log and
several other logs, and disables processors_profile_log.
Verification
-- After cleanup, verify disk usage
SELECT formatReadableSize(free_space) FROM system.disks WHERE name = 'default';
-- Check whether system log storage decreased
SELECT database, formatReadableSize(sum(total_bytes)) as size
FROM system.tables WHERE total_bytes > 0 GROUP BY database;
Confirm normal application writes have recovered in service metrics or logs.
References
- ClickHouse system tables documentation: https://clickhouse.com/docs/en/operations/system-tables
- ClickHouse TTL documentation: https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/mergetree#table_engine-mergetree-ttl