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

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

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


当前回答

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

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

其他回答

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

当我试图从二进制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

In my recent experience, it's possible to get this error when the real problem has nothing to do with escape characters or newlines. In my case, I had created a dump from database A with pg_dump -a -t table_name > dump.sql and was trying to restore it to database B with psql < dump.sql (after updating the proper env vars, of course) What I finally figured out was that the dump, though it was data-only (the -a option, so that the table structure isn't explicitly part of the dump), was schema-specific. That meant that without manually modifying the dump, I couldn't use a dump generated from schema1.table_name to populate schema2.table_name. Manually modifying the dump was easy, the schema is specified in the first 15 lines or so.

我遵循了所有这些例子,它们都失败了,出现了我们正在谈论的错误:

在Postgres中将一个表从一个数据库复制到另一个数据库

有效的是使用-C的语法,请看这里:

pg_dump -C -t tableName "postgres://$User:$Password@$Host:$Port/$DBName" | psql "postgres://$User:$Password@$Host:$Port/$DBName"

此外,如果两者之间有不同的模式,我发现改变一个dB的模式以匹配其他的表副本是必要的,例如:

DROP SCHEMA public;
ALTER SCHEMA originalDBSchema RENAME TO public;

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