|  | 
| 877 | 877 |   </para> | 
| 878 | 878 | 
 | 
| 879 | 879 |   <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 | 
| 883 | 884 |    by altering the <option>--wal-segsize</option> <application>initdb</application> option).  Each segment is | 
| 884 | 885 |    divided into pages, normally 8 kB each (this size can be changed via the | 
| 885 | 886 |    <option>--with-wal-blocksize</option> configure option).  The WAL record headers | 
|  | 
| 891 | 892 |    available stock of numbers. | 
| 892 | 893 |   </para> | 
| 893 | 894 | 
 | 
| 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 |  | - | 
| 902 | 895 |   <para> | 
| 903 | 896 |    The aim of <acronym>WAL</acronym> is to ensure that the log is | 
| 904 | 897 |    written before database records are altered, but this can be subverted by | 
|  | 
| 940 | 933 |   </para> | 
| 941 | 934 |  </sect1> | 
| 942 | 935 | 
 | 
|  | 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 | + | 
| 943 | 976 | </chapter> | 
0 commit comments