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

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

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


当前回答

安装postgresql-(你的版本)-postgis-scripts

其他回答

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

对我来说,与源数据库不同的是ENCODING和LOCALE。 一旦我放弃了目标DB并重新创建它,它就可以正常工作。

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.

当我试图从二进制pg_dump恢复时,我收到了相同的错误消息。我简单地使用pg_restore来恢复我的转储,并完全避免\N错误,例如。

pg_restore -c -F t -F your.backup.tar

开关说明:

-f, --file=FILENAME      output file name
-F, --format=c|d|t       backup file format (should be automatic)
-c, --clean              clean (drop) database objects before recreating

今天我也遇到了同样的事。我通过使用——inserts命令转储来处理问题。

我所做的是:

1) pg_dump插入:

pg_dump dbname --username=usernamehere --password --no-owner --no-privileges --data-only --inserts -t 'schema."Table"' > filename.sql

2) PSQL(恢复转储文件)

psql "dbname=dbnamehere options=--search_path=schemaname" --host hostnamehere --username=usernamehere -f filename.sql >& outputfile.txt

注意1)确保添加outputfile可以提高导入的速度。

注2)在用psql导入之前,不要忘记创建具有完全相同名称和列的表。