Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi i am using postgresql . i tried to import a databsee by

$ psql arbles < app.arbles.com.15.08.2014.sql;
ERROR:  syntax error at or near ""
LINE 1:
        ^

it gives me an error ,

  1. I firstly created my database arbles
  2. then i gave one of my database user's full privilages of the database

grant all privileges on database arbles to postgrestest;

3.then i tried the first command and it failed

my app.arbles.com.15.08.2014.sql file is in /var/lib/postgres i also moved it to different locations , but the same error occures.

postgrestest

is also a super user

i also thired with different solutions

   1. psql -h hostname -d databasename -U username -f file.sql
   2. \i C:/database/db-backup.sql

non of them worked , why is this happening , please help me , thanks in advance

share|improve this question
    
Are you sure the backup file is SQL file? How was it created? If it was created using pg_dump, then use pg_restore to import the database. –  Aleks G Aug 15 '14 at 8:13
    
@AleksG yes it was createed using pg_dump command –  Kanishka Panamaldeniya Aug 15 '14 at 8:14
    
Try psql < filename dbname –  John Barça Aug 15 '14 at 8:16
    
@JohnBarça same error :( –  Kanishka Panamaldeniya Aug 15 '14 at 8:17
    
@KanishkaPanamaldeniya What is the output of file app.arbles.com.15.08.2014.sql? How about head -n 3 app.arbles.com.15.08.2014.sql | cat -A ? –  Craig Ringer Aug 15 '14 at 8:35

1 Answer 1

As you indicated that the backup was created using pg_dump, then, most likely, it's not a SQL file. Instead of trying to execute SQL from that file, use pg_restore to restore it:

pg_restore -h hostname -d databasename -U username filename
share|improve this answer
    
it says pg_restore: [archiver] input file does not appear to be a valid archive , actually create pg_dump in one server and then i upload via scp to another server , from that i do these things –  Kanishka Panamaldeniya Aug 15 '14 at 8:32
    
@AleksG That's incorrect and misleading. pg_dump can create SQL dumps and does so by default. It only creates custom-format dumps if you pass -Fc (custom archive) or -Fd (directory). –  Craig Ringer Aug 15 '14 at 8:34
    
@CraigRinger pg_dump can create dumps in SQL format, true, however pg_restore is supposed to be smart about the existing format - and import whatever it encounters. In the past, I have had issues trying to execute the dump as a sql script while pg_restore worked fine. –  Aleks G Aug 15 '14 at 8:39
    
@AleksG Well, newer versions will at least complain that pg_restore: [archiver] input file appears to be a text format dump. Please use psql.. Older versions just choke and die. It certainly doesn't do anything smart like run it through psql. –  Craig Ringer Aug 15 '14 at 8:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.