Install Postgres 9.2 on CentOS, RHEL, Debian 6

Overview

PostgreSQL is another popular open source database which continues to grow in popularity as an alternative to MySQL database server. The latest release of postgresql is 9.2, this post helps one setup postgresql on CentOS, Debian and RHEL.

Install Postgres 9.2 on CentOS, RHEL, Debian 6

On CentOS


32-bit
# rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-i386/pgdg-centos92-9.2-6.noarch.rpm

64-bit
# rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm

Open the CentOS-Base.repo file in an editor


# vi /etc/yum.repos.d/CentOS-Base.repo

Append the exclude directive after the main and update definition


[base]
exclude=postgresql*

[updates]
exclude=postgresql*

On RHEL


32-bit
# rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-i386/pgdg-redhat92-9.2-7.noarch.rpm

64-bit
# rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-redhat92-9.2-7.noarch.rpm

Open the rhnplugin conf file


# vi /etc/yum/pluginconf.d/rhnplugin.conf

Append the exclude directive after the main definition


[main]
exclude=postgresql*

Install postgresql


# yum install postgresql postgresql-server postgresql-contrib

Intialize the db and start the service


# service postgresql-9.2 initdb
# service postgresql-9.2 start
# chkconfig postgresql-9.2 on

On Debian

Add backports repo

# deb http://backports.debian.org/debian-backports squeeze-backports main
# sudo apt-get update
# sudo apt-get -t squeeze-backports install libpq5 postgresql-common

Add the official postgresql repo key


# wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -

Open the sources.list file and


# vi /etc/apt/sources.list

Append the following line to the file (postgresql official repo)


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

Run apt-get update and install the server and client


# sudo apt-get update
# sudo apt-get install postgresql postgresql-client chkconfig

Starting the server now will throw an error.

# /etc/init.d/postgresql start
No PostgreSQL clusters exist; see “man pg_createcluster” … (warning).

Create a new cluster


# pg_createcluster 9.2 postgres

Now start the server


# /etc/init.d/postgresql start
# chkconfig postgresql on