psql invalid command \N while restore sql

2019-01-13 09:02发布

I'm trying to restore my dump file, but it caused an error:

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

Is there a solution? I searched, but I didn't get a clear answer.

10条回答
混吃等死
2楼-- · 2019-01-13 09:27

I go the same error message when trying to restore from a binary dump. I simply used pg_restore to restore my dump and completely avoid the \N errors, e.g.

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

Explanation of switches:

-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

查看更多
可以哭但决不认输i
3楼-- · 2019-01-13 09:29

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.

查看更多
地球回转人心会变
4楼-- · 2019-01-13 09:37

Most times, the solution is to install postgres-contrib package.

查看更多
Fickle 薄情
5楼-- · 2019-01-13 09:39

You can generate your dump using INSERTS statements, with the --inserts parameter.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-13 09:43

Install postgresql-(your version)-postgis-scripts

查看更多
再贱就再见
7楼-- · 2019-01-13 09:44

I know this is an old post but I came across another solution : postgis wasn't installed on my new version, which caused me the same error on pg_dump

查看更多
登录 后发表回答