Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql- restoring .dump file

I am new for psql. I got from my server data.dump file. I need to restore it in my local. I tried these commands.

i) psql -U postgres dbname -f servicedb.dump

Error:
      psql: warning: extra command-line argument "-f" ignored
      psql: warning: extra command-line argument "servicedb.dump" ignored

ii) psql -U postgres dbname < servicedb.dump

 Error:
              ^
 ERROR:  syntaxe error at or near "☺"
 LINE 1: ☺☺

What is this ".dump" file and how to restore it?

like image 749
shahul Avatar asked Dec 08 '09 11:12

shahul


People also ask

How do I restore a .GZ file in PostgreSQL?

Use “-d” comamnd line option to provide database name to pg_dump command. Make sure to replace your actual database name in place of mydb . Restore a single database from backup in PostgreSQL. Just use “psql” command to restore PostgreSQL database.

Can I restore SQL database to PostgreSQL?

You can't restore it to a PostgreSQL database. If you need to migrate the data from SQL Server to Postgres you need to script the data out or use a Migration/ETL tool.

Where is Postgres backup file located?

Go to command prompt and directory postgresql\9.3\bin. .. c:\Program files\postgresql\9.3\bin> pg_dump -h localhost -p 5432 -U postgres test > D:\backup.


6 Answers

I got a .dump file from my server (Heroku). As Klaus said, pg_restore is the only way I could restore it in my local.

What I wrote in my terminal was:

pg_restore -c -d [database_name] [dumpfile_name].dump

There are a lot of options you can see in Klaus link of pg_restore :)

like image 105
marrossa Avatar answered Oct 05 '22 17:10

marrossa


psql -f filenamed.dmp db_name

works fine

like image 40
Zydoon Avatar answered Oct 05 '22 16:10

Zydoon


For Postrgres 9.2

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U [user] -d [db] [filename].dump
like image 23
Sergiy Seletskyy Avatar answered Oct 05 '22 17:10

Sergiy Seletskyy


Have a look at the pg_restore command.

like image 42
Klaus Byskov Pedersen Avatar answered Oct 05 '22 16:10

Klaus Byskov Pedersen


I found it tricky in windows environment.

pg_restore will not work if its a text format dump. In that case, we need to use psql.

psql -U username -f database.dump databasename

It will prompt for the password of the username and then the restoring process will be initiated.

like image 35
shakil080 Avatar answered Oct 05 '22 17:10

shakil080


pg_restore is far from obvious, this is the command I used to create a new database and restore the dumpfile into it on a remote Postgres instance running on AWS. If your connection is correct, pg_restore should immediately ask you to input your password)

pg_restore -h mypostgresdb.eu-west-1.rds.amazonaws.com -U adminuser --verbose -C -d existingdatabase mydbdump.dm

Where the switches are:

  • -h - hostname on aws
  • -U - username, this needs to be an admin user with permissions to create a db
  • --verbose - get verbose output to screen
  • -C - means create a brand new database from the dumpfile (it will be named whatever the db you dumped was called)
  • -d - confusingly this needs to be the name of a database that already exists, basically pg_restore needs to connect to an existing DB so it can run the necessary scripts to create the new database
  • mydbdump.dmp this is the location of the dumpfile you are attempting to restore.
like image 32
Iain Hunter Avatar answered Oct 05 '22 17:10

Iain Hunter