[英]How do I clone an entire database from one Postgres instance, to become a part of a database hosted on a different instance?
I have a PostgreSQL instance A
with 10 tables, and another instance B
hosted on a different box, which contains the same 10 tables but also many others.我有一个 PostgreSQL 实例A
有 10 个表,另一个实例B
托管在不同的盒子上,它包含相同的 10 个表,但还有许多其他的。 I'd like to clone all 10 tables from the small database A
to overwrite their equivalents in the larger database B
.我想从小型数据库A
克隆所有 10 个表以覆盖它们在较大数据库B
的等价物。 What's a good way to do this?有什么好方法可以做到这一点?
One path I'm considering is to do a full pg_dump
of A
, copy that dump file to B
's host, then pg_restore
it into B
.我正在考虑的一种方法是对A
进行完整的pg_dump
,将该转储文件复制到B
的主机,然后pg_restore
到B
。 It seems like it should work since I do want every single table on A
to overwrite the table of the same name on B
, but I'm just a bit nervous doing a pg_restore
of a full database dump, and I'm also not very familiar with pg_dump
and pg_restore
so it would be great to have that plan validated by someone more knowledgeable.似乎它应该可以工作,因为我确实希望A
上A
每个表都覆盖B
上的同名表,但是我在执行完整数据库转储的pg_restore
时有点紧张,而且我也不是很熟悉pg_dump
和pg_restore
因此该计划最好由更有知识的人验证。
You can use a plain format pg_dump
with the --clean
option and specify the tables you want to dump with -t
.您可以使用带有--clean
选项的纯格式pg_dump
并使用-t
指定要转储的表。
Then you get an SQL script that contains only the tables you want replaced, and each table is preceeded with a DROP TABLE
.然后你会得到一个只包含你想要替换的表的 SQL 脚本,每个表前面都有一个DROP TABLE
。
You can check the script before using it.您可以在使用之前检查脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.