需要一些关于在 pg_restore 期间删除数据库的说明

问题描述 投票:0回答:1

当使用带有 clean 选项的 pg_dump 时,它会生成专门用于在使用 pg_restore 恢复时删除对象的 SQL 语句(pg_dump 自定义格式文件包含“DROP DATABASE”)。如果 pg_dump 不包含 clean,但 pg_restore 包含,那么会产生什么影响? pg_upgrade 同时使用 pg_dump 和 pg_restore。我在转储文件中遇到了删除 postgres 数据库的 SQL 命令。

这些是来自pg_dump源文件的注释;

We assume that "template1" and "postgres" already exist in the target installation.  dropDBs() won't have removed them, for fear of removing the DB the restore script is initially connected to. If --clean was specified, tell pg_dump to drop and recreate them; otherwise we'll merely restore their contents.  Other databases should simply be created.

我不确定在此类操作期间对 template1 的处理。由于 template0 并不用于数据连接并且不会被删除,因此该过程如何处理 template1,特别是考虑到 pg_restore 通常使用 template1 连接。 如果 pg_restore 在连接到 template1 时尝试删除 template1,可能会出现问题。

postgresql pg-dump pg-restore pg-upgrade pg-dumpall
1个回答
0
投票

--create
--clean
pg_dump
选项仅在纯格式下有效。对于自定义格式转储,它们没有任何作用。您与
pg_restore
一起使用的选项会影响发生的情况。

© www.soinside.com 2019 - 2024. All rights reserved.