1. Home
  2. Knowledge Base
  3. Convert MergeTree to Replicated In ClickHouse

Convert MergeTree to Replicated In ClickHouse

To convert a MergeTree table to a Replicated table in ClickHouse, you can use the ALTER TABLE statement with the ENGINE clause. Here is an example:

ALTER TABLE original_table
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/{table}', '{replica}')
ORDER BY (primary_key_column)

In this example, original_table is the name of the table you want to convert, primary_key_column is the name of the column that serves as the primary key for the table, and replica is the name of the replica you want to use for the Replicated table. The path /clickhouse/tables/{database}/{table} is the place where clickhouse store the table.

Note: This is an online process.

You can also use PARTITION BY clause if your table is partitioned.

ALTER TABLE original_table
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/{table}', '{replica}')
PARTITION BY partition_column
ORDER BY (primary_key_column)

It is also important to note that if you are converting a table to a Replicated table, you should also have a cluster of clickhouse servers setup to handle the replication.

Was this article helpful?

CHISTADATA IS COMMITTED TO OPEN SOURCE SOFTWARE AND BUILDING HIGH PERFORMANCE COLUMNSTORES

In the spirit of freedom, independence and innovation. ChistaDATA Corporation is not affiliated with ClickHouse Corporation 

Need Support?

Can't find the answer you're looking for?
Contact Support

ChistaDATA Inc. Knowledge base is licensed under the Apache License, Version 2.0 (the “License”)

Copyright 2022 ChistaDATA Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.