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. I'd like to clone all 10 tables from the small database A
to overwrite their equivalents in the larger database 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
. 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.
You can use a plain format pg_dump
with the --clean
option and specify the tables you want to dump with -t
.
Then you get an SQL script that contains only the tables you want replaced, and each table is preceeded with a DROP TABLE
.
You can check the script before using it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.