Skip to content

Commit bae2bb1

Browse files
poloboCommitfest Bot
authored andcommitted
doc: Explain use of symbolic linking for pg_wal
1 parent 03fbb08 commit bae2bb1

File tree

3 files changed

+54
-23
lines changed

3 files changed

+54
-23
lines changed

doc/src/sgml/ref/initdb.sgml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,10 @@ PostgreSQL documentation
411411
<term><option>--waldir=<replaceable class="parameter">directory</replaceable></option></term>
412412
<listitem>
413413
<para>
414-
This option specifies the directory where the write-ahead log
415-
should be stored.
414+
This option specifies the directory in which to store write-ahead log files.
415+
See <xref linkend="wal-internals-relocation"/> for more information.
416+
The specified path must be absolute. It will be created, including parents,
417+
if missing. Otherwise, the directory must be empty.
416418
</para>
417419
</listitem>
418420
</varlistentry>
@@ -695,6 +697,7 @@ PostgreSQL documentation
695697
<command>initdb</command> can also be invoked via
696698
<command>pg_ctl initdb</command>.
697699
</para>
700+
698701
</refsect1>
699702

700703
<refsect1>

doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,11 @@ PostgreSQL documentation
324324
<term><option>--waldir=<replaceable class="parameter">waldir</replaceable></option></term>
325325
<listitem>
326326
<para>
327-
Sets the directory to write WAL (write-ahead log) files to.
328-
By default WAL files will be placed in
329-
the <filename>pg_wal</filename> subdirectory of the target
330-
directory, but this option can be used to place them elsewhere.
331-
<replaceable>waldir</replaceable> must be an absolute path.
332-
As with the main target directory,
333-
<replaceable>waldir</replaceable> need not exist already, but if
334-
it does exist it must be empty.
335-
This option can only be specified when
336-
the backup is in plain format.
327+
This option specifies the directory in which to store write-ahead log files.
328+
See <xref linkend="wal-internals-relocation"/> for more information.
329+
The specified path must be absolute. It will be created, including parents,
330+
if missing. Otherwise, the directory must be empty.
331+
This option can only be specified when the backup is in plain format.
337332
</para>
338333
</listitem>
339334
</varlistentry>

doc/src/sgml/wal.sgml

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,10 @@
877877
</para>
878878

879879
<para>
880-
<acronym>WAL</acronym> files are stored in the directory
881-
<filename>pg_wal</filename> under the data directory, as a set of
882-
segment files, normally each 16 MB in size (but the size can be changed
880+
<acronym>WAL</acronym> files are written to the directory
881+
<filename>pg_wal</filename> under the data directory
882+
(see <xref linkend="wal-internals-relocation"/>).
883+
Each file, also called a segment file, is 16 MB in size (but the size can be changed
883884
by altering the <option>--wal-segsize</option> <application>initdb</application> option). Each segment is
884885
divided into pages, normally 8 kB each (this size can be changed via the
885886
<option>--with-wal-blocksize</option> configure option). The WAL record headers
@@ -891,14 +892,6 @@
891892
available stock of numbers.
892893
</para>
893894

894-
<para>
895-
It is advantageous if the WAL is located on a different disk from the
896-
main database files. This can be achieved by moving the
897-
<filename>pg_wal</filename> directory to another location (while the server
898-
is shut down, of course) and creating a symbolic link from the
899-
original location in the main data directory to the new location.
900-
</para>
901-
902895
<para>
903896
The aim of <acronym>WAL</acronym> is to ensure that the log is
904897
written before database records are altered, but this can be subverted by
@@ -940,4 +933,44 @@
940933
</para>
941934
</sect1>
942935

936+
<sect1 id="wal-internals-relocation" xreflabel="WAL Directory Relocation">
937+
<title>Relocating the <acronym>WAL</acronym> Directory</title>
938+
<para>
939+
The data directory of a <productname>PostgreSQL</productname> cluster always
940+
contains an entry named <filename>pg_wal</filename>. This is where
941+
<acronym>WAL</acronym> files are written. If this entry is a directory
942+
then the files will be physically stored within the same filesystem as the
943+
data directory. However, the entry can be a symbolic link, in which case
944+
the files will be stored in the filesystem location the link points to.
945+
</para>
946+
<para>
947+
To create a symbolic link during the creation of a cluster, using either
948+
<application><xref linkend="app-initdb"/></application> or
949+
<application><xref linkend="app-pgbasebackup"/></application>, specify
950+
the <option>--waldir</option> option. On an existing, but not running,
951+
cluster use operating system commands to move the contents of the
952+
<filename>pg_wal</filename> directory to the new location, remove the
953+
empty directory, and create the symbolic link named <filename>pg_wal</filename>
954+
pointing to the new location.
955+
</para>
956+
<para>
957+
One reason for relocating the <acronym>WAL</acronym> directory is to
958+
ensure that even if the data directory runs out of space the writing of
959+
<acronym>WAL</acronym> files can continue. For this, the chosen location must
960+
be on a different filesystem. Similarly, the optimal filesystem
961+
characteristics for the data directory, which involves considerable random
962+
read and write <acronym>I/O</acronym>, are different than those for the
963+
<acronym>WAL</acronym>, which mainly requires sequential write
964+
<acronym>I/O</acronym>. Another reason is to increase the effective
965+
<acronym>I/O</acronym> capacity of the cluster by leveraging a separate
966+
physical disk for the <acronym>WAL</acronym> files.
967+
</para>
968+
<para>
969+
If the symbolic link does point to another filesystem, or for some other
970+
reason involves a mount point on the filesystem the data directory is located
971+
on, create a directory under the mount point and use that as the target of
972+
the symbolic link.
973+
</para>
974+
</sect1>
975+
943976
</chapter>

0 commit comments

Comments
 (0)