ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target
</programlisting>
Using <literal>Type=notify</literal> requires that the server binary was
built with <literal>configure --with-systemd</literal>.
</para>
<para>
Consider carefully the timeout
setting. <application>systemd</application> has a default timeout of 90
seconds as of this writing and will kill a process that does not report
readiness within that time. But a <productname>PostgreSQL</productname>
server that might have to perform crash recovery at startup could take
much longer to become ready. The suggested value
of <literal>infinity</literal> disables the timeout logic.
</para>
</listitem>
<listitem>
<para>
On <productname>NetBSD</productname>, use either the
<productname>FreeBSD</productname> or
<productname>Linux</productname> start scripts, depending on
preference.
<indexterm><primary>NetBSD</primary><secondary>start script</secondary></indexterm>
</para>
</listitem>
<listitem>
<para>
On <productname>Solaris</productname>, create a file called
<filename>/etc/init.d/postgresql</filename> that contains
the following line:
<indexterm><primary>Solaris</primary><secondary>start script</secondary></indexterm>
<programlisting>
su - postgres -c "/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data"
</programlisting>
Then, create a symbolic link to it in <filename>/etc/rc3.d</filename> as
<filename>S99postgresql</filename>.
</para>
</listitem>
</itemizedlist>
</para>
<para>
While the server is running, its
<acronym>PID</acronym> is stored in the file
<filename>postmaster.pid</filename> 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.
</para>
<sect2 id="server-start-failures">
<title>Server Start-up Failures</title>
<para>
There are several common reasons the server might fail to
start. Check the server's log file, or start it by hand (without
redirecting standard output or standard error) and see what error
messages appear. Below we explain some of the most common error
messages in more detail.
</para>
<para>
<screen>
LOG: could not bind IPv4 address "127.0.0.1": Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
FATAL: could not create any TCP/IP sockets
</screen>
This usually means just what it suggests: you tried to start
another server on the same port where one is already running.
However, if the kernel error message is not <computeroutput>Address
already in use</computeroutput> or some variant of that, there might
be a different problem. For example, trying to start a server
on a reserved port number might draw something like:
<screen>
$ <userinput>postgres -p 666</userinput>
LOG: could not bind IPv4 address "127.0.0.1": Permission denied
HINT: Is another postmaster already running on port 666? If not, wait a few seconds and retry.
FATAL: could not create any TCP/IP sockets
</screen>
</para>
<para>
A message like:
<screen>
FATAL: could not create shared memory segment: Invalid argument
DETAIL: Failed system call was shmget(key=5440001, size=4011376640, 03600).
</screen>
probably means your kernel's limit on the size of shared memory is
smaller than the work area <productname>PostgreSQL</productname>
is trying to create (4011376640 bytes in this example).
This is only likely to happen if you have set <literal>shared_memory_type</literal>
to <literal>sysv</literal>. In that case, you
can try starting