• Last Modified
  • 10.05.2007

PostgreSQL Database Installation Notes

After spending couple of hours installing postgresql on Read Hat Linux, I thought I might share my notes with you. I also had to read many web sites and forums in order to get some answers and I decided to put it all in one page. So, let's go. I assume you have installed postgres on linux from source code. Just in case, STEP 1 - covers the basic install steps. STEP 2 - is auto startup service.

STEP 1: Installing from source code (from official postgres web site)

	./configure
	make
	su
	make install
	adduser postgres
	mkdir /usr/local/pgsql/data
	chown postgres /usr/local/pgsql/data
	su - postgres
	/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
	/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
	/usr/local/pgsql/bin/createdb test
	/usr/local/pgsql/bin/psql test

STEP 2: Configuring Auto StartUp Service (Red Hat Linux)

	Have a look in the /contrib/start-scripts/ directory in the source tree.
	There's a "linux" script - open it and see the comments in the script header.
	It explains what to do next, or you can follow next steps to skip it.

	I shall call "source_directory" - where you keep the source code.

	$ scp /source_directory/contrib/start-scripts/linux /etc/rc.d/init.d/postgresql
	$ chmod 755 /etc/rc.d/init.d/postgresql
	$ cd /etc/rc.d/init.d/
	$ chkconfig --add postgresql
	$ vi /etc/rc.d/init.d/postgresql

	Add the following two lines, including the hash (#) symbol, at the beginning of the /etc/rc.d/init.d/postgresql file:
	# chkconfig: 012345 99 02
	# description: PostgreSQL RDBMS

That's it, now if you reboot your server, PostgreSQL should start on server startup!



PROBLEM 1: If PostgreSQL does not start after server reboot.

Open system log and look for messages related to "postgresql"

	$ tail -100 /var/log/messages
	.......................
	Aug 14 18:00:33 apollo postgresql: Starting PostgreSQL:
	Aug 14 18:00:34 apollo su(pam_unix)[3993]: session opened for user postgres by (uid=0)
	Aug 14 18:00:34 apollo postgresql: Do you want to choose a different one? [n]
	.......................

SOLUTION 1: SELinux need to use 'runuser' not 'su'

Open and edit /etc/rc.d/init.d/postgresql file adding/replacing the following lines marked in bold



if [ -x /sbin/runuser ]
then
    SU=runuser
else
    SU=su
fi


# Parse command line parameters.
case $1 in
  start)
        $ECHO_N "Starting PostgreSQL: "$ECHO_C
        $SU - $PGUSER -c "$DAEMON start -D '$PGDATA' -s -l $PGLOG"
        echo "ok"
        ;;
  stop)
        echo -n "Stopping PostgreSQL: "
        $SU - $PGUSER -c "$DAEMON stop -D '$PGDATA' -s -m fast"
        echo "ok"
        ;;
  restart)
        echo -n "Restarting PostgreSQL: "
        $SU - $PGUSER -c "$DAEMON restart -D '$PGDATA' -s -m fast -l $PGLOG"
        echo "ok"
        ;;
  reload)
        echo -n "Reload PostgreSQL: "
        $SU - $PGUSER -c "$DAEMON reload -D '$PGDATA' -s"
        echo "ok"
        ;;
  status)
        $SU - $PGUSER -c "$DAEMON status -D '$PGDATA'"
        ;;
  *)
        # Print help
        echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
        exit 1
        ;;
esac

Useful to know

	# start|stop|restart the service manually
	$ service postgresql start
	$ service postgresql stop
	$ service postgresql restart

	# re-installing postgresql
	$ cd /source_directory/make uninstall

	# watching system startup log with last 100 messages
	$ tail -100 /var/log/messages
	...................................
	Aug 15 10:47:36 postgresql: Starting PostgreSQL:
	Aug 15 10:47:37 postgresql: ok
	...................................


Installing PostgreSQL Service on Windows XP/NT

Sometimes after re-installing Windows XP, you may want to restore PostgreSQL service without re-installing entire database from executable.

Note: If you choose 'fresh' installation over your existing /data/ folder, you will loose database and tables as the programm will re-cluster the data folder and we don't want that, do we?.

Instead we just want to register PostgreSQL service, so it starts each time Windows boots up and let me show you how to do it:

START: Let's assume you had your previous installation path: D:\apache2\pgsql

1) Go to Start Menu -> Run ... -> cmd
- Will open DOS command prompt

2) C:> SET PGDATA=D:\apache2\pgsql\data
- Set PostreSQL PGDATA Enviroment variable

3) C:> D:
4) D:> CD D:\apache2\pgsql\bin
5) D:> pg_ctl register -N PostgreSQL
6) D:> pg_ctl start

NOTE: pg_ctl --help
- Will show you all available options
  • Bookmark this page on Delicious
  • Bookmark this page on StumbleUpon
  • Digg this page on Digg
  • Submit this page on Reddit
  • Submit this page on Furl
  • Share this page on Facebook
  • Bookmark this page on Google
  • Bookmark this page on Yahoo
  • Search for links to this page on Technorati
  • Search for links to this page on IceRocket

Comments


Leave a comment (E-mail address never displayed)





2006-2007 @ SkyByte.net. All Rights Reserved xhtml 1.0 css