|
4 | 4 | <title>Server Setup and Operation</title>
|
5 | 5 |
|
6 | 6 | <para>
|
7 |
| - This chapter discusses how to set up and run the database server |
| 7 | + This chapter discusses how to set up and run the database server, |
8 | 8 | and its interactions with the operating system.
|
9 | 9 | </para>
|
10 | 10 |
|
| 11 | + <para> |
| 12 | + The directions in this chapter assume that you are working with |
| 13 | + plain <productname>PostgreSQL</productname> without any additional |
| 14 | + infrastructure, for example a copy that you built from source |
| 15 | + according to the directions in the preceding chapters. |
| 16 | + If you are working with a pre-packaged or vendor-supplied |
| 17 | + version of <productname>PostgreSQL</productname>, it is likely that |
| 18 | + the packager has made special provisions for installing and starting |
| 19 | + the database server according to your system's conventions. |
| 20 | + Consult the package-level documentation for details. |
| 21 | + </para> |
| 22 | + |
11 | 23 | <sect1 id="postgres-user">
|
12 | 24 | <title>The <productname>PostgreSQL</productname> User Account</title>
|
13 | 25 |
|
|
21 | 33 | separate user account. This user account should only own the data
|
22 | 34 | that is managed by the server, and should not be shared with other
|
23 | 35 | daemons. (For example, using the user <literal>nobody</literal> is a bad
|
24 |
| - idea.) It is not advisable to install executables owned by this |
25 |
| - user because compromised systems could then modify their own |
26 |
| - binaries. |
| 36 | + idea.) In particular, it is advisable that this user account not own |
| 37 | + the <productname>PostgreSQL</productname> executable files, to ensure |
| 38 | + that a compromised server process could not modify those executables. |
| 39 | + </para> |
| 40 | + |
| 41 | + <para> |
| 42 | + Pre-packaged versions of <productname>PostgreSQL</productname> will |
| 43 | + typically create a suitable user account automatically during |
| 44 | + package installation. |
27 | 45 | </para>
|
28 | 46 |
|
29 | 47 | <para>
|
|
71 | 89 | completely up to you where you choose to store your data. There is no
|
72 | 90 | default, although locations such as
|
73 | 91 | <filename>/usr/local/pgsql/data</filename> or
|
74 |
| - <filename>/var/lib/pgsql/data</filename> are popular. To initialize a |
75 |
| - database cluster, use the command <xref |
76 |
| - linkend="app-initdb"/>,<indexterm><primary>initdb</primary></indexterm> which is |
77 |
| - installed with <productname>PostgreSQL</productname>. The desired |
78 |
| - file system location of your database cluster is indicated by the |
| 92 | + <filename>/var/lib/pgsql/data</filename> are popular. |
| 93 | + The data directory must be initialized before being used, using the program |
| 94 | + <xref linkend="app-initdb"/><indexterm><primary>initdb</primary></indexterm> |
| 95 | + which is installed with <productname>PostgreSQL</productname>. |
| 96 | + </para> |
| 97 | + |
| 98 | + <para> |
| 99 | + If you are using a pre-packaged version |
| 100 | + of <productname>PostgreSQL</productname>, it may well have a specific |
| 101 | + convention for where to place the data directory, and it may also |
| 102 | + provide a script for creating the data directory. In that case you |
| 103 | + should use that script in preference to |
| 104 | + running <command>initdb</command> directly. |
| 105 | + Consult the package-level documentation for details. |
| 106 | + </para> |
| 107 | + |
| 108 | + <para> |
| 109 | + To initialize a database cluster manually, |
| 110 | + run <command>initdb</command> and specify the desired |
| 111 | + file system location of the database cluster with the |
79 | 112 | <option>-D</option> option, for example:
|
80 | 113 | <screen>
|
81 | 114 | <prompt>$</prompt> <userinput>initdb -D /usr/local/pgsql/data</userinput>
|
@@ -309,10 +342,22 @@ postgres$ <userinput>initdb -D /usr/local/pgsql/data</userinput>
|
309 | 342 | Before anyone can access the database, you must start the database
|
310 | 343 | server. The database server program is called
|
311 | 344 | <command>postgres</command>.<indexterm><primary>postgres</primary></indexterm>
|
312 |
| - The <command>postgres</command> program must know where to |
313 |
| - find the data it is supposed to use. This is done with the |
314 |
| - <option>-D</option> option. Thus, the simplest way to start the |
315 |
| - server is: |
| 345 | + </para> |
| 346 | + |
| 347 | + <para> |
| 348 | + If you are using a pre-packaged version |
| 349 | + of <productname>PostgreSQL</productname>, it almost certainly includes |
| 350 | + provisions for running the server as a background task according to the |
| 351 | + conventions of your operating system. Using the package's |
| 352 | + infrastructure to start the server will be much less work than figuring |
| 353 | + out how to do this yourself. Consult the package-level documentation |
| 354 | + for details. |
| 355 | + </para> |
| 356 | + |
| 357 | + <para> |
| 358 | + The bare-bones way to start the server manually is just to invoke |
| 359 | + <command>postgres</command> directly, specifying the location of the |
| 360 | + data directory with the <option>-D</option> option, for example: |
316 | 361 | <screen>
|
317 | 362 | $ <userinput>postgres -D /usr/local/pgsql/data</userinput>
|
318 | 363 | </screen>
|
@@ -364,7 +409,7 @@ pg_ctl start -l logfile
|
364 | 409 | <secondary>starting the server during</secondary>
|
365 | 410 | </indexterm>
|
366 | 411 | Autostart scripts are operating-system-specific.
|
367 |
| - There are a few distributed with |
| 412 | + There are a few example scripts distributed with |
368 | 413 | <productname>PostgreSQL</productname> in the
|
369 | 414 | <filename>contrib/start-scripts</filename> directory. Installing one will require
|
370 | 415 | root privileges.
|
@@ -1481,9 +1526,23 @@ $ <userinput>cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages</userinp
|
1481 | 1526 | </indexterm>
|
1482 | 1527 |
|
1483 | 1528 | <para>
|
1484 |
| - There are several ways to shut down the database server. You control |
1485 |
| - the type of shutdown by sending different signals to the supervisor |
| 1529 | + There are several ways to shut down the database server. |
| 1530 | + Under the hood, they all reduce to sending a signal to the supervisor |
1486 | 1531 | <command>postgres</command> process.
|
| 1532 | + </para> |
| 1533 | + |
| 1534 | + <para> |
| 1535 | + If you are using a pre-packaged version |
| 1536 | + of <productname>PostgreSQL</productname>, and you used its provisions |
| 1537 | + for starting the server, then you should also use its provisions for |
| 1538 | + stopping the server. Consult the package-level documentation for |
| 1539 | + details. |
| 1540 | + </para> |
| 1541 | + |
| 1542 | + <para> |
| 1543 | + When managing the server directly, you can control the type of shutdown |
| 1544 | + by sending different signals to the <command>postgres</command> |
| 1545 | + process: |
1487 | 1546 |
|
1488 | 1547 | <variablelist>
|
1489 | 1548 | <varlistentry>
|
@@ -1620,6 +1679,10 @@ $ <userinput>kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`</userinput
|
1620 | 1679 | is to dump and reload the database, though this can be slow. A
|
1621 | 1680 | faster method is <xref linkend="pgupgrade"/>. Replication methods are
|
1622 | 1681 | also available, as discussed below.
|
| 1682 | + (If you are using a pre-packaged version |
| 1683 | + of <productname>PostgreSQL</productname>, it may provide scripts to |
| 1684 | + assist with major version upgrades. Consult the package-level |
| 1685 | + documentation for details.) |
1623 | 1686 | </para>
|
1624 | 1687 |
|
1625 | 1688 | <para>
|
|
0 commit comments