PostgreSQL is a very popular database in Rails world. Here I describe how to install and configure it on Ubuntu 14.04 server.
Using apt-get to install PostgreSQL is very simple. Just execute the following two commands,
Here on my server it will install PostgreSQL 9.3.
During the installation a user named ‘postgres’ will be created automatically and this user is used to start postgresql.
So we should change the password of user ‘postgres’.
1 2 3 4
The installation will put configuration files in /etc/postgresql/9.3/main by default.
1 2 3 4 5 6 7 8 9 10
Configure new data directory
Sometimes to improve performance, we want put postgres data files in its own disk. For example, we may mount a disk in folder /database and we want to put all postgres data file there. So let’s do that.
Suppose the /database folder already exists. We need to change its owner to postgres firstly.
Now we need to initialize this folder as a data folder
We must su as postgres first since this user also owns the server process.
Now let’s stop server by running sudo service postgresql stop.
Now we need to update the file /etc/postgresql/9.3/main/postgresql.conf,
change data_directory = ‘/var/lib/postgresql/9.3/main’ to data_directory = ‘/database’
PS: You need to stop the server first before updating the data_directory location. Otherwise the stop will fail and you need to kill the process manually.
After update the configuration file we need to restart postgresql server.