pg_restore: error: corrupt tar header found in PGDMP

bash-4.2$ pg_restore -U appmdm-Ft -d test < test.tar
pg_restore: error: corrupt tar header found in PGDMP (expected 0, computed 18703) file position 512

The above error occurred while importing the test database using pg_restore command.

pg_dump was taken in .tar format using below command.

bash-4.2$ pg_restore -U appmdm -Ft -d test < test.tar
Here, -F is format and t is tar.

To overcome this issue, we checked few blogs where it was mentioned this as a bug. I tried to extract it and see the contents of tar file but seems it is not recognized as a tar file.

bash-4.2$ tar -tvf test.tar
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

bash-4.2$ tar -xvf test.tar
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

To fix it, when I change the extension of dumpfile as .dump it worked, and we didn’t face any issues while pg_restore.

bash-4.2$ pg_restore -U appmdm -Fc -d test < test.dump --verbose 2>test_restore12oct2019.log
Here, -Fc is custom format.