|PostgreSQL Reference Manual - Volume 3 - Server Administration Guide|
by The PostgreSQL Global Development Group
Paperback (6"x9"), 204 pages
RRP £13.95 ($24.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
3.3 Starting the Database Server
Before anyone can access the database, you must start the database
server. The database server program is called
postgres program must know where to
find the data it is supposed to use. This is done with the
-D option. Thus, the simplest way to start the
$ postgres -D /usr/local/pgsql/data
which will leave the server running in the foreground. This must be
done while logged into the PostgreSQL user
-D, the server will try to use
the data directory named by the environment variable
If that variable is not provided either, it will fail.
Normally it is better to start
postgres in the
background. For this, use the usual shell syntax:
$ postgres -D /usr/local/pgsql/data >logfile 2>&1 &
It is important to store the server's
stderr output somewhere, as shown above. It will help
for auditing purposes and to diagnose problems. (See section 9.3 Log File Maintenance for a more thorough discussion of log
This shell syntax can get tedious quickly. Therefore the wrapper
is provided to simplify some tasks. For example:
pg_ctl start -l logfile
will start the server in the background and put the output into the
named log file. The
-D option has the same meaning
here as for
is also capable of stopping the server.
Normally, you will want to start the database server when the computer boots. Autostart scripts are operating-system-specific. There are a few distributed with PostgreSQL in the ‘contrib/start-scripts’ directory. Installing one will require root privileges.
Different systems have different conventions for starting up daemons
at boot time. Many systems have a file
‘/etc/rc.d/rc.local’. Others use
‘rc.d’ directories. Whatever you do, the server must be
run by the PostgreSQL user account
and not by root or any other user. Therefore you
probably should form your commands using
su -c '...'
postgres. For example:
su -c 'pg_ctl start -D /usr/local/pgsql/data -l serverlog' postgres
Here are a few more operating-system-specific suggestions. (In each case be sure to use the proper installation directory and user name where we show generic values.)
- For FreeBSD, look at the file ‘contrib/start-scripts/freebsd’ in the PostgreSQL source distribution.
On OpenBSD, add the following lines
to the file ‘/etc/rc.local’:
if [ -x /usr/local/pgsql/bin/pg_ctl -a -x /usr/local/pgsql/bin/postgres ]; then su - -c '/usr/local/pgsql/bin/pg_ctl start -l /var/postgresql/log -s' postgres echo -n ' postgresql' fi
On Linux systems either add
/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/datato ‘/etc/rc.d/rc.local’ or look at the file ‘contrib/start-scripts/linux’ in the PostgreSQL source distribution.
- On NetBSD, either use the FreeBSD or Linux start scripts, depending on preference.
On Solaris, create a file called
‘/etc/init.d/postgresql’ that contains
the following line:
su - postgres -c "/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data"Then, create a symbolic link to it in ‘/etc/rc3.d’ as ‘S99postgresql’.
While the server is running, its PID is stored in the file ‘postmaster.pid’ in the data directory. This is used to prevent multiple server instances from running in the same data directory and can also be used for shutting down the server.
|ISBN 0954612043||PostgreSQL Reference Manual - Volume 3 - Server Administration Guide||See the print edition|