ワンクリックで
migration-patterns
// Schema migrations: ALTER patterns, engine changes, zero-downtime swaps, clickhouse-local offline migrations, and lightweight UPDATE/DELETE strategies.
// Schema migrations: ALTER patterns, engine changes, zero-downtime swaps, clickhouse-local offline migrations, and lightweight UPDATE/DELETE strategies.
| name | migration-patterns |
| description | Schema migrations: ALTER patterns, engine changes, zero-downtime swaps, clickhouse-local offline migrations, and lightweight UPDATE/DELETE strategies. |
ALTER TABLE t ADD COLUMN col Type [DEFAULT expr] [AFTER existing_col]ALTER TABLE t DROP COLUMN colALTER TABLE t MODIFY COLUMN col NewType (must be compatible)ALTER TABLE t RENAME COLUMN old TO newCREATE TABLE t_new ENGINE = ReplacingMergeTree() ORDER BY id AS SELECT * FROM t_old;
RENAME TABLE t_old TO t_backup, t_new TO t_old;
INSERT INTO ... SELECT with batchingEXCHANGE TABLES t_old AND t_newRENAME TABLE t_old TO t_backup, t_new TO t_oldCREATE MATERIALIZED VIEW mv TO t_new AS SELECT ... FROM t_oldINSERT INTO t_new SELECT ... FROM t_oldINSERT INTO new SELECT * FROM old WHERE toYYYYMM(date) = 202301max_insert_block_size and max_threads for throughput controlsystem.processes and system.mergesALTER TABLE t UPDATE col = expr WHERE condition — async by default (mutations_sync = 0)SELECT * FROM system.mutations WHERE table = 't'ALTER TABLE t DELETE WHERE condition — rewrites affected partsmax_rows_per_mutation to limit rows per mutation batchsystem.mutations for completionremote() table function to copy between servers:INSERT INTO local_db.t SELECT * FROM remote('source_host:9000', 'db', 't', 'user', 'pass')
clickhouse-local offline approachclickhouse-local --file migration.sqlclickhouse-local -S 'col1 Type1, col2 Type2' --input-format Native < data.binCREATE TABLE _schema_migrations (name String, applied_at DateTime DEFAULT now()) ENGINE = TinyLog;
ALTER TABLE t ATTACH PARTITION id FROM other_table — zero-copy if same structureALTER TABLE t REPLACE PARTITION id FROM other_table — atomic swapALTER TABLE t MOVE PARTITION id TO TABLE other_table — move dataEXCHANGE TABLES fails if either table is replicated with different replica pathsExact column names for the system tables the agent queries most (processes, query_log, parts, merges, mutations, replicas, replication_queue, disks, settings, zookeeper, users/grants, metrics) plus rules for choosing dedicated tools over raw SQL. Load before hand-writing SQL against system tables.
Cluster management: distributed tables, ON CLUSTER DDL, node lifecycle, resharding, load balancing, and Keeper migration.
ReplicatedMergeTree operations, failover procedures, lag diagnosis, quorum writes, and Keeper management.
RBAC configuration, row policies, quotas, network security, audit logging, and access control best practices.
Compression codecs, TTL policies, tiered storage, part management, and disk space optimization.
Production operational practices: insert batching, async writes, query cache, connection pooling, and recommended settings.