How to dump database into your existing postgres database?

First check your database is created. If Not then it will show error “Databasename does not exist.”

Then run command–   rake db:create and then rake db:migrate

then run following command to import database into your created database

psql -d dbname -U username -f dumpfile_name.sql

You may have to include a full path to the psql executable if it is not on your path, and possible add “.exe” to psql, so it is “psql.exe”.


Install PostgreSQL in Ubuntu

1)  sudo apt-get install libpq-dev

2)  write gem ‘pg’ in gemfile

3)  bundle install

4)  sudo apt-get update

5) sudo apt-get install postgresql-9.4

Then rake:db create and then rake:db migrate You might get “peer authentication failed for user postgres” error To solve it follow below steps:

1) open the file pg_hba.conf for ubuntu by running this command in terminal:

$ sudo nano /etc/postgresql/9.4/main/pg_hba.conf

and then find below line and make changes....

local   all             postgres                                peer


local   all             postgres                                trust
  1. Restart the server
sudo service postgresql restart
  1. Login into psql and set your passowrd

psql -U postgres

ALTER USER postgres with password 'your-pass'; or  ALTER ROLE davide WITH PASSWORD NULL;
  1. Finally change the pg_hba.conf from
local   all             postgres                                trust


local   all             postgres                                md5

After this restart the server:

sudo service postgresql restart

Now,you can access it with your own password Now run rake db:create Authentication methods details:

trust – anyone who can connect to the server is authorized to access the database

peer – use client’s operating system user name as database user name to access it.

md5 – password-base authentication

=> If you get role “User_name” does not exist error, Create role by following below steps

$ psql -d postgres
postgres=# create role "User" login createdb;
postgres=# \q


sudo apt-get remove --purge postgresql-9.4