Before anyone can access the database you must start the database server. The database server is called postmaster. The postmaster must know where to find the data it is supposed to work on. This is done with the -D option. Thus, the simplest way to start the server is, for example,
$ postmaster -D /usr/local/pgsql/data
To start the postmaster in the background, use the usual shell syntax:
$ postmaster -D /usr/local/pgsql/data > logfile 2>&1 &
It is an extremely good idea to keep the server's stdout and stderr output around somewhere, as suggested here. It will help both for auditing purposes and to diagnose problems. (See Section 8.3 for a more thorough discussion of log file handling.)
The postmaster also takes a number of other command line options. For more information see the reference page and Section 3.4 below. In particular, in order for the server to accept TCP/IP connections (rather than just Unix domain socket ones), you must also specify the -i option.
pg_ctl start -l logfile
su -c 'pg_ctl start -D /usr/local/pgsql/data -l serverlog' postgres
For FreeBSD, take a 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/postmaster ]; then su - -c '/usr/local/pgsql/bin/pg_ctl start -l /var/postgresql/log -s' postgres echo -n ' postgresql' fi
/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data
On NetBSD, either use the FreeBSD or Linux start scripts, depending on preference, as an example and place the file at /usr/local/etc/rc.d/postgresql.
On Solaris, create a file called /etc/init.d/postgresql to contain the following single 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.
FATAL: StreamServerPort: bind() failed: Address already in use Is another postmaster already running on that port?
$ postmaster -i -p 666 FATAL: StreamServerPort: bind() failed: Permission denied Is another postmaster already running on that port?
IpcMemoryCreate: shmget(key=5440001, size=83918612, 01600) failed: Invalid argument FATAL 1: ShmemCreate: cannot create region
IpcSemaphoreCreate: semget(key=5440026, num=16, 01600) failed: No space left on device
Details about configuring System V IPC facilities are given in Section 3.5.1.
psql: could not connect to server: Connection refused Is the server running on host server.joe.com and accepting TCP/IP connections on port 5432?
Alternatively, you'll get this when attempting Unix-socket communication to a local postmaster:
psql: could not connect to server: Connection refused Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
The last line is useful in verifying that the client is trying to connect where it is supposed to. If there is in fact no postmaster running there, the kernel error message will typically be either Connection refused or No such file or directory, as illustrated. (It is particularly important to realize that Connection refused in this context does not mean that the postmaster got your connection request and rejected it -- that case will produce a different message, as shown in Section 4.3.) Other error messages such as Connection timed out may indicate more fundamental problems, like lack of network connectivity.