The text file created by pg_dump or pg_dumpall needs to be restored into an existing database. If a database does not exist to hold the data from this restoration, then you must create a database before executing the restoration. To create a database use the command:

   createdb -t template1 dbname 

The previous command shown uses the template1 database to create a new database. It is executed at the Unix shell. For detailed information on database creation, refer to the Database Management chapter.

Note Using Dump or Dump_all
 

Objects dumped into the output file during a pg_dump process must be owned by the user you are logged in as for you to restore the dump. If the owner of those objects are several different users, then those users must exist and you must connect as each user.

This creates a problem when you are upgrading to a new version because there will not exist any users besides the default users. To utilize the dump performed by pg_dump , you can re-create every user who owns an object in the dump. Instead of doing this, you can use the pg_dumpall for a dump that will eventually be restored on a version upgrade.

Now you can restore the database using the command:

   psql dbname < input_file   

The input file is defined as the file that was used in the pg_dump command.