我试图恢复我的转储文件,但它导致了一个错误:
psql:psit.sql:27485: invalid command \N
有解决办法吗?我找了,但没有得到明确的答案。
我试图恢复我的转储文件,但它导致了一个错误:
psql:psit.sql:27485: invalid command \N
有解决办法吗?我找了,但没有得到明确的答案。
当前回答
我的解决办法是:
psql -U your_user your_db < your.file.here.sql 2>&1|more
这样我就可以读取错误消息
我希望这能对大家有所帮助。
其他回答
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.
检查表中的列和备份文件中的列是否合适
当我试图从二进制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
对于我在SUSE 12上使用postgreSQL 10,我通过增加磁盘空间解决了无效命令\N错误。磁盘空间不足导致了我的错误。如果查看df -h输出中数据将要进入的文件系统,就可以判断是否耗尽了磁盘空间。如果文件系统/mount的使用率为100%,在执行类似psql -f db. mount的操作后。对于postgres(请参阅https://www.postgresql.org/docs/current/static/app-pg-dumpall.html),您可能需要增加可用的磁盘空间。
今天我也遇到了同样的事。我通过使用——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导入之前,不要忘记创建具有完全相同名称和列的表。