【问题标题】:pg_restore fails with missing tablespace eventhough --no-tablespaces is givenpg_restore 因缺少表空间而失败,尽管给出了 --no-tablespaces
【发布时间】: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


【解决方案1】:

在 2016 年 9 月的 this 提交以修复 bug #14315 修复了与您非常相似的问题,因此请确保您拥有 PostgreSQL 9.5 或更高版本的最新补丁。

但即使有了这些补丁,您的示例也会失败,因为您没有将 --no-tablespaces 添加到 pg_dump 的调用中。

这有点令人惊讶,但是要在转储中抑制CREATE DATABASE 的TABLESPACE 子句,调用pg_restore --no-tablespaces 是不够的。必须使用该选项创建转储。

【讨论】:

  • 对于 Postgres 版本,请参阅更新后的问题。但即使在 Windows 下下载(并使用)最新的 10.0 x64 后,结果仍然保持不变。您提供的链接是针对 pg_dump 的:我的假设是否正确,我必须 pg_dump 和 --no-tablespaces (见编辑的问题)?
  • 是这样的:当使用普通转储(-Fp)时,插入有问题的语句是pg_dump。使用自定义格式 (-Fc) 时,是 pg_restore 执行此操作。所以你必须更新导入服务器的版本。
  • 我不确定目录转储属于普通类别还是自定义类别。所以我再次尝试使用我的问题中描述的两个命令从 Postgres 10 回到 Postgres 10 - 结果相同:"C:\Program Files\PostgreSQL\10\bin\pg_restore.exe" --dbname=postgres --create --format=d --jobs=16 --no-tablespaces --host=localhost --username=postgres G:\Postgres-Backup\Directory-Dump_Inn ... pg_restore: [Archivierer (DB)] could not execute query: FEHLER: Tablespace »ts_inn« existiert nicht
  • 这太令人惊讶了;它在这里工作(即使是目录格式)。在没有目标数据库的情况下执行pg_restore --no-tablespaces 以获取 SQL 脚本并找出其中包含表空间的命令是什么。
  • "C:\Program Files\PostgreSQL\10\bin\pg_restore.exe" --file=G:\Postgres-Backup\skript_inn.sql --schema-only --create --format=d --jobs=16 --no-tablespaces --host=localhost --username=postgres G:\Postgres-Backup\Directory-Dump_Inn 导致:-- PostgreSQL database dump -- Dumped from database version 10.0 -- Dumped by pg_dump version 10.0 ... CREATE DATABASE inn WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'German_Germany.1252' LC_CTYPE = 'German_Germany.1252' TABLESPACE = ts_inn; 抱歉格式丑陋...
猜你喜欢
  • 2015-09-27
  • 2021-01-17
  • 2019-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-23
  • 1970-01-01
  • 2014-08-10
相关资源
最近更新 更多