Postgresql – Error while restoring Postgres DB Dump

errorspostgresqlpostgresql-9.1restore

Using below command to restore the database

Restoration command:

cat my_db_dump.sql.gz | gunzip | psql -d new_database -U my_username

Note: my_db_dump.sql.gz size is 4.5 GB, (extracted size will be around 70 GB)

Getting the below exception (after executing above restoration command)

gunzip: stdin: unexpected end of file
ERROR: unterminated quoted string at or near "'\x3c3f78
(hexadecimal junks removed)
LINE 1: SELECT pg_catalog.lowrite(0, '\x3c3f786d6c2076657273696f6e3d…

Best Answer

Based on the first error message, the .gz backup file seems to be truncated.

This could be confirmed with the command:

gunzip -c my_db_dump.sql.gz >/dev/null

Presumably this will lead to the same error message: unexpected end of file which is the root cause, the other error from postgres being the consequence of the abrupt end of the data stream.

If the .gz file is a copy resulting from a transfer, you want to compare its size against the size of the original, and transfer it again if it's incomplete. If that's the only copy or if the original itself is incomplete, completing the restore will not be possible.