./configure
gmake
su
gmake install
adduser postgres -s /sbin/nologin
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su -s /bin/sh postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 &
You may wish to create a database and assign a specific user:
createuser cfuser
createdb mydatabase -U cfuser
You may also wish to connect to Postgres over TCP from another host. To make Postgres listen on a TCP socket (default port 5432), start the postmaster with the -i option. To allow access from other hosts, you'll need to edit the file {postgres_home}/data/pg_hba.conf, for which you can find the documentation here. Several networks can be added to the authorization list such as this example:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 10.1.0.0/16 trust
host all all 192.168.1.0/24 trust
Installing from source means that you must start and stop the database by su'ing to the postgres user and running the postmaster to start it or pg_ctl to stop it. Further, when rebooting the machine, the Postgres database won't start up automatically as it would if it had been installed from the RPM (Postgres server RPM is not available from the download page).
To make my life easier when managing these Postgres databases, I've created the following pgsqld script which can be copied to the {postgres_home}/bin/ directory:
#!/bin/sh
# chkconfig: 345 89 13
# description: starts the PostgreSQL database server
# author: Steven Erat (serat -/at/- adobe -/dot/- com)
# caveat emptor: This script is released without warranty and
and is not guaranteed to work in all cases.
The user assumes all liability for using this script.
ID=`id -u`
if [ ! $ID -eq 0 ]; then
echo "You must be root to start or stop PostgreSQL database server"
exit 1
fi
PGHOME=/usr/local/pgsql
PGLOG=$PGHOME/logs/pglog
pgstart() {
pglisten=`netstat -an | grep PGSQL | cut -d'.' -f4`
if [ ! "$pglisten" = "" ]; then
echo " PostgreSQL database is already running and listening on port $pglisten "
exit 1
fi
echo " Starting the PostgreSQL database server ..."
su -s /bin/sh postgres -c "$PGHOME/bin/postmaster -D $PGHOME/data -i >> $PGLOG 2>&1 &"
sleep 5
pglisten=`netstat -an | grep PGSQL | cut -d'.' -f4`
if [ -n $pglisten ]; then
echo " PostgreSQL database is listening on port $pglisten "
fi
}
pgstop() {
pglisten=`netstat -an | grep PGSQL | cut -d'.' -f4`
if [ -z "$pglisten" ]; then
echo " PostgreSQL isn't running "
else
echo " Stopping the PostgreSQL database server that is listening on port $pglisten ..."
su -s /bin/sh postgres -c "$PGHOME/bin/pg_ctl stop -D $PGHOME/data -m fast >> $PGLOG 2>&1 &"
sleep 4
pglisten=`netstat -an | grep PGSQL | cut -d'.' -f4`
if [ ! "$pglisten" = "" ]; then
echo " !!! PostgreSQL database has NOT been stopped !!!"
else
echo " PostgreSQL database has been stopped! "
fi
fi
}
pgstatus() {
echo " `su -s /bin/sh postgres -c "$PGHOME/bin/postmaster --version"`"
pglisten=`netstat -an | grep PGSQL | cut -d'.' -f4`
if [ -z "$pglisten" ]; then
echo " PostgreSQL isn't running "
else
echo " PostgreSQL database server is running and listening on port $pglisten"
fi
echo " See $PGLOG for PostgreSQL logging"
}
ARG=$1
case $ARG in
start)
pgstart
;;
stop)
pgstop
;;
restart)
pgstop
pgstart
;;
status)
pgstatus
;;
*)
echo " Usage:$0 (start|stop|restart|status)"
;;
esac
exit 0
To use the script, you can make it executable and then run it with the arguments of start, stop, restart, or status (i.e. ./pgsqld start).
To make the database start on a system boot or to add the convenience of controlling the database with the service command (i.e. service pgsqld start), make a symbolic link to the pgsqld script from /etc/init.d, then run chkconfig to add it as a service:
cd /etc/init.d
ln -s /usr/local/pgsql/bin/pgsqld pgsqld
chkconfig --add pgsqld
chkconfig --list pgsqld
pgsqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Postgres will now start after a reboot, and from any system directory root can use the service command to control the database:
[root@RHEL4QA1 ~]# service pgsqld start
Starting the PostgreSQL database server ...
PostgreSQL database is listening on port 5432
[root@RHEL4QA1 ~]# service pgsqld status
postmaster (PostgreSQL) 8.1.4
PostgreSQL database server is running and listening on port 5432
See /usr/local/pgsql/logs/pglog for PostgreSQL logging
[root@RHEL4QA1 ~]# service pgsqld stop
Stopping the PostgreSQL database server that is listening on port 5432 ...
PostgreSQL database has been stopped!
[root@RHEL4QA1 ~]# service pgsqld status
postmaster (PostgreSQL) 8.1.4
PostgreSQL isn't running
See /usr/local/pgsql/logs/pglog for PostgreSQL logging