postgresql pg_restore 会覆盖现有的表吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43603192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:33:19  来源:igfitidea点击:

will pg_restore overwrite the existing tables?

postgresqlpsqlpostgresql-9.5pg-dumppg-restore

提问by Karthik

Say I have two host servers s1 and s2. In both the servers i have a schema named n1, now i have made some changes to some of the tables present in schema n1 of s1. I want the same change to be done to schema n1 of server s2. what i am planning to do is to take a backup of the schema n1 of server s1 using pg_dump and restore in the server s2 using pg_restore. Now my question is ,since there is already the same schema n1 in the server s2 with the same set of tables. what the restore process will do? will it overwrite the existing tables or should i drop the existing schema of server s2 and restore it using the dump from server s1?

假设我有两个主机服务器 s1 和 s2。在两台服务器中,我都有一个名为 n1 的模式,现在我对 s1 的模式 n1 中存在的一些表进行了一些更改。我希望对服务器 s2 的架构 n1 进行相同的更改。我打算做的是使用 pg_dump 备份服务器 s1 的架构 n1,并使用 pg_restore 在服务器 s2 中恢复。现在我的问题是,因为在具有相同表集的服务器 s2 中已经存在相同的架构 n1。恢复过程会做什么?它会覆盖现有的表还是应该删除服务器 s2 的现有架构并使用服务器 s1 的转储来恢复它?

回答by Laurenz Albe

If you use the --cleanoption of pg_restore, the old tables will be dropped before the new ones are created.

如果使用--clean选项pg_restore,则在创建新表之前将删除旧表。

If you do not use the --cleanoption, you will get an error message that the table already exists, but pg_restorewill continue processing unless you use the --exit-on-erroroption.

如果您不使用该--clean选项,您将收到一条错误消息,指出该表已存在,但pg_restore除非您使用该--exit-on-error选项,否则将继续处理。