Centos - POstgresql 9.2
Centos - POstgresql 9.2
Centos - POstgresql 9.2
3 / RedHat EL6/Fedora
1 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
As a good measure install all updates to this CentOS 6 server. Before you continue further. This step is optional.
7/9/2013 7:10 AM
2 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Postgres Repo:
pgdg is the repo that postgresql can be downloaded and installed from. Here is where you download it from.
Identify which version of rpm you want to download for installing PostgreSQL database server. Right now I
am picking PostgreSQL 9.2 for CentOS [CentOS 6 - x86_64] as this is the latest version at this time. Now that
we have identified which version we want to download, right click on that hyperlink and click "copy link address".
7/9/2013 7:10 AM
3 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Login into your CentOS Server by SSH and run the following command to download it into your CentOS 6
Server.
wget http://yum.pgrpms.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
7/9/2013 7:10 AM
4 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
If It fails and complains that you dont have wget utility installed on your machine, Install wget utility by running command
7/9/2013 7:10 AM
5 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Now that wget utility is installed, download the rpm from PostgreSQL rpm repository
7/9/2013 7:10 AM
6 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Now that we have installed the pgdg central PostgreSQL repo, we should have postgresql rpms show up in
yum package manager search. Run the following command on command line to search for all postgres related available rpms.
7/9/2013 7:10 AM
7 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
The following list should be generated from the search. Now install PostgreSQL client / Server programs.
7/9/2013 7:10 AM
8 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
7/9/2013 7:10 AM
9 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
You now have successfully installed PostgreSQL database server / client on this CentOS Server.
Now create default data/tables into this newly build database server by running command:
[Service name is postgresql-9.2 or corresponding PostgreSQL generated init file under /etc/init.d/ directory]
7/9/2013 7:10 AM
10 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Make your database server auto starts when this CentOS server starts/restarts.
chkconfig postgresql-9.2 on
7/9/2013 7:10 AM
11 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Create an user other than default user for granting access to the database from outside world into this database server.
Login into database as postgres user, to do that run the following commands:
su postgres
psql -dpostgres
Above command some times lead to a PostgreSQL shared library issue. On some systems that have shared
libraries (which most systems do) you need to tell your system how to find the newly installed shared libraries. If you did not encounter this error, please skip this step of adding path to /etc/profile file and move
on to creating user.
psql: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
7/9/2013 7:10 AM
12 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
To fix this issue we need to add the following lines in your /etc/profile file all the way at the bottom of the
file. First exit out as postgres user by typing exit on command line and add the following lines at the bottom
on /etc/profile file as root user. Save and quit from here after adding those lines mentioned below.
Restart your CentOS Server to get the new LD_LIBRARY_PATH variable set properly.
shutdown -r now
After the server is up and running, SSH in and run the following commands to create an user.
su postgres
psql -dpostgres
7/9/2013 7:10 AM
13 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Now you are inside PostgreSQL database server, so create a super user for accessing database server from
outside world and exit out of there.
\q
7/9/2013 7:10 AM
14 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Now we have created a super user for managing the database. We are almost done. To grant outside world
access we need to make modifications to the database server configuration files and CentOS Server firewall
rules [iptables]. First exit out as postgres user on your server and log back in as root user.
Make the changes in your database configuration file :
vi /var/lib/pgsql/9.2/data/postgresql.conf
The second configuration file that you need to edit in order to grant access to outside world is below [Host
7/9/2013 7:10 AM
15 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
vi /var/lib/pgsql/9.2/data/pg_hba.conf
Add a new line under IPv4 local connections all the way to the near bottom of the file. Make appropriate
changes to network you want this new user to login from. If your subnet is 192.168.1.1/24 or 192.168.1.1/32,
please use that or what ever is relevant in you case. This rule I added indicates the database server to accept
connections for this user originating with in 192.168.1.1/24 sub-net network.
7/9/2013 7:10 AM
16 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Finally open the default PostgreSQL database port in server firewall to connecting from outside world.
vi /etc/sysconfig/iptables
Add line:
7/9/2013 7:10 AM
17 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
At this point you should be able to connect to this database server from clients outside this server like pgAdmin III [Download pgAdmin III and install on a host that you want to access this database from] as shown below:
7/9/2013 7:10 AM
18 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
7/9/2013 7:10 AM
19 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
If you have installed this in a virtual machine, make sure that you port forward (NAT Only) 5432 under your
VM Settings > Network Settings > Advanced > Port forwarding to pass through this 5432 from main host to
your VM to connect from outside VM.
Pingback: How to do point in time recovery with PostgreSQL 9.2 : PITR in CentOS 6/Redhat EL6
7/9/2013 7:10 AM
20 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
BVSat
February 25, 2013 at 2:14 am
This is one of the best! Thanks for sharing in one place. Great work
Alexander Murad
April 18, 2013 at 8:30 am
Hi, Thanks for tutorial install postgre on Centos 5.9 x64 from installing to initdb but when i started the service
[FAILED] do you have solution for this one? Thanks.
Prashanth Goriparthi
Post author
Tobi
April 25, 2013 at 12:35 pm
anonymous
April 25, 2013 at 1:05 pm
7/9/2013 7:10 AM
21 of 21
http://opensourcedbms.com/dbms/installing-postgresql-9-2-on-cent-os-6-...
Pingback: Running multiple PostgreSQL 9.2 Instances on one server in CentOS 6/RHEL 6/Fedora | Open
source database management systems - PostgreSQL & MySQL
Feby
June 14, 2013 at 5:40 am
7/9/2013 7:10 AM