Install postgresql 9.4 on Ubuntu 14.04 LTS server

PostgreSQL is an object-relational database system (ORDBMS). It is free and its source code is available. Many volunteers, individuals and companies are contributing to develop the postgresql , the group is often addressed as PostgreSQL Global Development Group . PostgreSQL is cross platform means it can be run on many Linux/Unix based Operating System, Windows etc. If you are getting problem in pronouncing PostgreSQL, you can also call it as Postgres.

Details Of Lab
Operating System: Ubuntu 14.04 LTS Server
Arch: x86_64
PostgreSQL version: 9.4 (Stable release) [Always recommend to install latest, find from postgres official website.]

Let’s start installing the Postgres on Ubuntu 14.04 LTS Server.

Create apt repo file for postgres

Create new apt repo file for postgres. Generally we use vi editor , you can use your favorite file editor.

sudo vi /etc/apt/sources.list.d/pgdg.list

Paste the below given lines in /etc/apt/sources.list.d/pgdg.list file then save and close.

deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main

Import repository signing key and update packages list

To import the repository signing key and update packages, run the following command.

sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update

Install Postgres

Now run below given command to install postgres 9.4 version on Ubuntu 14.04 LTS Server.

sudo apt-get install postgresql-9.4

Start/stop/restart/status of Postgres

It is important to know how to start,stop,restart postgres and check its running status. The given below commands will help you to do so.

To start postgres service

sudo service postgresql start

To stop postgres service

sudo service postgresql stop

To restart postgres service

sudo service postgresql restart

To check status of postgres service

sudo service postgresql status

How to login into postgresql

This is quite tricky one. To login into postgresql server through command line first login as system user called postgres. Once you switch to postgres system user run the command psql and you will be in. (Because it is fresh installation, password is not set)

Note: After installing postgreSQL, the system user postgres is also get created.

Follow the below given command –

## Switch to system user called postgres
sudo su - postgres

Now you are switched to postgres system user. Run below command to login into PostgreSQL server console .

psql

To exit from postgres server console, type q and hit enter .

See below given screenshot for clear understanding.

postgres

Learn in next post about, how to set postgres password on PostgreSQL .