How to install and configure PostgreSQL on Ubuntu for Ruby on Rails

PostgreSQL is object oriented database and is getting more powerful than MySQL, there is no doubt it will take place instead of MySQL.
1. Installing
sudo apt-get -y install postgresql-9.1
sudo locale-gen ja_JP.UTF-8
sudo service postgresql restart
2. First time settings
In PostgreSQL access setting is configured in pg_hba.conf file. This file exists in /etc/postgresql/9.1/main, and you should edit it according to your need
after editing
sudo service postgresql-9.1 reload
3. Setting buffer size
you can set buffer size editing postgres.conf
shared_buffers = 512mb
buffer size must be lesser than kernel.shmax size. Todo so check:
cat /prov/sys/kernel/shmmax
and see if the size is kernel size is lesser, then increase it:
sudo vi /etc/sysctl.d/30-postgresql-shm.conf
kernel.shmmax = 536870912
sudo sysctl-p
sudo service postgresql restart
4. setting access from outside
4.1edit /etc/postgresql/9.1/postgresql.conf :
add address to, just like :
 #listen_addresses = 'localhost, 192.168.0.100, 192.168.0.101'
4.2 edit pg_hba.conf
In order to connect to database sample_production from 192.168.0.100 PostgreSQL user john do following in pg_hba.conf :
host sample_production john 192.168.0.100 md5
sudo service postgresql restart

5. Firewall settings
PostgreSQL uses port 5432 by default. In order allow access from 192.168.0.100 :
sudo ufw allow proto tcp from 192.168.0.100 to any port 5432

Comments