Skip to content

The bundled ClickHouse keeps query_log and text_log for 30 days - #828

Merged
zlareb1 merged 5 commits into
ClickHouse:mainfrom
enricoconvento98:fix/436-system-log-retention
Nov 18, 2026
Merged

zlareb1 merged 5 commits into
ClickHouse:mainfrom
enricoconvento98:fix/436-system-log-retention

Conversation

@enricoconvento98

@enricoconvento98 enricoconvento98 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #436
Related: #428

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The bundled ClickHouse and the Helm chart's dev ClickHouse keep 30 days of system.query_log and system.text_log rows. The deployment guide gives the same configuration file for a self-managed server. An existing install keeps its earlier rows in system.query_log_0 and system.text_log_0 until you drop them (deployment guide, Log retention).

Why

A refused statement's error can quote the allowlisted metadata value it failed on, such as a memory key, a title or a user id. Erasure reaches neither system log, and ClickHouse's default configuration sets no TTL on them, so those rows stayed until an operator bounded them. #428 left this for its own change because a TTL change to a system log renames the existing table on the next start.

Scope and risk

  • New deploy/clickhouse-config/system_logs.xml sets event_date + INTERVAL 30 DAY DELETE on query_log and text_log.
  • Mounted by compose.yaml, dev/ci_start_clickhouse.sh, the release bundle (scripts/release/build_stack_bundle.py) and inline in the Helm chart's dev ClickHouse (deploy/helm/loom/templates/dev-clickhouse.yaml, ConfigMap key and volume mount).
  • Docs: a "Log retention" section in docs/operations/deployment.md (the file for self-managed servers, the _0 rename, dropping the old tables); docs/architecture/assistant.md and docs/features/memory/retention-and-erasure.md no longer say the logs have no TTL.
  • Left alone: scripts/gates/mixed_version.py and tests/analyzer/README.md start short-lived containers that do not mount system_logs.xml; a log TTL changes nothing there.
  • Risk: rows older than 30 days leave both logs. insights.query and anything else that reads system.query_log sees at most 30 days.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: on the first start with the file, ClickHouse renames the existing logs to system.query_log_0 and system.text_log_0, keeps them with their rows and no TTL, and creates new logs. Read what you need from the old tables, then DROP TABLE IF EXISTS system.query_log_0; DROP TABLE IF EXISTS system.text_log_0;. A self-managed server gets the TTL only by adding the same file to config.d/.
  • Rollback: reverting removes the file; on the next start ClickHouse renames the 30-day logs to the next free _N name and creates them again with no TTL. No migration, no generated files.

Tests

  • tests/unit/test_deploy_clickhouse_config.py: one test that system_logs.xml sets the 30-day TTL on both logs, one that the Helm chart's inline copy matches the file (fails when the chart's TTL is changed).
  • Against ClickHouse 26.10.4 and 26.9.18.11 (the Helm pin): no TTL before; after a restart with the file, SHOW CREATE TABLE system.query_log and system.text_log show TTL event_date + toIntervalDay(30); the old tables became query_log_0 and text_log_0 with their rows and no TTL; DROP TABLE on them works; a second TTL change renames to the next free _N name, which keeps its old TTL.
  • ClickHouse 26.10.4 with the <text_log> block removed from config.xml and system_logs.xml in config.d/: system.text_log exists and records Trace rows, as with the default configuration. The deployment guide says to keep only the <query_log> block on such a server.
  • After rebasing on main: ruff format --check, make lint, and pytest tests/unit/test_deploy_clickhouse_config.py tests/unit/test_public_copy.py tests/unit/test_doc_links.py tests/unit/test_agent_instructions.py (474 passed). Before the rebase: helm lint --strict with values-kind.yaml, and the rendered ConfigMap XML parses.
  • Not run locally, left to CI: shfmt (the shell half of make format-check), make typecheck, the full make test-unit, and kubeconform.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I checked the TTL behaviour and the _0 rename against a real ClickHouse, and the Helm copy against the file.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: none are affected.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited. (No migration.)
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version. (No plugin file changed.)
  • The frontend builds and its tests pass, if frontend/ changed. (Not changed.)
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

enricoconvento98 and others added 5 commits November 18, 2026 06:23
A refused statement's error can quote an allowlisted metadata value it
failed on, and erasure reaches neither system log. ClickHouse's default
configuration sets no TTL on them, so the rows stayed until an operator
bounded them.

system_logs.xml sets a 30-day TTL on both logs. compose.yaml, the CI
ClickHouse, the release bundle and the Helm chart's dev ClickHouse mount
it. The deployment guide gives the same file for self-managed servers and
says what happens to the old tables: on the first start with the file,
ClickHouse renames them to query_log_0 and text_log_0 and keeps them with
no TTL, so an operator drops them.

Closes: ClickHouse#436

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Enrico Convento <[email protected]>
The assistant's retention table said 30 days for the whole server log, which also covers ClickHouse's file log, rotated by size. It now names system.query_log and system.text_log. The production checklist points a self-managed server at system_logs.xml.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Enrico Convento <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Enrico Convento <[email protected]>
On a server whose configuration has no text_log, a <text_log> element creates system.text_log at trace level. The guide says to keep only the query_log block there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Enrico Convento <[email protected]>
@zlareb1 zlareb1 self-assigned this Nov 18, 2026

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings in the log TTLs, config mounts, release bundle, Helm template or documented restart behavior. The 63 focused config and bundle tests pass locally. All 49 checks and all matching parent workflows pass; intervening main changes do not overlap the deployment paths.

@zlareb1
zlareb1 merged commit 2aab9c1 into ClickHouse:main Nov 18, 2026
49 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The bundled ClickHouse bounds how long query_log and text_log keep rows

2 participants