npx skills add ...
npx skills add altinity/altinity-skills --skill altinity-expert-clickhouse-caches
Analyzes the ClickHouse mark cache, uncompressed cache, query cache and compiled expression cache, their hit ratios and their RAM footprint. Use when cache hit ratios are poor, caches take too much RAM, mark counts look excessive, or cache sizing needs tuning.
npx skills add altinity/altinity-skills --skill altinity-expert-clickhouse-caches
Answers "are the caches sized right and are they helping?" from system.metrics, system.asynchronous_metrics, system.events, system.parts, system.server_settings and system.metric_log.
Run altinity-expert-clickhouse-connection first if the connection mode, cluster and time window are not yet established.
checks.sql — 12 checks: mark cache health (hit ratio and RAM share), uncompressed cache health, query cache, compiled expression cache, mark bytes per table, primary-key memory per table, cache events over time, current cache server settings, mark-cache sizing analysis, a hit-ratio diagnostic over the tables queried today, tables holding excessive marks, and the mark-cache hit ratio minute by minute for the last hour. Check caches-07 needs system.asynchronous_metric_log and caches-12 needs system.metric_log; skip them when those tables are absent.reference.md — background (settings, sizing, anti-patterns); read only when you need to explain a recommendation.; and start with a -- @check <id> <title> header; keep the id with its result.-- @requires: skip the statement when the named table is missing, when keeper is required and the server has no Keeper/ZooKeeper, or when the version condition is not met. List skipped ids with the reason.{cluster} as written when a cluster macro exists; otherwise apply the connection skill's rewrite rule. Any other {placeholder} is a template variable: substitute a real value first or skip the statement.UNKNOWN_IDENTIFIER, run DESCRIBE TABLE system.<table> and drop the missing column.severity column is the verdict for that row. Copy it; do not re-grade.hit_severity and size_severity. Copy both; a cache can be well sized and still useless, or effective and still too large.Moderate, below 0.5 Major, below 0.3 Critical. The causes are, in order: the cache is too small for the working set, queries touch many different tables, or the workload is many small queries against cold data. Use caches-10 to tell these apart before resizing.index_granularity on the tables in caches-11, let merges reduce the number of tiny parts, drop unused tables, and only then lower mark_cache_size. Never lower index_granularity to shrink the cache; a smaller granularity produces more marks, not fewer.Moderate, not Critical. Size 0 (disabled) is a legitimate production choice; the cache only pays off for repeated small point reads with use_uncompressed_cache enabled per query or per profile.mark_cache_size and uncompressed_cache_size are server settings; the query cache size lives in the server config as <query_cache><max_size_in_bytes> and may therefore be absent from the result. use_query_cache and use_uncompressed_cache are query-level settings and never appear here.Marks per table inside one database, to find what fills the mark cache:
The index_granularity actually in force for one table, to confirm before recommending a change:
Largest query cache entries, when caches-03 shows the cache filling up:
check, severity, object, evidence, recommendation; one row per finding, Critical first. Evidence quotes the numbers from the result rows.altinity-expert-clickhouse-memoryaltinity-expert-clickhouse-storageindex_granularity or a wide ORDER BY → load skill altinity-expert-clickhouse-schemaaltinity-expert-clickhouse-mergesaltinity-expert-clickhouse-reportingSELECT database, table, engine, create_table_query FROM system.tables WHERE database = '{database}' AND name = '{table}';SELECT substring(query, 1, 120) AS query_preview, formatReadableSize(result_size) AS result_size, stale, shared, expires_at FROM system.query_cache ORDER BY result_size DESC LIMIT 20;