1

I am running PostgreSQL 9.3 on my machine. I have PhpPgAdmin running on a cloud, using which I exported the database I am supposed to be working on, selecting "Structure and Data" and "Download". There is an sql file generated. On my machine however, I open my PgAdmin3 client , initialize my databases and run the following import command

psql -U postgres -d postgres -f dump.sql

Nothing happens. I also tried

psql postgres < /path/to/dump.sql 

But again nothing happens. I tried on both Windows as well as Linux Mint because I thought it was something wrong with my installation on Windows. I am new to PostgreSQL and the equivalent for it in MySQL using PhpMyAdmin was simple. Am I missing any security things? I think not because just so that nothing gets confused, I saved all my names as postgres itself.

I have researched everywhere but nothing so far. Any help would be appreciated. Thanks!

  • 1
    Do you try to run psql from pgAdmin? At least what you write suggests that. It won't work. You should run it from the command line or open the dump in the pgAdmin query tool and run it from there. – dezso Jun 20 '14 at 10:25
  • Yes i did that. No response. As if nothing happened, the terminal ignores my query and creates a new prompt. (I mean #) – ValarMorghulis Jun 20 '14 at 10:27
  • Which OS, exactly what command issued? What do you see in the dump if you visit it with an editor? – dezso Jun 20 '14 at 10:28
  • Windows 7. Both commands were issued from the prompt which is found in Plugins->PSQL Console in PgAdmin3. The dump contains a lot of PostgreSQL commands. Here is a redacted version. pastebin.com/B3uUUiL5. – ValarMorghulis Jun 20 '14 at 11:01
  • 1
    Try to open the dump in query editor and run from there or really do it from the command line. I'm not sure what that console can or cannot do. – dezso Jun 20 '14 at 11:50
2

The PSQL Console in pgadmin3 consists of opening a terminal and running psql --username yourname [other options] dbname inside it for you, with yourname and dbname being taken from what you've used to log in pgadmin3.

This console runs the psql interpreter which expects either psql meta-commands starting with backslash, or plain SQL commands.

When typing this:

`psql -U postgres -d postgres -f dump.sql`

it's taken as an unfinished SQL sentence for the interpreter, so it's just waiting for the rest. That's why nothing happens as you wrote. This command is out of context.

What you want is:

\i /path/to/dump.sql

\i means 'include' and is the meta-command to feed a file as a stream of SQL commands to the interpreter. You'll see the output of these commands on the terminal and when finished , type \q to end the session.

  • But according to the manual -f should be equivalent to \i – a_horse_with_no_name Jun 23 '14 at 8:18
  • @Daniel Verite : Thanks for that suggestion. I tried it but now it says ERROR : Syntax Error at or near "'" - LINE 1 INSERT INTO ... Similar error with ALTER TABLE instead INSERT INTO as well. I did not change anything at all in the dump. Here is the screenshot. bayimg.com/baocOAAfO – ValarMorghulis Jun 23 '14 at 9:29
  • 1
    @George: your dump is apparently for MySQL, not PostgreSQL. It encloses table names between backticks like only MySQL does. – Daniel Vérité Jun 23 '14 at 9:32
  • @a_horse_with_no_name: the asker doesn't get the option to use -f because the psql command line invocation is generated by pgadmin. – Daniel Vérité Jun 23 '14 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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