본문으로 건너뛰기
cccskills
무료GitHub에 공개

clickhouse-cloud-multi-table-rename

Fix ClickHouse Cloud migration failures caused by multi-table RENAME statements. Use when: (1) Migration fails with "Database X is Shared, it does not support renaming of multiple tables in single query", (2) golang-migrate or other migration tools show dirty database version after a table-swap migration on ClickHouse Cloud, (3) Schema migration works on self-hosted ClickHouse but fails on ClickHouse Cloud. ClickHouse Cloud uses SharedMergeTree engine which has restrictions not present in regular MergeTree.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md5.3 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

ClickHouse Cloud Multi-Table RENAME Limitation

Problem

ClickHouse Cloud (SharedMergeTree engine) does not support renaming multiple tables in a single RENAME TABLE statement, which is a common pattern for atomic table swaps in schema migrations. Self-hosted ClickHouse supports this, so migrations that work locally or on self-hosted instances will fail on ClickHouse Cloud.

Context / Trigger Conditions

  • Error message: "Database X is Shared, it does not support renaming of multiple tables in single query"
  • Error code: 48
  • Using golang-migrate (or similar) with ClickHouse Cloud
  • Migration SQL contains a pattern like:
    RENAME TABLE db.original TO db.original_old,
                 db.new_version TO db.original;
    
  • Migration works in staging (self-hosted ClickHouse) but fails in production (ClickHouse Cloud)

Solution

Prevention: Write ClickHouse Cloud-compatible migrations

Instead of multi-table RENAME:

-- BAD: This fails on ClickHouse Cloud
RENAME TABLE nostr.my_table TO nostr.my_table_old,
             nostr.my_table_v2 TO nostr.my_table;

Use separate RENAME statements:

-- GOOD: Split into individual operations
RENAME TABLE nostr.my_table TO nostr.my_table_old;
RENAME TABLE nostr.my_table_v2 TO nostr.my_table;

Note: This loses atomicity, but ClickHouse Cloud doesn't support the atomic version anyway.

Recovery: Fix a dirty migration that already failed

  1. Check the current state — identify which tables exist and what state they're in:

    SHOW TABLES LIKE '%my_table%';
    DESCRIBE TABLE nostr.my_table;       -- Check if it has old or new schema
    DESCRIBE TABLE nostr.my_table_v2;    -- Check if the new table was created
    
  2. Complete the migration manually with separate renames:

    -- If both original and v2 exist (RENAME never executed):
    RENAME TABLE nostr.my_table TO nostr.my_table_old;
    RENAME TABLE nostr.my_table_v2 TO nostr.my_table;
    DROP TABLE IF EXISTS nostr.my_table_old;
    -- Recreate any views that were dropped
    
  3. Force the migration version to mark it as completed:

    # Using golang-migrate
    migrate -path=/migrations -database "clickhouse://..." force VERSION
    
  4. If using K8s jobs, recreate the job with force VERSION args:

    containers:
      - name: migrate
        image: my-migrate-image:tag
        args: ["force", "65"]  # The migration number that was applied manually
    

Verification

After manual migration, verify:

-- Check table has new schema
DESCRIBE TABLE nostr.my_table;

-- Check migration version is clean (not dirty)
SELECT version, dirty FROM schema_migrations ORDER BY version DESC LIMIT 5;

-- Check old/temp tables are cleaned up
SHOW TABLES LIKE '%my_table%';

Example

Migration 65 for funnelcake needed to change view_traffic_sources.source from Enum8 to String. The migration:

  1. Dropped a dependent view
  2. Created view_traffic_sources_v2 with new schema
  3. Copied data
  4. Tried RENAME TABLE original TO old, v2 TO original — FAILED on ClickHouse Cloud

Recovery:

# Via HTTP API from a curl pod in the cluster:
curl -s "$CH_URL/?database=nostr&user=$USER&password=$PASS" \
  --data-binary 'RENAME TABLE nostr.view_traffic_sources TO nostr.view_traffic_sources_old'
curl -s "$CH_URL/?database=nostr&user=$USER&password=$PASS" \
  --data-binary 'RENAME TABLE nostr.view_traffic_sources_v2 TO nostr.view_traffic_sources'
curl -s "$CH_URL/?database=nostr&user=$USER&password=$PASS" \
  --data-binary 'DROP TABLE IF EXISTS nostr.view_traffic_sources_old'
# Recreate the summary view...
# Then force migration version to 65

Notes

  • SharedMergeTree is the default engine on ClickHouse Cloud — you cannot switch to regular MergeTree
  • Other SharedMergeTree limitations exist (e.g., some ALTER operations behave differently)
  • When writing migrations for dual self-hosted/cloud environments, always use separate RENAME statements
  • The golang-migrate ClickHouse driver uses x-multi-statement=true which splits statements on ;, but the RENAME with commas is still a single statement
  • If a failed migration left a _v2 table behind, you must DROP TABLE IF EXISTS it before re-running the migration, or CREATE TABLE IF NOT EXISTS will silently skip creation and the INSERT will duplicate data into the existing v2 table
  • Use SET alter_sync = 2; SET mutations_sync = 2; in migrations to ensure synchronous execution on ClickHouse Cloud

References

  • ClickHouse Cloud SharedMergeTree differences: SharedMergeTree engine has restrictions on operations that require cross-shard coordination
  • golang-migrate ClickHouse driver: github.com/golang-migrate/migrate with clickhouse driver

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y". Use when: (1) ExternalSecret shows OutOfSync in ArgoCD but won't sync, (2) ArgoCD application status shows "namespace X is not permitted in project 'infrastructure'", (3) ExternalSecret targets a namespace managed by a different ArgoCD project, (4) Using apps-of-apps pattern with separate infrastructure and application projects.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2652026년 10월 21일 업데이트

Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language. After selection, generates AI image prompts and visual briefs section-by-section. Use when the user shares content and needs visual direction, image sourcing, or creative direction for any material.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2652026년 10월 21일 업데이트

Fix "Null check operator used on a null value" errors when an object is set to null during an async await. Use when: (1) Object reference is nullified while awaiting, (2) Code accesses object with ! after await returns, (3) Cancel/dispose operations run concurrently with async operations on same object. Solution: capture local reference before await.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2652026년 10월 21일 업데이트

Add custom metadata headers (x-amz-meta-*) to AWS v4 signed requests for GCS S3-compatible API. Use when: (1) Adding custom metadata to GCS uploads via S3 API, (2) Getting signature mismatch errors after adding new headers, (3) x-amz-meta-* headers being ignored or causing 403 errors. Custom headers MUST be included in canonical headers and signed headers list.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2652026년 10월 21일 업데이트

Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings. Use when: (1) Password authentication fails with correct password, (2) Secret created with `<<< "value"` syntax, (3) Error like "password authentication failed" or "invalid token" despite correct value. Bash here-strings (`<<<`) add a trailing newline that corrupts secrets.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2652026년 10월 21일 업데이트

Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp). Use when: (1) Media moderation, transcoding, or analysis silently skips files from Blossom or content-addressed storage servers, (2) URL extraction from Nostr event tags (imeta, r tags) drops URLs without recognized extensions, (3) CDN fallback URLs append .mp4 but the actual server uses extensionless content-addressed paths like /{sha256}. Common in Nostr video events (kind 34236) where different clients use different URL formats.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2652026년 10월 21일 업데이트

divinevideo의 스킬 모두 보기

이 스킬의 문제 신고