当使用带有 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,可能会出现问题。
--create
的--clean
和pg_dump
选项仅在纯格式下有效。对于自定义格式转储,它们没有任何作用。您与 pg_restore
一起使用的选项会影响发生的情况。