psql invalid command \N while restore sql

前端 未结 14 858
后悔当初
后悔当初 2020-12-04 15:54

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

相关标签:
14条回答
  • 2020-12-04 16:28

    I followed all these example's and they all failed with the error we are talking about:

    Copy a table from one database to another in Postgres

    What worked was the syntax with -C, see here:

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

    Also if there are differing Schema's between the two, I find altering one dB's schema to match the others is necessary for Table copies to work, eg:

    DROP SCHEMA public;
    ALTER SCHEMA originalDBSchema RENAME TO public;
    
    0 讨论(0)
  • 2020-12-04 16:29

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

    0 讨论(0)
  • 2020-12-04 16:35

    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

    0 讨论(0)
  • 2020-12-04 16:38

    Install postgresql-(your version)-postgis-scripts

    0 讨论(0)
  • 2020-12-04 16:38

    For me it was the ENCODING and LOCALE that differ from the source database. Once I dropped the target DB and recreated it it was working fine.

    0 讨论(0)
  • 2020-12-04 16:39

    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
    
    0 讨论(0)
提交回复
热议问题