<!-- doc/src/sgml/runtime.sgml -->
<chapter id="runtime">
<title>Server Setup and Operation</title>
<para>
This chapter discusses how to set up and run the database server,
and its interactions with the operating system.
</para>
<para>
The directions in this chapter assume that you are working with
plain <productname>PostgreSQL</productname> without any additional
infrastructure, for example a copy that you built from source
according to the directions in the preceding chapters.
If you are working with a pre-packaged or vendor-supplied
version of <productname>PostgreSQL</productname>, it is likely that
the packager has made special provisions for installing and starting
the database server according to your system's conventions.
Consult the package-level documentation for details.
</para>
<sect1 id="postgres-user">
<title>The <productname>PostgreSQL</productname> User Account</title>
<indexterm>
<primary>postgres user</primary>
</indexterm>
<para>
As with any server daemon that is accessible to the outside world,
it is advisable to run <productname>PostgreSQL</productname> under a
separate user account. This user account should only own the data
that is managed by the server, and should not be shared with other
daemons. (For example, using the user <literal>nobody</literal> is a bad
idea.) In particular, it is advisable that this user account not own
the <productname>PostgreSQL</productname> executable files, to ensure
that a compromised server process could not modify those executables.
</para>
<para>
Pre-packaged versions of <productname>PostgreSQL</productname> will
typically create a suitable user account automatically during
package installation.
</para>
<para>
To add a Unix user account to your system, look for a command
<command>useradd</command> or <command>adduser</command>. The user
name <systemitem>postgres</systemitem> is often used, and is assumed
throughout this book, but you can use another name if you like.
</para>
</sect1>
<sect1 id="creating-cluster">
<title>Creating a Database Cluster</title>
<indexterm>
<primary>database cluster</primary>
</indexterm>
<indexterm>
<primary>data area</primary>
<see>database cluster</see>
</indexterm>
<para>
Before you can do anything, you must initialize a database storage
area on disk. We call this a <firstterm>database cluster</firstterm>.
(The <acronym>SQL</acronym> standard uses the term catalog cluster.) A
database cluster is a collection of databases that is managed by a
single instance of a running database server. After initialization, a
database cluster will contain a database named <literal>postgres</literal>,
which is meant as a default database for use by utilities, users and third
party applications. The database server itself does not require the
<literal>postgres</literal> database to exist, but many external utility
programs assume it exists. There are two more databases created within
each cluster during initialization, named <literal>template1</literal>
and <literal>template0</literal>. As the names suggest, these will be
used as templates for subsequently-created databases; they should not be
used for actual work. (See <xref linkend="managing-databases"/> for
information about creating new databases within a cluster.)
</para>
<para>
In file system terms, a database cluster is a single directory
under which all data will be stored. We call this the <firstterm>data
directory</firstterm> or <firstterm>data area</firstterm>. It is
completely up to you where you choose to store your data. There is no
default, although locations such as
<filename>/usr/local/pgsql/data</filename> or
<filename>/var/lib/pgsql/data</filename> are popular.
The data directory must be initialized before being used, using the program
<xref linkend="app-initdb"/><indexterm><primary>initdb</primary></indexterm>