psql invalid command \N while restore sql
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.
Solution 1:
Postgres uses \N
as substitute symbol for NULL value. But all psql commands start with a backslash \
symbol. You can get these messages, when a copy statement fails, but the loading of dump continues. This message is a false alarm. You have to search all lines prior to this error if you want to see the real reason why COPY statement failed.
Is possible to switch psql to "stop on first error" mode and to find error:
psql -v ON_ERROR_STOP=1
Solution 2:
I received the same error message when trying to restore from a binary pg_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
Solution 3:
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