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
Related
I have a Postgesql database that I want to copy/replicate from my local machine to an AWS RDS instance.
I've created a dump as follows:
pg_dump -v -U postgres mydb > mydb.dump
I then tried to copy to my RDS as follows:
psql -f mydb.dump -h XXXXXXXXXXXX.us-east-1.rds.amazonaws.com -p 5432 -U postgres -d mydb
However, I get the following error:
psql:mydb.dump:1: error: invalid command \
psql:mydb.dump:6: ERROR: syntax error at or near "ÿ_"
LINE 1: ÿ_-"\o""edrp\nou"tnsctme e
^
I then tried to rule out any issues with RDS by copying the archive to another local database as follows:
pg_restore -U postgres -d mydbcopy mydb.dump
I received an error:
pg_restore: error: input file does not appear to be a valid archive
I also tried the preceding as follows:
psql -f my.dump -U postgres -d mydbcopy
And got the same error as before:
psql:mydb.dump:1: error: invalid command \
psql:mydb.dump:6: ERROR: syntax error at or near "ÿ_"
LINE 1: ÿ_-"\o""edrp\nou"tnsctme e
^
I am using Windows Powershell and Postgresql 13.2.
Am I missing something ?
It seems to be an issue with PSQL tools in view that I'm getting the error even when trying to copy locally.
I managed to solve this problem by using
pg_dump -f dump.sql --inserts mydb
It turns out using the redirect ">" means PowerShell does the file writing and it uses UTF16 which doesn't play nice with psql. The -f flag makes pg_dump do the writing itself.
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
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,
I've downloaded the latest copy of my heroku database with
$ curl -o latest.dump `heroku pg:backups public-url --app myapp`
And this gives a file with the following type on my local machine:
$ file db/latest.dump
db/latest.dump: PostgreSQL custom database dump - v1.12-0
I'm trying to import this into my local Postgres DB (my_db) using psql. However, I'm getting lots of errors:
$ psql my_db < db/latest.dump
...
psql:db/latest.dump:119425: invalid command \?A~??ܣb?{#?+????LS??
psql:db/latest.dump:119426: invalid command \D%!ѡ/F??g????A???dC????|2?M?$?8GTJ??c?E?;??֛Sh??S?[NP?f?2?+H?W????k
... [thousands of lines]
psql:db/latest.dump:261719: ERROR: invalid byte sequence for encoding "UTF8": 0xba
The command psql -f db/latest.dump my_db fails the same way.
What needs to be done in order to import this file locally into a new database with the same schema, etc?
I was able to use pg_restore to solve the problem:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d my_db db/latest.dump
I'm getting this error when I restore a Postgres backup from another server:
pg_restore: [compress_io] could not uncompress data: invalid block type
I haven't found much online about what that error means. Except of this discussion.
Is it a problem with the backup file? Is it corrupted? Or is there anything that I need to do in order for the target database to read the block type?
This is part of a script running in crontab for creating the backup: ...
if /usr/pgsql-9.1/bin/pg_dump -Fc -Z 9 -U postgres $PG_DATABASE -p $PG_PORT --schema=$SCHEMA > $PG_BACKUP_FOLDER/notus_dump_$NOW-$SILO.backup 2>/tmp/pg_dump.err
... And this is the command that restores it:
/usr/pgsql-9.1/bin/pg_restore -v -U postgres -p $PG_PORT -C -e -d $PG_DATABASE -n $SCHEMA [backup file]
All variables resolve correctly. The problem is on restore, it starts restoring but it exits with the error in the title.