Install PostgreSQL on Ubuntu for Rails developers

These instructions worked for Ubuntu 12-14.

Check the language in the system:

env | grep LC_

It should be “en_US.UTF-8″, if not you can configure in “System Setting > Language Support”.
Installing DDBB and libpq-dev to compile rails gem when bundling, with following command:

sudo apt-get install postgresql libpq-dev

To gain access from the server it-self, In /etc/postgresql/9.3/main/postgresql.conf, uncomment the following line:

listen_addresses = 'localhost'

To have access from rails app, modify the following line in /etc/postgresql/9.1/main/pg_hba.conf:

# "local" is for Unix domain socket connections only
local   all             all                                     md5

Restart the service:

sudo service postgresql restart

You will need to add a role:

sudo -u postgres psql
create role pg_user with createdb login password 'pg_user';

Be sure that your Gemfile includes: gem ‘pg’
Create your database.yml for dev and test:

common: &common
  adapter: postgresql
  username: pg_user
  password: pg_user
 
development:
  <

Create and fill the database:

rake db:create
rake db:migrate
rake db:seed

Some Postgre useful commands are:

  • List of databases: sudo -u postgres psql -l
  • Check server encoding: sudo -u postgres psql -c “SHOW SERVER_ENCODING”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>