PostgreSQL on Linux Server (RedHat/Fedora/CentOS)

 

Source Installing PostgreSQL on RedHat/Fedora/CentOS Linux

** Please Note: All steps are done as 'root'

First, make sure the following packages are installed.

yum install -y yum-fastestmirror bison-devel readline-devel zlib-devel openssl-devel wget
yum groupinstall -y 'Development Tools'

 

 Make a directory to contain the source files.  This directory may already exist.

mkdir -p /usr/local/src

 

Change into the source directory.

cd /usr/local/src

 

Download PostgreSQL 8.3.7 from postgresql.org.

wget http://wwwmaster.postgresql.org/redir/198/h/source/v8.3.7/postgresql-8.3... -O /usr/local/src/

 

 Extract the source code.

tar zxvf postgresql-8.3.7.tar.gz

 

Change into to postgres source directory

cd postgresql-8.3.7

 

Configure postgres with OpenSSL support

./configure --prefix=/usr/local/pgsql --with-openssl --with-pgport=5432

 

Run make.

make

 

Run make install.

make install

 

Change into the contrib directory to make additional items.

cd /usr/local/src/postgresql-8.3.7/contrib/

 

Run make all.

make all

 

Run make install.

make install

 

Copy the startup script to the proper location.

cp /usr/local/src/postgresql-8.3.7/contrib/start-scripts/linux /etc/init.d/postgresql

 

Make the startup script executable.

chmod 775 /etc/init.d/postgresql

 

Add a postgres user.

adduser postgres

 

Add the path information to the shell, so postgres commands can be more readily accessed.

echo 'PATH=$PATH:/usr/local/pgsql/bin' > /etc/profile.d/postgresql.sh
echo 'export PATH;' >> /etc/profile.d/postgresql.sh

 

Make it executable.

chmod 775 /etc/profile.d/postgresql.sh

 

Make a logging directory.

mkdir -p /var/log/pgsql

 

Make a file to log to.

touch /var/log/pgsql/pgsql.log

 

Make sure postgres can read/write to it.

chown -R postgres:postgres /var/log/pgsql/

 

Make a data directory, this can be named anything, but 'data' is most common.  This is your postgres database cluster.

mkdir /usr/local/pgsql/data

 

Change ownership of the data directory to postgres.

chown -R postgres:postgres /usr/local/pgsql/data

 

Execute the initdb script.  This prepares the cluster for use.

sudo -u postgres /usr/local/pgsql/bin/initdb -U postgres -E=UTF8 /usr/local/pgsql/data

 

Modify your /usr/local/pgsql/data/postgresql.conf to allow you installation to listen for remote connections.
Change the listen_addresses and port parameters to:
Remove the leading '#' marks also.

listen_addresses = '*'
port = 5432

 

Add postgres to the startup routine.

chkconfig --add postgresql

 

Start postgres.

service postgresql start

 

Load some additional functions into template1 of the postgres install.

/usr/local/pgsql/bin/psql -U postgres -p 5432 template1 < /usr/local/pgsql/share/contrib/adminpack.sql
/usr/local/pgsql/bin/psql -U postgres -p 5432 template1 < /usr/local/pgsql/share/contrib/pgcrypto.sql
/usr/local/pgsql/bin/psql -U postgres -p 5432 template1 < /usr/local/pgsql/share/contrib/pgstattuple.sql
/usr/local/pgsql/bin/psql -U postgres -p 5432 template1 < /usr/local/pgsql/share/contrib/sslinfo.sql

DONE.