clickhouse-log-retention plugin for Tutor
Stops ClickHouse’s own system.* log tables (trace_log, text_log, metric_log, asynchronous_metric_log, …) from filling the disk. Works for both Cairn (cairn-clickhouse) and Aspects (clickhouse).
ClickHouse records its own telemetry in the system database and never expires it. On Open edX instances this telemetry is often more than 95% of what ClickHouse stores.
What it does
Sets a TTL on every system log table (default 7 days, query_log 30 days).
Turns the query profiler off (it is what makes system.trace_log huge).
Nothing else is touched: no data database, no live table is dropped.
Installation
pip install git+https://github.com/Abstract-Tech/tutor-contrib-clickhouse-log-retention
Usage
tutor plugins enable clickhouse-log-retention
tutor config save
tutor local restart clickhouse # Aspects
tutor local restart cairn-clickhouse # Cairn
Settings (tutor config save --set NAME=value):
CLICKHOUSE_LOG_RETENTION_DAYS: days to keep the diagnostic logs (default 7).
CLICKHOUSE_LOG_RETENTION_QUERY_LOG_DAYS: days to keep system.query_log (default 30). The Aspects performance dashboards read it, so keep it longer.
A value below 1 is treated as 1.
After the first restart (important)
ClickHouse renames every existing system log table to <name>_0, <name>_1, … and creates a fresh one with the TTL. The renamed copies keep their data and their disk space until you drop them. List them:
SELECT name, formatReadableSize(total_bytes) AS size
FROM system.tables
WHERE database = 'system' AND match(name, '_log_[0-9]+$')
ORDER BY total_bytes DESC;
Each system.<name>_N listed is an old copy of ClickHouse’s own diagnostics: nothing writes to it and neither Cairn nor Aspects reads it, so DROP TABLE system.<name>_N is safe. Never drop a table without a numeric suffix.
To free space that is already used, clean up before enabling the plugin: drop old monthly partitions with ALTER TABLE system.<table> DROP PARTITION ID 'YYYYMM' (the renamed copies then stay small).
Disabling the plugin does not remove what it rendered. Delete env/local/docker-compose.override.yml and env/plugins/clickhouse-log-retention and run tutor config save again.
How it works
All the XML is in tutorclickhouse_log_retention/templates (real files, easy to read). plugin.py has the full explanation.
Aspects: the TTL goes through Aspects’ own patch clickhouse-server-config (present in every release since 0.70). The profiler setting needs its own file in the users directory Aspects mounts, because ClickHouse ignores a second <profiles> block in the same file.
Cairn: no patch exists, so two XML files are rendered and mounted by a docker-compose.override.yml in env/local (Tutor loads it for tutor local). It replaces an existing override file of that name. Kubernetes is not covered.
Tested with Tutor 16 to 22 (Cairn 16 to 22, Aspects 0.107 to 6.0), and against real ClickHouse 22.1, 24.1, 24.2, 24.3, 24.8 and 25.8 containers.
Hosts that are not Tutor (plain Docker Compose)
Mount the two files in manual/ into the ClickHouse container (the profiler file must be in users.d, not config.d):
volumes:
- ./data:/var/lib/clickhouse/
- ./zz-system-ttl.xml:/etc/clickhouse-server/config.d/zz-system-ttl.xml:ro
- ./zz-noprofiler.xml:/etc/clickhouse-server/users.d/zz-noprofiler.xml:ro
Recreate the container (docker compose up -d). The same renaming as above happens on the first start.
License
This software is licensed under the terms of the AGPLv3.
Metadata
Release files for tutor-contrib-clickhouse-log-retention 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tutor_contrib_clickhouse_log_retention-0.1.1.tar.gz | 17.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tutor_contrib_clickhouse_log_retention-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.0 kB
Release files / tutor_contrib_clickhouse_log_retention-0.1.1.tar.gz
| Download URL | tutor_contrib_clickhouse_log_retention-0.1.1.tar.gz |
|---|---|
| Size | 17.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d339457f227cbc0aaf027a60eaa13ef7d716bc3a5d9331427576e5894adc7af2
|
|
BLAKE2b-256 checksum How to use checksums |
d28b9253168443945252a2a92541232ae95ae893923589a002203614e71d3cca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / tutor_contrib_clickhouse_log_retention-0.1.1-py3-none-any.whl
| Download URL | tutor_contrib_clickhouse_log_retention-0.1.1-py3-none-any.whl |
|---|---|
| Size | 22.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb15daedbd98bf159bcb0568ac667dbf4eea823e78db774f7a3a9cf6e7215f63
|
|
BLAKE2b-256 checksum How to use checksums |
687cdc4ba21bd428a2b0a08cff666609d464f89e8b3ff3eecc81e67dfbc4bd6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency log