Fix pg_restore Error: Expected Format Differs from Found Format


The pg_dump -Fd mydb -f mydb.dump command creates a mydb.dump directory with a toc.dat file. The pg_dump man page mentions that pg_restore is able to read this file, but after skimming its man page and stumbling upon this PostgreSQL mailing list thread, I get this cryptic error:

$ pg_restore -l mydb.dump/toc.dat

pg_restore: error: expected format (1) differs from format found in file (3)

Best Answer

TL;DR pg_restore expects the a directory when reading from directory dumps:

pg_restore -l <dump_directory_name>

So, in the case above, it is pg_restore -l mydb.dump.

After a more careful reading of the pg_restore man page, I found the -F option:

-F format
Specify format of the archive. It is not necessary to specify the format, since pg_restore will determine the format automatically. If specified, it can be one of the following: (c custom, d directory, t tar)

So I tried pg_restore -l mydb.dump/toc.dat -Fd next; the result:

pg_restore: error: could not open input file "mydb.dump/toc.dat/toc.dat": Not a directory

Then pg_restore -l mydb.dump -Fd, which worked, so I gave it try deleting -Fd from the end, which also did.

update: Could have avoided this experimentation if I had actually paid attention to the man page (emphasis mine):


pg_restore accepts the following command line arguments.

Specifies the location of the archive file (or directory, for a directory-format archive) to be restored. If not specified, the standard input is used.