Add article: exporting query and session logs to files, S3, or HTTP - #189
Merged
Conversation
The KB had no coverage of getting system.query_log / system.session_log out of the server for auditing. session_log appeared exactly once across content/en (as <session_log remove="1"/>); logging.md and ch-logs-2-json-vectordev.md cover only the server text log files; the S3 articles treat S3 as MergeTree storage, never as an export sink. Every recipe and error message in the article was executed against clickhouse-server in Docker (26.7.5.10, 26.4.5.143, 26.3.21.7 LTS, 25.8.32.4, 24.10.1.2812) with MinIO and a local HTTP collector. Findings that shaped the article: - A materialized view with an S3 target can permanently destroy rows in the local system.query_log. materialized_views_ignore_errors only guards row-push errors; the S3 sink's object-existence probe throws during createSink(), outside the guard, which fails the whole flush. Measured: 20/20 markers survive with no MV and with a working target, 1/20 with a misconfigured S3 target, 0/10 with an unreachable one. Reproduced on 26.7, 26.3 and 25.8. URL targets are unaffected. - SETTINGS s3_create_new_file_on_insert = 1 on a CREATE TABLE with an S3 engine is silently dropped (absent from SHOW CREATE TABLE). The same setting on the MV is kept but has no effect on the target write. Only a users.d profile default works. - After an upgrade that renames system.query_log to query_log_0, the MV follows the renamed table and the export stops silently, with no error and no SystemLogErrorOnFlush increment. Includes a detection query against system.tables and the fix. - Issue #112419 reproduced: two servers on one S3 key sequence made 300 acknowledged inserts with zero errors and left only 267 objects. - File engine does accept a stable path under user_files and appends across flushes; an arbitrary absolute path is rejected with code 291. - SystemLogErrorOnFlush was added in 25.2 (PR #75466). Its description string claims failed flushes are repeated; they are not. The one-line note in altinity-kb-system-tables-eat-my-disk.md is included here because it links to the new page. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AsB1E5eSBXpaZT4jGzY57L
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
A new article at
content/en/altinity-kb-setup-and-maintenance/altinity-kb-export-system-logs.mdcovering how to getsystem.query_logandsystem.session_logout of the server and into S3, an HTTP collector, or a file.Gap it fills. Swept all of
content/en:session_logappears exactly once in the KB, as<session_log remove="1"/>inaltinity-kb-system-tables-eat-my-disk.md.logging.mdandch-logs-2-json-vectordev.mdcover only the server text log files, not thesystem.*_logtables. Every article underaltinity-kb-s3-object-storage/treats S3 as MergeTree storage, never as an export sink. There is no article on theURLengine or on an MV writing to an external target.Testing
Per
AGENTS.md("every recipe must be copy-pasteable and tested"), every DDL block, object name, file path, and error message in the article was produced by running it. Lab:clickhouse-serverin Docker against MinIO and a stdlib HTTP collector.Versions: 26.7.5.10 (latest stable), 26.4.5.143, 26.3.21.7 (LTS), 25.8.32.4, 24.10.1.2812 (pre-#75679).
The three recipes were re-run verbatim on a clean 26.7.5.10 server as a final check.
Findings worth a reviewer's attention
1. An MV with an S3 target can permanently destroy local
system.query_logrows.materialized_views_ignore_errors=true(set unconditionally since 23.3) only guards exceptions thrown while pushing rows. The S3 sink's object-existence probe throws during sink construction:That escapes the guard and fails the whole flush, and there is no retry path —
SystemLogQueue::pop()detaches the batch before the insert runs.Same on 26.3.21.7 and 25.8.32.4.
URLtargets are unaffected (10/10 preserved on both HTTP 503 and connection-refused), so the usual "export failures are harmless" framing is true for HTTP and false for S3.2. The obvious way to set
s3_create_new_file_on_insertdoesn't work. On aCREATE TABLEwith an S3 engine theSETTINGSclause is silently dropped — it never appears inSHOW CREATE TABLE. On the MV it is preserved inSHOW CREATEbut has no effect on the target write. Only ausers.dprofile default works. The article documents all three, since the two that fail are the two anyone would try first.3. Upgrades silently break the export. After 25.8.32.4 → 26.7.5.10,
system.query_logis renamed toquery_log_0and the MV follows the renamed table — 0 rows exported, no error,SystemLogErrorOnFlushnever increments, andSHOW CREATE TABLEstill readsFROM system.query_log. The article includes asystem.tablesdetection query and the fix.4. Issue #112419 reproduced. Two servers on one S3 key sequence: 300 inserts, all acknowledged, zero errors, only 267 objects afterwards.
5.
SystemLogErrorOnFlushwas added in 25.2 (PR #75466; the changelog lists it under 25.3). Its own description string insystem.eventssays "Attempts to flush are repeated." — which is false for this path, and would lead an operator to the opposite of the right conclusion.Also corrected along the way: the
Fileengine does accept a stable path underuser_filesand appends across flushes (an arbitrary absolute path gives code 291), and theifNull()casts onsession_logare needed — not for the DDL, which accepts implicit conversion, but because a realNULLraises code 349 at push time, which is silently swallowed during a flush.Second file in this PR
The 2-line note in
altinity-kb-system-tables-eat-my-disk.mdis attached to its existing Note 2 about renamed_Nlog tables — exactly the hazard finding 3 describes. It is in this PR rather than a separate one because it links to the new page and would 404 on its own.Verification
Built with the CI-pinned Hugo (0.128.2, per
.github/workflows/gh-pages.yml): 328 pages, page renders, all 6{{% alert %}}shortcodes resolve with no leakage, both internal links resolve to existing pages, and the page appears in the Setup & maintenance nav in the expected alphabetical position forweight: 100.Note for maintainers: the site does not build on any Hugo newer than 0.128.2 —
unknown output format "md" for kind "home", then.Site.DisqusShortnameremoval. That is pre-existing onmainand unrelated to this PR.Reviewer notes
s3_create_new_file_on_insertdefault has a blast radius beyond the audit export; the article flags this rather than hiding it. If there's a narrower placement I missed, I'd like to know — I tested table-level and MV-level and both fail.Distributed-sender section is design prose, not a recipe, and makes no tested claim.🤖 Generated with Claude Code
https://claude.ai/code/session_01AsB1E5eSBXpaZT4jGzY57L