Restoring from Postgres sql file

2019-03-04 12:46发布

问题:

I have a backup from PostgresSQL database created this way:

/usr/bin/pg_dump --no-owner --no-acl > dump.sql

When I try to restore on a different machine:

psql db < dump.sql it trows many errors: invalid command \N

When I try to use pg_restore:

pg_restore dump.sql -d db

Different error: pg_restore: [archiver] input file appears to be a text format dump. Please use psql.

According to documentation this should be a non issue.

Any way to tell psql that \N character is a null value?

回答1:

Oh hi me, it's me

Make sure:

  • Database exists
  • Importing user has permissions
  • Get the first error before \N ones flood in
  • psql -d database -f backup.sql -U user should do the trick for importing

Also eat healthy and get good rest. k bye