pg_restore not working for .dump file - postgresql

I'm trying to restore a database to a new environment and pg_dump/pg_restore seems like the best way for me to do that.
I've run the pg_dump command with the following code which has produced my dump file:
pg_dump -v -Fc --host=test.postgres.database.azure.com --port=5432 --username=test#test --dbname=test > test.dump
However when I run pg_restore it is not able to restore the database. I have run into two separate errors when trying two separate commands. The first error
occurs when i use the following command
pg_restore -h test.postgres.database.azure.com -p 5432 -U test#test -C test.dump
and the second
occurs upon using this command
pg_restore -h test.postgres.database.azure.com -p 5432 -U test#test -C -Fc test.dump
I really don't understand what is going wrong here. All other answers I have found that get these same errors were encountered when people tried to restore plain text files but that's not what I'm attempting to do here. Any help would be greatly appreciated.

Related

pg_restore is not working - input file does not appear to be a valid archive

I am doing pg_dump using -
pg_dump -U <username> -h <host> <database> > backup.sql
pg_dump is working fine.
I am trying to do pg_restore doing -
pg_restore -U <username> -h <host> -d <databse> backup.sql
Then it is showing pg_restore: error: input file does not appear to be a valid archive
I have checked many StackOverflow answers about this, but I could not figure out anything. Please help me. Thanks in advance.
Update : As per comments we can not use pg_restore for .sql files. Actually I have an restriction that I must have to restore the database using pg_restore command. Can you please give the pg_dump command using which I can restore that using pg_restore?
You created a plain format dump, which is an SQL file. You have to restore plain-format dumps with psql:
psql -U <username> -h <host> -d <databse> -f backup.sql
pg_restore is used to restore dumps in all other formats. You get dumps in other formats by using the appropriate -F option with pg_dump: for example, -F c produces a custom format dump.
If you want to restore a plain format dump with a client other than psql, you have to create it with the option --inserts.

How to restore .bak file using pg_restore command through cmd in PostgreSQL?

I have a test.bak file created with pg_dump command which has a hypertable and i have created a new database Performance_Test in postgreSQL.
The database was dumped using the command:
pg_dump -h localhost -U postgres -p 5432 -Fc -f "D:\Database Backup\temp.bak" Performace_Test
I want to restore that test.bak file in Performance_Test.
How can i do that?
You can restore doing the below(with caveats noted further on):
pg_restore -h localhost -d Performace_Test -U postgres -p 5432 "D:\Database Backup\temp.bak"
The caveats are:
If Performace_Test was created as mixed case by quoting you will need to quote the name above e.g. "Performace_Test"
If Performace_Test is not empty then you will get a bunch of errors.
Also assumes that Performace_Test is on the same cluster as you specified in the pg_dump command.
psql Performance_Test < test.bak

Postgresql - backup restore on different owner?

My question is similar to this I even vote up it, but unfortunately in my case I have text dump and I can not restore using pg_restore =(
zcat /home/kes/work/projects/bennet/db/bennet.sql.gz | \
pg_restore -h 127.0.0.1 -p 5432 -U bennet --no-owner --role=bennet -d bennet
pg_restore: error: input file appears to be a text format dump. Please use psql.
But psql has no role and no-owner options
Is there a way to restore text dump on different owner?
No. You have two options:
Manually edit the SQL script. This is cumbersom and error-prone.
Restore the complete dump to a new, empty scratch database using psql and dump that with --role and --no-owner as you need.

pg_restore throws warnings and return exit 1

I am trying to restore a PostgreSQL database using the command below:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -p 5432 -U postgres -w -d databaseName Backup.dump
The restoring is done successfully. But it displays below warning message in the end.
WARNING: errors ignored on restore: 97
Due to which my shell script is failing as the command returns exit 1 code.
Can anyone please guide on this?
It can be done by dropping the database, creating it and then storing a clean database.

copy (pg_dump) .sql file to postgresql using Cygwin

I have downloaded YELP's sql file and tried to import the sql to my local Postgresql.
I am running postgres on Windows 10 and using Cygwin to execute command that I have found on Google. (it took me forever to use Cygwin instead of windows psql shell)
anyhow, Yelp gives data schema in sql and also data in sql. You may find them a link attached below
https://www.yelp.com/dataset/download
so, basically what I thought was creating an empty table with YELP's schema
the, copy all YELP's data into that table.
pg_dump -h localhost -p 5433 -U postgres -s mydb < D:/YELP/yelp_schema.sql
pg_dump -h localhost -p 5433 -U postgres -d mydb < D:/YELP/yelp_sql-2.tar
and I am checking my database transaction and it doesn't change nothing and i do not see the table.
this is what i see on Cygwin terminal
enter image description here
and nothing on my postgresql database
Please let me know what I have missed.
Thanks a lot
your link asks for email to download. I would suspect yelp to be not transparent for it. So I did not check if they have any advise on their data sets... Anyway you use pg_dump to dump the data. to import the resulting file use psql for plain sql files and pg_restore for custom format ones...
Eg:
psql -h localhost -p 5433 -U postgres -f D:/YELP/yelp_schema.sql
pg_restore -h localhost -p 5433 -U postgres -s worldmap -Ft D:/YELP/yelp_schema.sql
https://www.postgresql.org/docs/current/static/app-pgdump.html
pg_dump — extract a PostgreSQL database into a script file or other
archive file