PostgreSQL is a open source object-relational, highly scalable, SQL compliant database management system. This article will help you for installing PostgreSQL 9.1 on CentOS 5/6 and RHEL 5/6.
Step 1: Add PostgreSQL Yum Repository
First step is to install postgres repository in your system, Use one of below commands as per your system architecture and operating system.
CentOS/RHEL 5, 32-Bit: # rpm -Uvh http://yum.postgresql.org/9.1/redhat/rhel-5-i386/pgdg-centos91-9.1-4.noarch.rpm CentOS/RHEL 6, 32-Bit: # rpm -Uvh http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpm CentOS/RHEL 5, 64-Bit: # rpm -Uvh http://yum.postgresql.org/9.1/redhat/rhel-5.0-x86_64//pgdg-centos91-9.1-4.noarch.rpm CentOS/RHEL 6, 64-Bit: # rpm -Uvh http://yum.postgresql.org/9.1/redhat/rhel-6.3-x86_64/pgdg-centos91-9.1-4.noarch.rpm
Step 2: Install PostgreSQL Server 9.1 using Yum.
Below command will install PostgreSQL 9.1 on your system.
# yum install postgresql91-server
Sample Output
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * epel: mirror.yourconnect.com * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package postgresql91-server.i686 0:9.1.9-1PGDG.rhel6 will be installed --> Processing Dependency: postgresql91 = 9.1.9-1PGDG.rhel6 for package: postgresql91-server-9.1.9-1PGDG.rhel6.i686 --> Processing Dependency: libpq.so.5 for package: postgresql91-server-9.1.9-1PGDG.rhel6.i686 --> Running transaction check ---> Package postgresql91.i686 0:9.1.9-1PGDG.rhel6 will be installed ---> Package postgresql91-libs.i686 0:9.1.9-1PGDG.rhel6 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Installing: postgresql91-server i686 9.1.9-1PGDG.rhel6 pgdg91 3.6 M Installing for dependencies: postgresql91 i686 9.1.9-1PGDG.rhel6 pgdg91 973 k postgresql91-libs i686 9.1.9-1PGDG.rhel6 pgdg91 192 k Transaction Summary ==================================================================================================== Install 3 Package(s) Total download size: 4.7 M Installed size: 20 M Is this ok [y/N]: y Downloading Packages: (1/3): postgresql91-9.1.9-1PGDG.rhel6.i686.rpm | 973 kB 00:02 (2/3): postgresql91-libs-9.1.9-1PGDG.rhel6.i686.rpm | 192 kB 00:02 (3/3): postgresql91-server-9.1.9-1PGDG.rhel6.i686.rpm | 3.6 MB 00:07 ---------------------------------------------------------------------------------------------------- Total 321 kB/s | 4.7 MB 00:15 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : postgresql91-libs-9.1.9-1PGDG.rhel6.i686 1/3 Installing : postgresql91-9.1.9-1PGDG.rhel6.i686 2/3 Installing : postgresql91-server-9.1.9-1PGDG.rhel6.i686 3/3 Installed: postgresql91-server.i686 0:9.1.9-1PGDG.rhel6 Dependency Installed: postgresql91.i686 0:9.1.9-1PGDG.rhel6 postgresql91-libs.i686 0:9.1.9-1PGDG.rhel6 Complete!
Step 3: Initialize PGDATA first time after Installation
After installing PosgreSQL server, Its required to initialize it before using first time. To initialize database use below command.
# /etc/init.d/postgresql-9.1 initdb
Above command will take some time to initialize postgres first time. PGDATA environment variable contains path of data directory.
PostgreSQL data directory Path
/var/lib/pgsql/9.1/data/
Older version ( PostgreSQL 7 or 8 ) uses below path by default for data directory.
/var/lib/pgsql/data/
Step 4: Start PostgreSQL Server
Start postgresql service using following command.
# service postgresql-9.1 start
Setup PostgreSQL service to auto start on system boot.
# chkconfig postgresql-9.1 on
Step 5: Access PostgreSQL admin command prompt.
To access postgres as admin user, first switch to postgres system account.
# su - postgres
Use psql command to access postgres prompt with admin priviledges.
$ psql
Sample output:
psql (9.1.9) Type "help" for help. postgres=#
Read below article to to how to install phpPgAdmin.
>> How to Install phpPgAdmin on CentOS using Yum
Thanks for using this tutorial for installting PostgreSQL 9.1 on CentOS 5/6 and RHEL 5/6 systems.
1 Comment
Rahul
Thank you for this neat document on getting PgSql up and running.