【发布时间】:2021-10-26 15:02:10
【问题描述】:
我正在尝试使用以下命令将数据库导入 postgres:
"C:\Program Files\PostgreSQL\9.5\bin\pg_restore.exe" --dbname=postgres --clean --create --format=d --jobs=16 --no-tablespaces --host=localhost --username=postgres "S:\Directory-Dump_Inn"
精美的手册说:
--无表空间
不要输出命令来选择表空间。使用此选项,所有对象都将在还原期间的默认表空间中创建。
我认为这意味着我不必创建转储来源的表空间。由于导入失败
ERROR: tablespace "ts_inn" does not exist
我猜,这个假设是错误的。那么手册中的解释是什么意思呢? 如果我事先创建表空间,导入工作正常。
编辑:导入服务器版本为 9.5.4,导出服务器版本为 9.6.3。可能导出命令也很重要:
"C:\Program Files\PostgreSQL\9.6\bin\pg_dump.exe" --host localhost --port 5432 --username "postgres" --no-password --format directory --section pre-data --section data --section post-data --compress 0 --jobs 4 --verbose --file "F:\Postgres-Backup\Directory-Dump_Inn" "inn" 2>> %logfile%
是导出省略--no-tablespaces的罪魁祸首吗?如果是这样并且如果我将--no-tablespaces 添加为pg_dump 的参数,那么我为什么要在导入过程中使用--no-tablespaces?显然,转储文件中不会有任何CREATE TABLESPACE xxx。
【问题讨论】:
-
尽管
--no-tablespaces不导出CREATE TABLESPACE的命令,选项tablespace仍然在被导出的数据库对象中声明,这就是导入时错误的来源它在没有那个表空间的数据库中。 -
那么什么时候会使用
--no-tablespaces? -
我已经“解释”了你所说的行为,但我没有提到这可能是一个错误,你应该将你的 Postgres 安装升级到 9.5 稳定版本,看看错误是否继续。
标签: postgresql