Skip to content

Instantly share code, notes, and snippets.

@bvajda
Created October 18, 2011 21:37
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bvajda/1296795 to your computer and use it in GitHub Desktop.
Save bvajda/1296795 to your computer and use it in GitHub Desktop.
Postgresql 9.1 server on CentOS 6

install CentOS 6

yum update
yum upgrade

check the server time. sync the time to a time server if needed (service 'ntpd')

download and install Postgresql Server v9.1 rpm package:

rpm -Uvh http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-4.noarch.rpm

This should have installed the necessary server package: postgresql91-server.x86_64.

Install the package:

yum install postgresql91-server.x86_64

This will install even the postgresql91.x86_64 and the postgresql91-libs.x86_64 packages. Create a user (e.g. "postgres") to run the server instance, and change its password:

adduser postgres
passwd postgres

Create any database clusters as needed. The installation creates an empty data directory in /var/lib/pgsql/9.1/data/. Make sure that the data directory is owned by the Postgresql user ("postgres" in this example). Initialize the cluster (as Postgresql user "postgres"):

whoami
#=> "postgres"
#initialize the cluster with admin user "postgres" (-U postgres), prompting to enter a password (-W), setting the password to md5 (-A md5):
/path/to/initdb -D /path/to/data/directory -W -A md5 -U postgres

Open the server for external connections:

vi /path/to/data/directory/postgresql.conf
# find the line with listen_addresses and edit as follows
listen_addresses = '*'

Edit the /path/to/data/directory/pg_hba.conf file to set which hosts/user are allowed to establish connections.

The install process creates a startup script in /etc/rc.d/init/postgresql-9.1. Edit the script as required (or create a custom script). Turn on the automatic startup:

chkconfig --level 345 postgresql-9.1 on

Try establishing an external connection. If you get a "Connection refused...accepting TCP/IP connections on port 5432?" error then the port is probably closed. Check that the firewall allows external TCP/IP connections (netstat -nap). You can open a port with lokkit or by configuring the iptables.

@amalagaura
Copy link

@bvajda
Copy link
Author

bvajda commented Dec 15, 2011

thanks, amalagaura! I updated the gist

@Hardcore-fs
Copy link

also this is bad:
chkconfig postgresql-9.1 on

It needs to be far more selective:

chkconfig --level 345 postgresql on

@bvajda
Copy link
Author

bvajda commented Apr 16, 2012

Right you are, Hardcore-fs! Thx!

@sylvesterjakubowski
Copy link

initdb is in:

/usr/pgsql-9.1/bin/initdb

In CentOS 6 after running the steps above, wasn't clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment