How can I restore Postgres backup extension file in windows? - postgresql

Let's start with basic info:
-OS Windows Server 2012R2
-Postgres 9.5
I'm trying to restore a .backup file from a backup generated from the pgadmin3 interface.
I've tried restoring it using the GUI and psql and pg_restore.
I always receive the following error :
[archiver] input file does not appear to be a valid archive
Here's a sample of my pg_restore command
D:>pg_restore -d newDB -h HOSTNAME -U someuser -v -F c
"D:\BackupFull.backup" pg_restore: [archiver] did
not find magic string in file header
or
D:>pg_restore -d newDB -h HOSTNAME -U someuser
"D:\BackupFull.backup"
pg_restore: [archiver] input
file does not appear to be a valid archive
Am I doing something wrong or is my file corrupted somehow.
Thanks,

Related

Postgresql restore with compressed dump file

I took a postgresql DB Bacup with the below command
pg_dump -Z6 -h localhost test_db -f test_db.tar -p port
Now If I try to restore it with psql facinf the below error:
psql:test_db.sql:117359: error: invalid command \gg<CB>t<E4>Iƣ<AC>=<AF>*ESC^TDuV^P^Ov<B6><B0>
psql:test_db.sql:117362: error: invalid command \a>#
psql:test_db.sql:117363: error: invalid command \"<99>k<86>
psql:test_db.sql:117372: error: invalid command \<9B>遥<FD><FE><BA>j
psql:test_db.sql:117406: ERROR: invalid byte sequence for encoding "UTF8": 0x8a
With pg_restore:
pg_restore: error: input file does not appear to be a valid archive
I thought i was using -Fc with pg_dump, but somehow I missed it. Now Can you help me to restore this Backup to postgresql.
I'm Using PostgreSQL 14.5
I've tried below commands
cat test_db.tar | psql test_db -U postgres -h localhost -p port
\i testdb.tar
even Tried to rename the dump file from test_db.tar to test_db.dump and tried restoring it. Nothing is working.
It seems -Z6 generates a gzipped file.
You can convert that into a plain text SQL script that psql can read using. To unzip it using gzip you will need to rename it, e.g. to test_db.sql.gz
Then you can use:
gzip -k -d test_db.sql.gz
-k will keep the original file

Restore database dump with tool pg_restore returns "pg_restore: error: input file does not appear to be a valid archive"

Im working on windows 10 with powershell, pgAdmin 4v6 and the user has no admin permissions.
When I create the dump with a command similar to this one:
pg_dump -h localhost -p 8083 -d database-name -U user --password --clean -Fc --no-acl --no-owner > backup_name.dump
I try to make the restore with this command:
pg_restore -h localhost -p 5432 -U postgres -d posgres-v backup_name.dump
Im gettign this message:
pg_restore: error: input file does not appear to be a valid archive
It seems that the error was the dump file, I created a new one and could restore it just fine.

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

i backup local database use
pg_dump -h localhost -p 5432 -U postgres -W -F t test_db > .\local-11-06.tar
then i drop test_db and recreate by
CREATE DATABASE test_db ENCODING 'UTF8'
then restore by pg_restore
pg_restore -h localhost -U postgres -p 5432 --dbname=test_db --verbose .\local-11-06.tar
but error with
pg_restore: [archiver] input file does not appear to be a valid archive
What might be wrong?
(my PC info : windows 10 with postgresql 11)
P.S.
it is work on CMD but failed on PowerShell.(Encoding? i'm in JP)

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:
I manually unpack the base.tar.gz => base.tar
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!
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

How to restore postgres 12 dump file into postgres 11.5

dump file generated by pg_dump command in postgres 12
command i use in postgres 11.5:
pg_restore -h [host] -p 5432 -U postgres -d [db] -1 backup.dump
error message:
pg_restore: error: could not set default_table_access_method: ERROR: unrecognized configuration parameter "default_table_access_method"
Is it possible to restore it? please advice.
It seems that only pg_restore throws an error, psql just issues a warning. So you could convert your binary dump to text:
pg_restore dumpfile.Fc -f- | psql -U user -d database
This worked for me on linux.
default_table_access_method is not available in pg11. So the workaround is to take a plain dump of source database and remove the following given below entry from your backup.dump file
SET default_table_access_method = heap;
After that use the below command for restoring the dump on target pg1