---
name: clickhouse-common-errors
description: |-
  Diagnose and fix the top 15 ClickHouse errors — query failures, insert problems,
  memory limits, and merge issues.
  Use when a ClickHouse query or insert throws an exception, a server-side error
  appears in logs, or a failed query needs root-cause analysis.
  Trigger with "clickhouse error", "fix clickhouse", "clickhouse not working",
  "debug clickhouse", "clickhouse exception", "clickhouse syntax error".
allowed-tools: Read, Grep, Bash(curl:*)
version: 1.7.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - database
  - analytics
  - clickhouse
  - olap
compatibility: Designed for Claude Code
title: clickhouse-common-errors
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/error-reference.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors/references/error-reference.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/clickhouse-common-errors`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/clickhouse-common-errors`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/clickhouse-common-errors --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/clickhouse-common-errors --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# ClickHouse Common Errors

## Overview

Quick reference for the most common ClickHouse errors with real error codes,
diagnostic queries, and proven solutions. The three highest-frequency errors are
inline below; the full catalog of 10 errors plus system-table diagnostics lives
in [references/error-reference.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors/references/error-reference.md).

## Prerequisites

- Access to a ClickHouse endpoint — either the native `clickhouse-client` or the
  HTTP interface (`curl` against `:8123`).
- Permission to read the `system.*` introspection tables (`system.parts`,
  `system.processes`, `system.query_log`, `system.columns`, `system.replicas`).
- The failing statement's text and, ideally, the raw exception string — the
  parenthetical name (e.g. `MEMORY_LIMIT_EXCEEDED`) and numeric code drive lookup.

## Instructions

Follow this loop to turn a raw ClickHouse exception into a verified fix:

1. **Capture the exception name and code.** Read the error string the client
   returned. If you only have a log file, use `Grep` to pull the matching line —
   `Grep` for `DB::Exception` or a specific token like `MEMORY_LIMIT_EXCEEDED`
   across the log to isolate the failure.
2. **Map it to a category.** Use the [Error Handling](#error-handling) code table
   to classify the error as Schema, Query, Performance, Permissions, Concurrency,
   Resources, or Insert-pattern.
3. **Apply the inline fix** for the three top errors (Too Many Parts, Memory
   Limit, Syntax) below, or open
   [references/error-reference.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors/references/error-reference.md) for the other
   seven plus copy-paste diagnostic queries.
4. **Confirm with a system table.** Re-run the relevant `system.*` query (part
   count, `system.processes`, `system.query_log`) to prove the condition cleared
   rather than assuming the fix took.

### Top 3 errors (inline)

**Too Many Parts (Code 252)** — hundreds of tiny inserts outpace merges:

```sql
-- Check current part count per table
SELECT database, table, count() AS part_count
FROM system.parts WHERE active GROUP BY database, table ORDER BY part_count DESC;

-- Temporary relief; permanent fix is batching (10K+ rows per INSERT)
ALTER TABLE events MODIFY SETTING parts_to_throw_insert = 1000;  -- default 300
```

**Memory Limit Exceeded (Code 241)** — query wants more RAM than `max_memory_usage`:

```sql
SET max_memory_usage = 20000000000;             -- 20GB for this query, OR
SET max_bytes_before_external_group_by = 10000000000;  -- spill big GROUP BY to disk
```

**Syntax Error (Code 62)** — most often MySQL habits leaking in:

```sql
SELECT "user_id" FROM events;          -- double-quote (not `backtick`) identifiers
SELECT * FROM events LIMIT 10 OFFSET 20;  -- OFFSET keyword, not LIMIT 10, 20
```

See [references/error-reference.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors/references/error-reference.md) for Unknown
Table, Timeout, DateTime parsing, Readonly, No Such Column, Type Mismatch, and
Distributed-table errors.

## Output

Working through this skill produces:

- A **classified diagnosis** — the error name, numeric code, and category from
  the table below.
- A **concrete remediation** — the exact `SET`, `ALTER`, or corrected SQL to run,
  plus whether it is a temporary relief valve or a permanent fix.
- A **verification query** against a `system.*` table confirming the condition
  cleared (e.g. part count back under threshold, no query stuck in
  `system.processes`).

## Error Handling

| Error Code | Name | Category |
|------------|------|----------|
| 16 | NO_SUCH_COLUMN_IN_TABLE | Schema |
| 60 | UNKNOWN_TABLE | Schema |
| 62 | SYNTAX_ERROR | Query |
| 159 | TIMEOUT_EXCEEDED | Performance |
| 164 | READONLY | Permissions |
| 202 | TOO_MANY_SIMULTANEOUS_QUERIES | Concurrency |
| 241 | MEMORY_LIMIT_EXCEEDED | Resources |
| 252 | TOO_MANY_PARTS | Insert pattern |

If the error name is not in this table, search the raw exception text against the
[Error Codes Reference](https://clickhouse.com/docs/knowledgebase) and inspect
`system.query_log` (`WHERE type = 'ExceptionWhileProcessing'`) for the full
server-side context.

## Examples

**Diagnosing a stalled insert pipeline.** Inserts start failing with
`Too many parts (600)`. Classify as code 252 (Insert pattern), run the
`system.parts` count query to see which table is affected, raise
`parts_to_throw_insert` for immediate relief, then switch the writer to batched
inserts. Full walkthrough and the other nine errors are in
[references/error-reference.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors/references/error-reference.md).

**Killing a runaway query.** A dashboard query hangs. Query `system.processes`
to find its `query_id`, then `KILL QUERY WHERE query_id = '...'`. The complete
set of diagnostic queries (running queries, recent errors, disk usage, merge
health) lives in the Diagnostic Queries section of
[references/error-reference.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors/references/error-reference.md).

## Resources

- [Error Codes Reference](https://clickhouse.com/docs/knowledgebase)
- [System Tables](https://clickhouse.com/docs/operations/system-tables)
- [Query Log](https://clickhouse.com/docs/operations/system-tables/query_log)
- [references/error-reference.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-common-errors/references/error-reference.md) — full 10-error
  catalog plus diagnostic queries
- For comprehensive debugging, see the `clickhouse-debug-bundle` skill.
