2 <TITLE>Architecture</TITLE>
4 <Sect1 id="arch-pg-concepts">
5 <Title><ProductName>Postgres</ProductName> Architectural Concepts</Title>
8 Before we begin, you should understand the basic
9 <ProductName>Postgres</ProductName> system architecture. Understanding how the
10 parts of <ProductName>Postgres</ProductName> interact will make the next chapter
12 In database jargon, <ProductName>Postgres</ProductName> uses a simple "process
13 per-user" client/server model. A <ProductName>Postgres</ProductName> session
14 consists of the following cooperating Unix processes (programs):
19 A supervisory daemon process (the <Application>postmaster</Application>),
24 the user's frontend application (e.g., the <Application>psql</Application> program), and
29 one or more backend database servers (the <Application>postgres</Application> process itself).
35 A single <Application>postmaster</Application> manages a given collection of
36 databases on a single host. Such a collection of
37 databases is called a cluster (of databases). A frontend
38 application that wishes to access a given database
39 within a cluster makes calls to an interface library (eg, libpq)
40 that is linked into the application.
41 The library sends user requests over the network to the
42 <Application>postmaster</Application>
43 (<XRef LinkEnd="PGARCH-CONNECTIONS">(a)),
44 which in turn starts a new backend server process
45 (<XRef LinkEnd="PGARCH-CONNECTIONS">(b))
47 <figure id="PGARCH-CONNECTIONS">
48 <title>How a connection is established</title>
52 <imagedata align="center" fileref="connections">
57 and connects the frontend process to the new server
58 (<XRef LinkEnd="PGARCH-CONNECTIONS">(c)).
59 From that point on, the frontend process and the backend
60 server communicate without intervention by the
61 <Application>postmaster</Application>. Hence, the <Application>postmaster</Application> is always running, waiting
62 for connection requests, whereas frontend and backend processes
63 come and go. The <FileName>libpq</FileName> library allows a single
64 frontend to make multiple connections to backend processes.
65 However, each backend process is a single-threaded process that can
66 only execute one query at a time; so the communication over any one
67 frontend-to-backend connection is single-threaded.
71 One implication of this architecture is that the
72 <Application>postmaster</Application> and the backend always run on the
73 same machine (the database server), while the frontend
74 application may run anywhere. You should keep this
76 because the files that can be accessed on a client
77 machine may not be accessible (or may only be accessed
78 using a different path name) on the database server
83 You should also be aware that the <Application>postmaster</Application> and
84 postgres servers run with the user-id of the <ProductName>Postgres</ProductName>
86 Note that the <ProductName>Postgres</ProductName> superuser does not
87 have to be any particular user (e.g., a user named
88 <literal>postgres</literal>), although many systems are installed that way.
89 Furthermore, the <ProductName>Postgres</ProductName> superuser should
90 definitely not be the Unix superuser, <literal>root</literal>!
91 It is safest if the <ProductName>Postgres</ProductName> superuser is an
92 ordinary, unprivileged user so far as the surrounding Unix system is
94 In any case, all files relating to a database should belong to
95 this <ProductName>Postgres</ProductName> superuser.