Install PostgreSQL 9.5.1 on Linux

PostgreSQL is a powerful, Free, open-source object-relational database system (ORDBMS). It’s in active development and had more than 15 years of experience and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness. It runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows. PostgreSQL support the standard database functionality such as foreign keys, joins, views, triggers, and stored procedures (in multiple languages) and support most SQL:2008 data types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and TIMESTAMP also supports storage of binary large objects, including pictures, sounds, or video. It has native programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among, etc…The latest version of PostgreSQL 9.5.1 released on February 11, 2016.

1) Add PostgreSQL Repo on RPM System

We can easily install Latest version of PostgreSQL release from PostgreSQL official repository to RHEL 6/7, CentOS 6/7, Oracle Linux 6/7 & Scientific Linux 6/7. Just add the below repository based on your distribution and install it.

For Fedora 23
# rpm -Uvh http://yum.postgresql.org/9.5/fedora/fedora-23-x86_64/pgdg-fedora95-9.5-3.noarch.rpm

For Fedora 22
# rpm -Uvh http://yum.postgresql.org/9.5/fedora/fedora-22-x86_64/pgdg-fedora95-9.5-3.noarch.rpm

For RHEL/CentOS/SL/OL 7 Series
# rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

For RHEL/CentOS/SL/OL 6 Series
# rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

1a) Install & Initializing PostgreSQL on RPM System

Once you added postgreSQL, just fire below commands to install and initialize the database in PGDATA (only needed once).

Install postgreSQL
# [yum|dnf] install postgresql95-server postgresql95

Initialize the database in PGDATA (only needed once) on RHEL/CentOS/SL/OL 7 Series & Fedora 19 & later

# /usr/pgsql-9.5/bin/postgresql95-setup initdb

Initialize the database in PGDATA (only needed once) on RHEL/CentOS/SL/OL 6 Series & upto Fedora 18

# service postgresql-9.5 initdb

1b) Start PostgreSQL Server

After successful installation of PostgreSQL, you have to kick start and enable in boot.

Start postgreSQL & Enable on boot (7 Series & Fedora)
# systemctl start postgresql-9.5
# systemctl enable postgresql-9.5

Start postgreSQL & Enable on boot (6 Series)
# service  postgresql-9.5 start
# chkconfig postgresql-9.5 on

2) Add apt repo & Install PostgreSQL on DEB System

Just add apt postgreSQL repo then fire below commands to install postgreSQL on Debian based systems such as Debian, Ubuntu & Mint.

Install postgreSQL on Debian 6, 7 & 8 : Ubuntu 12.04, 14.04 & 14.10
$ sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ '$(lsb_release -cs)'-pgdg main' >> /etc/apt/sources.list.d/pgdg.list"
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib

3) Verify PostgreSQL Installation

We have successful installed PostgreSQL to confirm, check whether PostgreSQL working fine or not, by following below steps. PostgreSQL has been installed under postgres user name, just switch the user and use psql command to access the shell. By default PostgreSQL wont have password and you can set easily.

Swithch to postgres user
# su - postgres

Access PostgreSQL shell
$ psql
psql (9.5.1)
Type "help" for help.

postgres=#

Set password for postgres
postgres=# \password postgres

To disconnet PostgreSQL
postgres-# \q

Enjoy….)

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

One Comment on “Install PostgreSQL 9.5.1 on Linux”

  1. For Linux Mint 18 I had to replace the following line:
    sudo sh -c “echo ‘deb http://apt.postgresql.org/pub/repos/apt/ ‘$(lsb_release -cs)’-pgdg main’ >> /etc/apt/sources.list.d/pgdg.list”

    ..with this one:
    sudo sh -c “echo ‘deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main’ >> /etc/apt/sources.list.d/pgdg.list”

    The variable “$(lsb_release -cs)” gets set to “sarah” which is the name of Mint 18, but the repo requires “xenial” (Ubuntu version).

Leave a Reply

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