pg_dump and pg_restore: input file does not appear to be a valid archive

Solution 1:

You are dumping in plain SQL format which was designed to feed to psql. This is not recognized by pg_restore.

cat db.txt | psql dbname

Should do the trick

Solution 2:

pg_dump by default creates the sql commmands necessary to recreate the data. To recover it, you just need to invoke psql (not pg_restore ) with the file as input . pg_restore is only to be used for the binary (not default, and less usual not recommended) format of pg_dump. Read the docs.

Update: The pg_dump binary formats (-Fc -Ft) that are to be used with pg_restore are ok, and offer some extra flexibility. But they are less standard (non SQL), less apt for importing from some tools (eg. a php frontend) or manipulate with a text editor, and a little less portable to other versions and even other databases. For backups, I'd stick with the default plain format. For other scenarios, the binary + pg_restore option can be equally or more apt.

The point to keep is that in Postgresql, in the typical scenario, the backup normally is done by pg_dump (plain) and the restore with the standard command line client (psql).


Solution 3:

Try passing the --format=c option to pg_dump. This will allow pg_restore to restore it.


Solution 4:

This is what I would do to backup my old database and restore

To back up your database

pg_dump --format=c olddb_name > db_dump_file.dump

To restore that backup

pg_restore -v -d newdb_name db_dump_file.dump

Read more on pg_dump and pg_restore


Solution 5:

For windows users try

type db.txt | psql --username="YOURNAME" dbname

Works like a charm

Tags:

Postgresql