I am doing pg_dump using -
pg_dump -U <username> -h <host> <database> > backup.sql
pg_dump is working fine. I am trying to do pg_restore doing -
pg_restore -U <username> -h <host> -d <databse> backup.sql
Then it is showing pg_restore: error: input file does not appear to be a valid archive
I have checked many StackOverflow answers about this, but I could not figure out anything. Please help me. Thanks in advance.
Update : As per comments we can not use pg_restore for .sql files. Actually I have an restriction that I must have to restore the database using pg_restore command. Can you please give the pg_dump command using which I can restore that using pg_restore?
You created a plain format dump, which is an SQL file. You have to restore plain-format dumps with psql
:
psql -U <username> -h <host> -d <databse> -f backup.sql
pg_restore
is used to restore dumps in all other formats. You get dumps in other formats by using the appropriate -F
option with pg_dump
: for example, -F c
produces a custom format dump.
If you want to restore a plain format dump with a client other than psql
, you have to create it with the option --inserts
.