The SysV script will allow the graceful control of the PostgreSQL database through the use of the SysV runlevel
system. The SysV script can be used for starting, stopping, and status-checking of PostgreSQL. It is known to work with
most Red Hat based versions of Linux, including Mandrake; however, it should work with other SysV systems (e.g., UnixWare,
Solaris, etc.) with little modification. The script is named
. To use it, you will first need to
script to your
directory. You may require root access to do
First, change to the directory where you unpacked the PostgreSQL source. In our case, the path to that directory is
. Then, issue a
command to copy the script
directory. Example 2-19 demonstrates how to do this on a Red Hat Linux system.
Example 2-19. Copying the linux script
su -c "cp contrib/start-scripts/linux /etc/rc.d/init.d/postgresql"
Example 2-19 arbitrarily re-names the new copy to
; you may
call it whatever you prefer, though it is typically named either
You will need to make the script file
after copying it. To do so, use the command
shown in Example 2-20.
Example 2-20. Making the linux script executable
su -c "chmod a+x /etc/rc.d/init.d/postgresql"
There are no additional requirements to use the SysV script with Red Hat, if you do not intend on using it to start
PostgreSQL automatically (i.e., if you wish to use the script manually). However, if you do wish for the script to startup
PostgreSQL automatically when the machine boots up (or changes runlevels), you will need to have the
program installed. If
is installed, you will also need to add
the following two lines, including the hash (#) symbol, at the beginning of the
# chkconfig: 345 85 15
# description: PostgreSQL RDBMS
These example numbers should work on your system; however, it is good to know what role they perform. The first group
of numbers (345) represent which runlevels PostgreSQL should be started at. The example
shown would start PostgreSQL at runlevels 3, 4, and 5. The second group of numbers (85)
represent the order in which PostgreSQL should be started within that runlevel, relative to other programs. You should
probably keep the second number high, to indicate that it should be started later in the runlevel. The third number
(15) represents the order in which PostgreSQL should be shutdown. It is a good idea to
keep this number low, representing a shutdown order that is inverse from the startup order. As previously mentioned, the
script should work on your system with the numbers provided, but you can change them if it is necessary.
Once these two lines have been added to the script, you can use the commands shown in Example 2-21 on Red Hat and Mandrake Linux distributions to start the PostgreSQL database. Be sure
to execute these as the
Example 2-21. Starting PostgreSQL with the SysV script
service postgresql start
Starting PostgreSQL: ok
service postgresql stop
Stopping PostgreSQL: ok
Note: The SysV script logs redirects all PostgreSQL debugging output to
, by default.