如何将 postgreSQL 模式转储恢复到具有不同名称的模式

Nux*_*Nux 6 postgresql pg-dump

我知道我可以在恢复后更改架构名称,但问题是名称可能已经存在,我不想触及现有架构。

转储类型是“自定义”。

如此有效地我想要这样的东西:

pg_dump -U postgres --schema "source_schema" --format "c" --create --file "source_schema.bak" my_db
pg_restore -U postgres --exit-on-error --dbname "my_db" "source_schema.bak" --destination-schema "destination_schema"
Run Code Online (Sandbox Code Playgroud)

如果可能的话,如果我可以在备份之前复制(和重命名)源模式就好了。

jja*_*nes 5

如果数据很小,我会做 pg_dump,将它恢复到一个临时的专用数据库服务器,重命名该临时服务器 ( ALTER SCHEMA...RENAME...) 中的架构,然后将它从该临时服务器中转储出来做最后的恢复。