简体   繁体   English

如何从一个 Postgres 实例克隆整个数据库,成为托管在不同实例上的数据库的一部分?

[英]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_restoreB 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.似乎它应该可以工作,因为我确实希望AA每个表都覆盖B上的同名表,但是我在执行完整数据库转储的pg_restore时有点紧张,而且我也不是很熟悉pg_dumppg_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.

相关问题 如何在Android中存储数据库实例,以使其不为null? - How to store database instance in Android so that it doesnt become null? 由于 1 个数据库上的锁定问题,具有多个数据库的 Postgres 实例是否会在多个/所有数据库中被阻止? - Can a Postgres instance with many Databases become blocked across many/all Databases due to a Locking issue on 1 Database? 如何使用Room创建数据库的新实例? - How do I create a new instance of a database using Room? 远程Postgres数据库Heroku连接因Digital Ocean实例而变慢 - Remote Postgres Database Heroku Connection is slow from Digital Ocean Instance 如何使用express保留一个数据库实例 - How to keep one instance of the database using express 使用SP克隆整个数据库 - Clone entire database with a SP 如何从数据库中删除整行 - How do I delete an entire row from a database 如何将我必须拥有的两个.MDF文件中的数据库数据合并到一个实例中,而我想将所有内容都合并到一个实例中 - How to combine the database data from two .MDF files I have to instances and I would like to have everything in one instance 如何更改Postgres的维护数据库? - How do I change the maintenance database for Postgres? 如何从 Room 数据库中获取 SQLite 数据库实例引用? - How to get the SQLite database instance reference from the Room database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM