Bug: ClickHouse system log tables never expire: <table_ttl> in assets/clickhouse-config.xml is ignored

Open Beginner friendly
#2,088 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
clickhouse, docker

Research direction

Start by reading assets/clickhouse-config.xml and the ClickHouse system log configuration docs linked in the issue. Check how the configured log tables express TTLs and account for processors_profile_log, which is also growing; docker-compose.yml shows how the config is mounted. Done when the configured system logs retain about seven days of data and the issue's SHOW CREATE or TTL query confirms the TTLs.

Written by the indexing model from the issue text.

Description

Component

OpenLIT

What happened?

assets/clickhouse-config.xml (added in #790) tries to keep ClickHouse's system log tables for 7 days with <table_ttl>604800</table_ttl> on query_log, trace_log, text_log, metric_log, asynchronous_metric_log, part_log and latency_log.

ClickHouse has no table_ttl setting. It ignores the key without a warning, so these tables are created with no TTL and keep growing. On an idle OpenLIT 2.2.0 stack (no traffic) we measured about 1.1 MB/h (≈27 MB/day, ≈0.8 GB/month) of system-log data that is never deleted. Most of it is system.asynchronous_metric_log, followed by processors_profile_log and query_log. OpenLIT's own tables don't grow at idle. processors_profile_log (≈0.27 MB/h) isn't in clickhouse-config.xml, so fixing the TTL key alone won't cap it. A <processors_profile_log> block with the same <ttl> (or remove="1") would.

SHOW CREATE on a stack started with this config shows no TTL clause:

system.query_log:
MergeTree PARTITION BY toYYYYMM(event_date) ORDER BY (event_date, event_time) SETTINGS index_granularity = 8192

All 7 configured tables are the same: query_log, trace_log, text_log, metric_log, asynchronous_metric_log and part_log report "no TTL". latency_log does not exist on 24.4.

ClickHouse's per-table key for this is <ttl>, which takes a TTL expression, for example <ttl>event_date + INTERVAL 7 DAY DELETE</ttl> (docs).

Steps to reproduce
  1. Start ClickHouse with the shipped config, as docker-compose.yml does:

    docker run -d --rm --name ttl-repro -e CLICKHOUSE_PASSWORD=x \
      -v "$PWD/assets/clickhouse-config.xml:/etc/clickhouse-server/config.d/custom-config.xml:ro" \
      clickhouse/clickhouse-server:24.4.1
    
  2. Write a log row and list the TTLs:

    docker exec ttl-repro clickhouse-client --password x -q "SYSTEM FLUSH LOGS"
    docker exec ttl-repro clickhouse-client --password x -q "
      SELECT name, if(engine_full LIKE '%TTL%', 'TTL', 'no TTL')
      FROM system.tables
      WHERE database = 'system'
        AND name IN ('query_log','trace_log','text_log','metric_log','asynchronous_metric_log','part_log')"
    

    Every table returns no TTL.

  3. Optional: show that old rows are kept. Insert a 10-day-old and a 3-day-old row, then force a merge:

    docker exec ttl-repro clickhouse-client --password x -q "
      INSERT INTO system.query_log (event_date, event_time, type, query) VALUES
        (today()-10, now()-864000, 'QueryFinish', 'age10'),
        (today()-3,  now()-259200, 'QueryFinish', 'age3')"
    docker exec ttl-repro clickhouse-client --password x -q "OPTIMIZE TABLE system.query_log FINAL"
    docker exec ttl-repro clickhouse-client --password x -q "
      SELECT query, count() FROM system.query_log WHERE query IN ('age10','age3') GROUP BY query"
    

    Both rows are still there. With <ttl>event_date + INTERVAL 7 DAY DELETE</ttl>, only age3 remains.

Expected behavior

System log tables keep about 7 days of data, as the config's comments say, and the ClickHouse volume stops growing while OpenLIT is idle.

Environment
  • OpenLIT version: 2.2.0 (ghcr.io/openlit/openlit:2.2.0). assets/clickhouse-config.xml on main is identical to the 2.2.0 copy as of 2026-12-04.
  • ClickHouse: clickhouse/clickhouse-server:24.4.1, the version pinned in docker-compose.yml
  • Deployment: the repo's docker-compose.yml on Linux arm64
Additional context
  • The same file is mounted by docker-compose.yml, src/dev-docker-compose.yml and examples/linux/docker-compose.yaml. examples/kubernetes/clickhouse.yaml uses its own inline ConfigMap and doesn't use this file.

  • Existing installs: when the TTL changes, ClickHouse renames the old table to <name>_0 (for example system.query_log_0) and creates a new one with the TTL. The renamed tables still have no TTL and keep their data. Users who want the space back must drop them by hand:

    SELECT name, formatReadableSize(total_bytes) FROM system.tables
    WHERE database = 'system' AND match(name, '_log_[0-9]+$');
    -- then, for each one: DROP TABLE system.<name>;
    
  • Other keys in the file that ClickHouse also ignores. These are not in the proposed fix and could be a separate change if you want one:

    • <level> under trace_log and part_log. It is valid only under text_log.
    • The <system_log> block.
    • <log_queries_min_query_duration_ms> under query_log. This is a user/profile setting, so it has no effect in config.d and queries are not filtered to slow ones. It would need a users.d profile file.
Pre-submission checklist
  • I searched existing issues and didn't find a duplicate
Are you willing to submit PR?

Yes, I am willing to submit a PR!

Dominant language
TypeScript
Stars
2.8k
Forks
385
Avg merge
7d 4h
Merged PRs (30d)
74

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openlit/openlit

All issues in openlit/openlit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.