AgentSkillsCN

altinity-expert-clickhouse-ingestion

诊断 ClickHouse 的 INSERT 性能、批量大小、分区创建模式以及数据摄入瓶颈。适用于处理插入速度缓慢及数据管道中的各类问题。

SKILL.md
--- frontmatter
name: altinity-expert-clickhouse-ingestion
description: Diagnose ClickHouse INSERT performance, batch sizing, part creation patterns, and ingestion bottlenecks. Use for slow inserts and data pipeline issues.

Insert Performance and Ingestion Analysis

Diagnose INSERT performance, batch sizing, part creation patterns, and ingestion bottlenecks.


Diagnostics

Run all queries from the file checks.sql and analyze the results.


Problem-Specific Investigation

Insert with MV Overhead - Correlate by Query ID

When inserts feed materialized views, slow MVs cause insert delays. To correlate a slow insert with its MV breakdown:

sql
-- Correlate slow insert with MV breakdown (requires query_id)
select
    view_name,
    view_duration_ms,
    read_rows,
    written_rows,
    status
from system.query_views_log
where query_id = '{query_id}'
order by view_duration_ms desc

Ad-Hoc Query Guidelines

Required Safeguards

sql
-- Always limit results
limit 100

-- Always time-bound
where event_date = today()
-- or
where event_time > now() - interval 1 hour

-- For query_log, filter by type
where type = 'QueryFinish'  -- completed
-- or
where type like 'Exception%'  -- failed

Useful Filters

sql
-- Filter by table
where has(tables, 'database.table_name')

-- Filter by user
where user = 'producer_app'

-- Filter by insert size
where written_rows > 1000000  -- large inserts
where written_rows < 100      -- micro-batches

Cross-Module Triggers

FindingLoad ModuleReason
Part creation > 1/secaltinity-expert-clickhouse-mergesMerge backlog likely
High memory during insertaltinity-expert-clickhouse-memoryMemory limits, buffer settings
Slow MV during insertaltinity-expert-clickhouse-reportingAnalyze MV query
TOO_MANY_PARTS erroraltinity-expert-clickhouse-merges + altinity-expert-clickhouse-schemaImmediate action needed
Insert queries reading too muchaltinity-expert-clickhouse-schemaMV design issues
Disk slow during insertaltinity-expert-clickhouse-storageStorage bottleneck

Key Settings Reference

SettingDefaultImpact
max_insert_block_size1048545Rows per block
min_insert_block_size_rows1048545Min rows before flush
min_insert_block_size_bytes268435456Min bytes before flush
async_insert0Async insert mode
async_insert_max_data_size1000000Async batch threshold
async_insert_busy_timeout_ms200Max wait for async batch