简体   繁体   中英

How to use pg_dump/pg_restore to update database?

Say I have db0 on the local machine and db1 on a remote server. I just want to keep db1 up-to-date with db0 .

Say I added few (thousands) rows to my_table in db0 and now I want to insert it to my_table in db1 .

All the recipes and docs about pg_dump/pg_restore say about full restoration of the table, however, I don't need (and don't want) to drop and to restore my_table from scratch.

Is there any clear and simple way to make a file, scp it to the server and just pg_restore from it?

Just two commands: for pg_dump and for pg_restore. Because I'm looking through docs and walkthroughs for about two hours getting new errors and becoming confused more and more.

You will have to use a statement like INSERT ... ON CONFLICT DO NOTHING or MERGE (which will probably come in v12), but that requires that you have access to both tables at the same time.

So you either have to use a foreign table or dump/restore the table into a different table in the destination database.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM