psql invalid command \N while restore sql

前端 未结 14 860
后悔当初
后悔当初 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:39

    I had the same problem, I created a new database and got invalid command \N on restore with psql. I solved it by setting the same tablespace with the old database.

    For example, old database backup had tablespace "pg_default", I defined the same tablespace to the new database, and the above error has gone!

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

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

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

    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
    
    0 讨论(0)
  • 2020-12-04 16:44

    For me using postgreSQL 10 on SUSE 12, I resolved the invalid command \N error by increasing disk space. Lack of disk space was causing the error for me. You can tell if you are out of disk space if you look at the file system your data is going to in the df -h output. If file system/mount is at 100% used, after doing something like psql -f db.out postgres (see https://www.postgresql.org/docs/current/static/app-pg-dumpall.html) you likely need to increase the disk space available.

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

    I have run into this error in the past as well. Pavel is correct, it is usually a sign that something in the script created by pg_restore is failing. Because of all the "/N" errors, you aren't seeing the real problem at the very top of the output. I suggest:

    1. inserting a single, small table (e.g., pg_restore --table=orders full_database.dump > orders.dump )
    2. if you don't have a small one, then delete a bunch of records out of the restore script - I just made sure the ./ was the last row to be loaded (e.g., open orders.dump and delete a bunch of records)
    3. watch the standard output, and once you find the problem, you can always drop the table and reload

    In my case, I didn't have the "hstore" extension installed yet, so the script was failing at the very top. I installed hstore on the destination database, and I was back in business.

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

    My solution was this:

    psql -U your_user your_db < your.file.here.sql  2>&1|more
    

    this way I could read the error message

    I hope this helps anybody.

    0 讨论(0)
提交回复
热议问题