向Citus迁移
Citus数据迁移
小型数据库迁移
对于可以容忍一点停机时间的小型环境,请使用简单的pg_dump / pg_restore进程。
- 从开发数据库中保存数据库结构:
pg_dump \
--format = plain \
--no-owner \
--schema-only \
--file = schema.sql \
--schema = target_schema \
postgres:// user:pass @ host :5432 / db
- 使用psql连接到Citus集群并创建响应结构:
i schema.sql
- 运行create_distributed_table和create_reference_table语句。如果您收到有关外键的错误,通常是由于操作顺序。在分发表之前删除外键,然后重新添加它们。
-
将应用程序置于维护模式,并禁用对旧数据库的任何其他写入。
-
使用pg_dump将原始生产数据库中的数据保存到磁盘:
pg_dump \
--format = custom \
--no-owner \
--data-only \
--file = data.dump \
--schema = target_schema \
postgres:// user:pass @ host :5432 / db
- 使用pg_restore导入Citus:
pg_restore \
--host = host \
--dbname = dbname \
--username = username \
data.dump
-
测试应用。
-
迁移完成,启动应用
大型数据库迁移
大型数据库通常有不停机的需求。
大于9.4版本不停机迁移需将4.5.6步骤更改成逻辑复制(PG10以上自带的逻辑复制不可以)的方式。
小于9.4版本不停机迁移需将4.5.6步骤更改成Slony复制的方式。
[CitusDB中国]站主,PostgreSQL粉丝,现从事Citus研发工作
愿Citus在中国发展的越来越好