Installing & Configuring Postgres on Ubuntu 14.04

In this tutorial, we will walk through the steps required to install and configure Postgres for your Greenfield application.

This tutorial assumes you have already created an Ubuntu 14.04 x64 VPS instance and have installed and configured Apache & Tomcat. If you haven't done this already, follow Minimum Server Setup : Apache, Tomcat & Greenfield on Ubuntu 14.04 for detailed instructions on how to install and configure Apache & Tomcat for Greenfield

1. Install Postgres

sudo apt-get install postgresql postgresql-contrib

2. Update Postgres user password

You will want to update the postgres user password after initial install

Switch to postgres user

sudo -i -u postgres

Invoke psql command line

psql

Change password

alter user postgres with password 'new password';

Exit out of psql

\q

3. Configure Postgres to accept outside connections (optional)

Depending on what type of user you are, you may want to configure postgres to accept connections from outside the server. One reason to do this is to use pgAdmin on your local machine. So in the example I will configure Postgres to accept connections from a personal machine/ip address

Login as postgres user

sudo -i -u postgres

Edit postgresql.conf

vim /etc/postgresql/9.3/main/postgresql.conf

Add/Edit the following listen_addresses definition to look like this

listen_addresses='*'

Edit pg_hba.conf to allow connections from your ip address

vim /etc/postgresql/9.3/main/pg_hba.conf

Add following line

substitue your ip address for 14.32.54.1 listed in example

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all            14.32.54.1/24              md5

Restart Postgres

/etc/init.d/postgresql stop
/etc/init.d/postgresql start

Download/Install pgAdmin

Now that you have Postgres installed and configured for an outside connection, you can download pgAdmin then create your Greenfield database. If you are new to pgAdmin, it is a Postgres database management GUI interface which simplifies database administration