Search code examples
postgresqlpostgresql-11

PostgreSQL pg_basebackup missing toc.dat header file


I'm using the following command to backup my database (PostgreSQL 11.8):

pg_basebackup -D "C:\\temp" -F tar -X f -z -P -U myUser

And the following to restore:

  1. I manually unpack the base.tar.gz => base.tar
  2. pg_restore -h localhost -W -U myUser -c -C -d myDatabase -F tar -v "C:\\temp\\base.tar"

This results in the following error:

pg_restore: [tar archiver] could not find header for file "toc.dat" in tar archive

What am I doing wrong? Also, I tried different versions of the restore (only data, etc.) but of course the missing header file issue persists.

Thanks for your help!


Solution

  • You cannot use pg_basebackup and pg_restore together:

    • pg_basebackup is a physical backup tool
    • pg_restore can only be used with a logical backup created by pg_dump.

    There is no single PostgreSQL command to restore a backup created with pg_basebackup.

    To restore a physical backup see https://www.postgresql.org/docs/12/continuous-archiving.html#BACKUP-PITR-RECOVERY