Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import SQL dump into PostgreSQL database

We are switching hosts and the old one provided a SQL dump of the PostgreSQL database of our site.

Now, I'm trying to set this up on a local WAMP server to test this.

The only problem is that I don't have an idea how to import this database in the PostgreSQL 9 that I have set up.

I tried pgAdmin III but I can't seem to find an 'import' function. So I just opened the SQL editor and pasted the contents of the dump there and executed it, it creates the tables but it keeps giving me errors when it tries to put the data in it.

ERROR:  syntax error at or near "t" LINE 474: t 2011-05-24 16:45:01.768633 2011-05-24 16:45:01.768633 view...  The lines: COPY tb_abilities (active, creation, modtime, id, lang, title, description) FROM stdin; t   2011-05-24 16:45:01.768633  2011-05-24 16:45:01.768633  view    nl ...   

I've also tried to do this with the command prompt but I can't find the command that I need.

If I do

psql mydatabase < C:/database/db-backup.sql; 

I get the error

ERROR:  syntax error at or near "psql" LINE 1: psql mydatabase < C:/database/db-backu...         ^ 

What's the best way to import the database?

like image 520
dazz Avatar asked Jul 27 '11 09:07

dazz


People also ask

Can I import MySQL dump to PostgreSQL?

It is not possible to import an Oracle (binary) dump to PostgreSQL.


2 Answers

psql databasename < data_base_dump 

That's the command you are looking for.

Beware: databasename must be created before importing. Have a look at the PostgreSQL Docs Chapter 23. Backup and Restore.

like image 127
Jacob Avatar answered Sep 25 '22 02:09

Jacob


Here is the command you are looking for.

psql -h hostname -d databasename -U username -f file.sql 
like image 45
Gabriel Ramirez Avatar answered Sep 23 '22 02:09

Gabriel Ramirez