我试图恢复我的转储文件,但它导致了一个错误:

psql:psit.sql:27485: invalid command \N

有解决办法吗?我找了,但没有得到明确的答案。


当前回答

检查表中的列和备份文件中的列是否合适

其他回答

Adding my resolution, incase it helps anyone. I installed postgis but the error wasn't resolved. The --inserts option was not feasible as I had to copy a big schema having tables with thousands of rows. For the same database I didn't see this issue when pg_dump and psql (restore) were run on mac. But the issue came when pg_dump was run on linux machine, the dump file copied to mac and tried for restore. So I opened the dump file in VSCode. It detected unusual line terminators and gave option to remove them. After doing that the dump file restore ran without the invalid command \N errors.

可以使用INSERTS语句和——INSERTS参数生成转储。

Postgres使用\N作为NULL值的替代符号。但是所有psql命令都以反斜杠\符号开始。当复制语句失败,但转储的加载仍在继续时,您可以获得这些消息。这条消息是假警报。如果希望看到COPY语句失败的真正原因,则必须搜索此错误之前的所有行。

可以切换psql到“第一个错误停止”模式,并找到错误:

psql -v ON_ERROR_STOP=1

我有同样的问题,我创建了一个新的数据库,并得到无效的命令\N恢复与psql。 我通过设置与旧数据库相同的表空间来解决这个问题。

例如,旧数据库备份有表空间“pg_default”,我给新数据库定义了相同的表空间,上面的错误已经消失了!

在我的例子中,问题是在我的目标计算机上缺少磁盘空间。简单地增加本地存储为我解决了它。

希望这能帮助到一些人;)