ClickHouse inactive parts accumulating in observations table — 112 GiB buildup in production despite non-business hours #15024
Replies: 4 comments
Problem 1: Inactive Parts AccumulationThe 112 GiB of inactive parts you're seeing in Cleanup options:
Prevention:
Problem 2: System Log Tables Consuming 100+ GiBThis is a common issue. ClickHouse system log tables ( Option 1 — Disable unused system log tables (recommended): Mount a config file into <clickhouse>
<trace_log remove="1"/>
<text_log remove="1"/>
<opentelemetry_span_log remove="1"/>
<asynchronous_metric_log remove="1"/>
<metric_log remove="1"/>
<latency_log remove="1"/>
</clickhouse>Keep Option 2 — Apply aggressive TTLs: If you want to keep the tables for debugging, attach short TTLs and disable the query profiler: <clickhouse>
<profiles>
<default>
<query_profiler_real_time_period_ns>0</query_profiler_real_time_period_ns>
<query_profiler_cpu_time_period_ns>0</query_profiler_cpu_time_period_ns>
</default>
</profiles>
<trace_log>
<engine>ENGINE = MergeTree PARTITION BY toYYYYMM(event_date) ORDER BY (event_date, event_time) TTL event_date + INTERVAL 7 DAY</engine>
</trace_log>
<opentelemetry_span_log>
<engine>ENGINE = MergeTree PARTITION BY toYYYYMM(finish_date) ORDER BY (finish_date, finish_time_us) TTL finish_date + INTERVAL 7 DAY</engine>
</opentelemetry_span_log>
<query_log>
<engine>ENGINE = MergeTree PARTITION BY toYYYYMM(event_date) ORDER BY (event_date, event_time) TTL event_date + INTERVAL 30 DAY</engine>
</query_log>
</clickhouse>Important: TTL directives only apply when the system table is first created. On an existing install, after deploying the config you also need to retrofit the tables: SET max_table_size_to_drop = 0;
TRUNCATE TABLE system.trace_log;
ALTER TABLE system.trace_log MODIFY TTL event_date + INTERVAL 7 DAY;Repeat for each table you want to cap. 📚 Sources:
Have another question? Just tag @inkeep. |
|
Hi Team , We need some urgent help regarding the problem one for Inactive parts (Problem 1: Inactive Parts Accumulation) |
|
Hi @Vinothkumars1994 Can you provide me output of following queries, this will help to determine whether the 112 GiB is recent/transient or genuinely stuck. To check if the issue is active small parts. |
|
@Vinothkumars1994 these are two separate problems, and fixing either one doesn't touch your Langfuse data. 1. 112 GiB of inactive parts in Inactive parts are the old copies left behind after a merge or a mutation, so they come from work that did run. If merges were falling behind, you'd see many active parts instead; @Ashmita152's second query shows that. ClickHouse deletes an inactive part about 8 minutes later ( SELECT query_id, round(elapsed) AS sec, left(query, 100) AS query
FROM system.processes ORDER BY elapsed DESC LIMIT 5;
SELECT database, table, command, create_time, parts_to_do, latest_fail_reason
FROM system.mutations WHERE NOT is_done;Stop a stuck query with A detail about the number itself: a mutation hard-links the column files it doesn't change, so the old and the new part share them on disk, and While the disk is tight I'd skip 2. About 100 GiB of ClickHouse's own logs These are ClickHouse's diagnostics, not your traces. Langfuse does read
TRUNCATE TABLE system.text_log SETTINGS max_table_size_to_drop = 0;
TRUNCATE TABLE system.opentelemetry_span_log;
TRUNCATE TABLE system.query_log;On older ClickHouse, create a one-time flag first, then run the plain docker compose exec clickhouse sh -c 'touch /var/lib/clickhouse/flags/force_drop_table && chmod 666 /var/lib/clickhouse/flags/force_drop_table'The first To stop it coming back, mount a file like this into <clickhouse>
<query_log><ttl>event_date + INTERVAL 7 DAY DELETE</ttl></query_log>
<text_log><ttl>event_date + INTERVAL 7 DAY DELETE</ttl></text_log>
<trace_log><ttl>event_date + INTERVAL 7 DAY DELETE</ttl></trace_log>
<part_log><ttl>event_date + INTERVAL 7 DAY DELETE</ttl></part_log>
<opentelemetry_span_log>
<engine>ENGINE = MergeTree PARTITION BY toYYYYMM(finish_date) ORDER BY (finish_date, finish_time_us) TTL finish_date + INTERVAL 7 DAY DELETE</engine>
</opentelemetry_span_log>
</clickhouse>Two traps:
SELECT 'DROP TABLE system.' || name || ' SETTINGS max_table_size_to_drop = 0;'
FROM system.tables
WHERE database = 'system' AND match(name, '_log_[0-9]+$');One more thing, since you're on Langfuse 3.143.0: if you ever move ClickHouse to 26.8 or newer, update Langfuse first (#16858). The same steps with the full file for every log, how to mount it and how to check the result are in section 4 of a guide I maintain (my project): https://github.com/Protemir/diskvet/blob/main/docs/guide.md#4-how-do-i-set-a-ttl-on-clickhouse-system-logs |
Uh oh!
There was an error while loading. Please reload this page.
Describe your question
Description
Environment:
Langfuse: self-hosted (Docker)
ClickHouse: running in Docker container
Usage: production environment with active chat/LLM workload
Langfuse Version: 3.143.0
Problem 1:
We are observing a large accumulation of inactive parts in our ClickHouse default.observations and default.traces tables in production.
Running the following query:
SELECT
database,
table,
formatReadableSize(sum(bytes_on_disk)) AS inactive_size,
count() AS inactive_parts
FROM system.parts
WHERE active = 0
GROUP BY database, table
ORDER BY sum(bytes_on_disk) DESC;
default observations 112.55 GiB 191
Root Cause (our analysis):
High chat volume causes frequent small inserts into observations and traces. ClickHouse background merge threads cannot keep up with the insert rate, causing inactive parts to pile up even during non-business hours.
Questions:
Problem 2:
Our ClickHouse system database log tables are consuming over 100 GiB of disk space and appear to be growing unbounded with no TTL or retention policy configured.
SELECT
table,
formatReadableSize(sum(bytes_on_disk)) AS size
FROM system.parts
WHERE database = 'system' AND active = 1
GROUP BY table
ORDER BY sum(bytes_on_disk) DESC;
text_log 59.20 GiB
opentelemetry_span_log 20.48 GiB
query_log 15.69 GiB
trace_log 2.17 GiB
part_log 1.50 GiB
Question:
Please provide detailed steps to perform log rotation, or any other recommended solution, to manage the disk space consumed by ClickHouse system log tables in a self-hosted Langfuse production deployment.
Langfuse Cloud or Self-Hosted?
Self-Hosted
If Self-Hosted
3.143.0
If Langfuse Cloud
No response
SDK and integration versions
No response
Pre-Submission Checklist
All reactions