Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

pg_restore refuses a dump file as not a valid archive

Errorpg_restore: [archiver] input file does not appear to be a valid archive

Short answer

pg_restore only reads archives made by pg_dump in custom, tar or directory format. A plain-text SQL dump, which is pg_dump's default, or a gzip file of one, is not an archive. Check how the dump was made, then restore a plain dump with psql and a compressed one through gunzip into psql.

  • Applies to PostgreSQL 17, PostgreSQL 18
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look at the file before restoring it. A plain dump is readable SQL; a gzip file is compressed bytes.

    file backup.dump
    head -c 200 backup.dump
  2. 2Match what you see, then jump to its fix

    1. 1head shows readable SQL such as SET statements and CREATE TABLE, and the dump was taken without -FThe dump is plain-text SQL, not an archiveFix
    2. 2file reports gzip compressed data, and the name ends in .gzThe file was compressed by gzip after dumpingFix
    3. 3pg_dump was run with -Fd and -f dirname, and the restore command points at a file inside it or at a different pathA directory-format dump was given as a single file path, or the wrong pathFix

What does the error look like?

  • pg_restore: [archiver] input file does not appear to be a valid archive

Cause 1 of 3

The dump is plain-text SQL, not an archive

1Check

pg_dump writes a plain-text SQL script unless you pass a format option. pg_restore does not handle that format.

head -n 20 backup.sql

2Fix

Feed the script to psql instead. Create the target database first from template0; the script does not create it.

createdb -T template0 newdb
psql -X -d newdb -f backup.sql

3Verify

psql finishes without errors, and the tables exist.

psql -d newdb -c '\dt'

Confirmed by postgresql.org

Did this fix it?

Cause 2 of 3

The file was compressed by gzip after dumping

1Check

Dumps piped through gzip are compressed copies of a plain script. They are not a pg_dump archive either.

file backup.sql.gz

2Fix

Decompress it into psql in one pipe. If the dump is meant for pg_restore, take it again with pg_dump -Fc.

gunzip -c backup.sql.gz | psql -X -d newdb
# next time, for pg_restore:
pg_dump -Fc dbname > backup.dump

3Verify

Restore a custom dump with pg_restore and list its table of contents to see it is accepted.

pg_restore -l backup.dump
pg_restore -d newdb backup.dump

Confirmed by postgresql.org

Did this fix it?

Cause 3 of 3

A directory-format dump was given as a single file path, or the wrong path

1Check

With directory format, pg_dump creates a directory and its path is what pg_restore needs. The directory must not exist before the dump.

ls -l backup_dir

2Fix

Point pg_restore at the directory itself and name the format.

pg_restore -Fd -d newdb backup_dir

3Verify

The listing prints without the archive error.

pg_restore -l backup_dir | head

Confirmed by postgresql.org

Did this fix it?

How do I stop it coming back?

  • Name dumps by format: .sql for plain, .dump for custom, a folder name for directory.
  • Use pg_dump -Fc when you want pg_restore, selective restore and compression.
  • Run pg_restore -l on every backup file as a quick check after the dump finishes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.