Psql databasename < file.db is the recommended method to import to a database. This doesn't work why?

  • 3
    What (apart from saying "This doesn't work") have you done to resolve the issue? Please add this detail. – Vérace Apr 2 '15 at 22:24

You are possibly not creating the database before attempting to restore it. From here,

24.1.1. Restoring the Dump

Text files created by pg_dump are intended to be read in by the psql program. The general command form to restore a dump is

psql dbname < infile where infile is the file output by the pg_dump command. The database dbname will not be created by this command, so you must create it yourself from template0 before executing psql (e.g., with createdb -T template0 dbname). psql supports options similar to pg_dump for specifying the database server to connect to and the user name to use. See the psql reference page for more information.

Note the part which says

"you must create it yourself from template0 before executing psql (e.g., with createdb -T template0 dbname)".

  • I have tried createdb for a new database, this didn't work either. I then used adminiii to create a database then tried to restore to this. – Henry Apr 3 '15 at 16:28
  • How did this work out? – Vérace Apr 3 '15 at 16:30
  • Thank you for your interest, turns out that it is my lack of knowledge and poor documentation is the cause of my problem. – Henry Apr 8 '15 at 10:28
  • And you could, perhaps, mark my answer as helpful? :-) – Vérace Apr 8 '15 at 11:51
  • I have given this a tick; what Windows users need to know is you can fall into the trap of thinking it works in a similar manner to a power shell. Also in the Admin III console you can invoke the command console but it will always want you to choose a database and then you can't operate as PSQL commands the /I seems to be equivalent at that stage. The lack of any confirmation or failure message is a bit disconcerting. – Henry Apr 9 '15 at 14:03

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