Skip to content

Commit 5f56933

Browse files
committed
Restore archive_command documentation
Commit 5ef1eef, which added archive_library, purged most mentions of archive_command from the documentation. This is inappropriate, since archive_command is still a feature in use and users will want to see information about it. This restores all the removed mentions and rephrases things so that archive_command and archive_library are presented as alternatives of each other. Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://www.postgresql.org/message-id/9366d634-a917-85a9-4991-b2a4859edaf9@enterprisedb.com
1 parent ade925e commit 5f56933

File tree

5 files changed

+86
-79
lines changed

5 files changed

+86
-79
lines changed

doc/src/sgml/backup.sgml

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ tar -cf backup.tar /usr/local/pgsql/data
593593
provide the database administrator with flexibility,
594594
<productname>PostgreSQL</productname> tries not to make any assumptions about how
595595
the archiving will be done. Instead, <productname>PostgreSQL</productname> lets
596-
the administrator specify an archive library to be executed to copy a
596+
the administrator specify a shell command or an archive library to be executed to copy a
597597
completed segment file to wherever it needs to go. This could be as simple
598598
as a shell command that uses <literal>cp</literal>, or it could invoke a
599599
complex C function &mdash; it's all up to you.
@@ -603,13 +603,15 @@ tar -cf backup.tar /usr/local/pgsql/data
603603
To enable WAL archiving, set the <xref linkend="guc-wal-level"/>
604604
configuration parameter to <literal>replica</literal> or higher,
605605
<xref linkend="guc-archive-mode"/> to <literal>on</literal>,
606-
and specify the library to use in the <xref
606+
specify the shell command to use in the <xref
607+
linkend="guc-archive-command"/> configuration parameter
608+
or specify the library to use in the <xref
607609
linkend="guc-archive-library"/> configuration parameter. In practice
608610
these settings will always be placed in the
609611
<filename>postgresql.conf</filename> file.
610-
One simple way to archive is to set <varname>archive_library</varname> to
611-
an empty string and to specify a shell command in
612-
<xref linkend="guc-archive-command"/>.
612+
</para>
613+
614+
<para>
613615
In <varname>archive_command</varname>,
614616
<literal>%p</literal> is replaced by the path name of the file to
615617
archive, while <literal>%f</literal> is replaced by only the file name.
@@ -634,17 +636,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
634636
</para>
635637

636638
<para>
637-
Another way to archive is to use a custom archive module as the
638-
<varname>archive_library</varname>. Since such modules are written in
639-
<literal>C</literal>, creating your own may require considerably more effort
640-
than writing a shell command. However, archive modules can be more
641-
performant than archiving via shell, and they will have access to many
642-
useful server resources. For more information about archive modules, see
643-
<xref linkend="archive-modules"/>.
644-
</para>
645-
646-
<para>
647-
The archive library will be executed under the ownership of the same
639+
The archive command will be executed under the ownership of the same
648640
user that the <productname>PostgreSQL</productname> server is running as. Since
649641
the series of WAL files being archived contains effectively everything
650642
in your database, you will want to be sure that the archived data is
@@ -653,42 +645,46 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
653645
</para>
654646

655647
<para>
656-
It is important that the archive function return <literal>true</literal> if
657-
and only if it succeeds. If <literal>true</literal> is returned,
648+
It is important that the archive command return zero exit status if and
649+
only if it succeeds. Upon getting a zero result,
658650
<productname>PostgreSQL</productname> will assume that the file has been
659-
successfully archived, and will remove or recycle it. However, a return
660-
value of <literal>false</literal> tells
661-
<productname>PostgreSQL</productname> that the file was not archived; it
662-
will try again periodically until it succeeds. If you are archiving via a
663-
shell command, the appropriate return values can be achieved by returning
664-
<literal>0</literal> if the command succeeds and a nonzero value if it
665-
fails.
651+
successfully archived, and will remove or recycle it. However, a nonzero
652+
status tells <productname>PostgreSQL</productname> that the file was not archived;
653+
it will try again periodically until it succeeds.
654+
</para>
655+
656+
<para>
657+
Another way to archive is to use a custom archive module as the
658+
<varname>archive_library</varname>. Since such modules are written in
659+
<literal>C</literal>, creating your own may require considerably more effort
660+
than writing a shell command. However, archive modules can be more
661+
performant than archiving via shell, and they will have access to many
662+
useful server resources. For more information about archive modules, see
663+
<xref linkend="archive-modules"/>.
666664
</para>
667665

668666
<para>
669-
If the archive function emits an <literal>ERROR</literal> or
670-
<literal>FATAL</literal>, the archiver process aborts and gets restarted by
671-
the postmaster. If you are archiving via shell command,
672-
<literal>FATAL</literal> is emitted if the command is terminated by a signal
673-
(other than <systemitem>SIGTERM</systemitem>
674-
that is used as part of a server shutdown)
675-
or an error by the shell with an exit status greater than 125 (such as
676-
command not found). In such cases, the failure is not reported in
677-
<xref linkend="pg-stat-archiver-view"/>.
667+
When the archive command is terminated by a signal (other than
668+
<systemitem>SIGTERM</systemitem> that is used as part of a server
669+
shutdown) or an error by the shell with an exit status greater than
670+
125 (such as command not found), or if the archive function emits an
671+
<literal>ERROR</literal> or <literal>FATAL</literal>, the archiver process
672+
aborts and gets restarted by the postmaster. In such cases, the failure is
673+
not reported in <xref linkend="pg-stat-archiver-view"/>.
678674
</para>
679675

680676
<para>
681-
The archive library should generally be designed to refuse to overwrite
677+
Archive commands and libraries should generally be designed to refuse to overwrite
682678
any pre-existing archive file. This is an important safety feature to
683679
preserve the integrity of your archive in case of administrator error
684680
(such as sending the output of two different servers to the same archive
685681
directory).
686682
</para>
687683

688684
<para>
689-
It is advisable to test your proposed archive library to ensure that it
685+
It is advisable to test your proposed archive command or library to ensure that it
690686
indeed does not overwrite an existing file, <emphasis>and that it returns
691-
<literal>false</literal> in this case</emphasis>.
687+
nonzero status or <literal>false</literal>, respectively, in this case</emphasis>.
692688
The example command above for Unix ensures this by including a separate
693689
<command>test</command> step. On some Unix platforms, <command>cp</command> has
694690
switches such as <option>-i</option> that can be used to do the same thing
@@ -700,7 +696,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
700696

701697
<para>
702698
While designing your archiving setup, consider what will happen if
703-
the archive library fails repeatedly because some aspect requires
699+
the archive command or library fails repeatedly because some aspect requires
704700
operator intervention or the archive runs out of space. For example, this
705701
could occur if you write to tape without an autochanger; when the tape
706702
fills, nothing further can be archived until the tape is swapped.
@@ -715,7 +711,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
715711
</para>
716712

717713
<para>
718-
The speed of the archive library is unimportant as long as it can keep up
714+
The speed of the archive command or library is unimportant as long as it can keep up
719715
with the average rate at which your server generates WAL data. Normal
720716
operation continues even if the archiving process falls a little behind.
721717
If archiving falls significantly behind, this will increase the amount of
@@ -727,11 +723,11 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
727723
</para>
728724

729725
<para>
730-
In writing your archive library, you should assume that the file names to
726+
In writing your archive command or library, you should assume that the file names to
731727
be archived can be up to 64 characters long and can contain any
732728
combination of ASCII letters, digits, and dots. It is not necessary to
733-
preserve the original relative path but it is necessary to preserve the file
734-
name.
729+
preserve the original relative path (<literal>%p</literal>) but it is necessary to
730+
preserve the file name (<literal>%f</literal>).
735731
</para>
736732

737733
<para>
@@ -748,7 +744,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
748744
</para>
749745

750746
<para>
751-
The archive function is only invoked on completed WAL segments. Hence,
747+
The archive command or function is only invoked on completed WAL segments. Hence,
752748
if your server generates only little WAL traffic (or has slack periods
753749
where it does so), there could be a long delay between the completion
754750
of a transaction and its safe recording in archive storage. To put
@@ -777,7 +773,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
777773
turned on during execution of one of these statements, WAL would not
778774
contain enough information for archive recovery. (Crash recovery is
779775
unaffected.) For this reason, <varname>wal_level</varname> can only be changed at
780-
server start. However, <varname>archive_library</varname> can be changed with a
776+
server start. However, <varname>archive_command</varname> and <varname>archive_library</varname> can be changed with a
781777
configuration file reload. If you are archiving via shell and wish to
782778
temporarily stop archiving,
783779
one way to do it is to set <varname>archive_command</varname> to the empty
@@ -947,12 +943,12 @@ SELECT * FROM pg_backup_stop(wait_for_archive => true);
947943
On a standby, <varname>archive_mode</varname> must be <literal>always</literal> in order
948944
for <function>pg_backup_stop</function> to wait.
949945
Archiving of these files happens automatically since you have
950-
already configured <varname>archive_library</varname> or
946+
already configured <varname>archive_command</varname> or <varname>archive_library</varname> or
951947
<varname>archive_command</varname>.
952948
In most cases this happens quickly, but you are advised to monitor your
953949
archive system to ensure there are no delays.
954950
If the archive process has fallen behind because of failures of the
955-
archive library or archive command, it will keep retrying
951+
archive command or library, it will keep retrying
956952
until the archive succeeds and the backup is complete.
957953
If you wish to place a time limit on the execution of
958954
<function>pg_backup_stop</function>, set an appropriate

doc/src/sgml/config.sgml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,7 @@ include_dir 'conf.d'
34963496
Maximum size to let the WAL grow during automatic
34973497
checkpoints. This is a soft limit; WAL size can exceed
34983498
<varname>max_wal_size</varname> under special circumstances, such as
3499-
heavy load, a failing <varname>archive_library</varname>, or a high
3499+
heavy load, a failing <varname>archive_command</varname> or <varname>archive_library</varname>, or a high
35003500
<varname>wal_keep_size</varname> setting.
35013501
If this value is specified without units, it is taken as megabytes.
35023502
The default is 1 GB.
@@ -3545,6 +3545,7 @@ include_dir 'conf.d'
35453545
<para>
35463546
When <varname>archive_mode</varname> is enabled, completed WAL segments
35473547
are sent to archive storage by setting
3548+
<xref linkend="guc-archive-command"/> or
35483549
<xref linkend="guc-archive-library"/>. In addition to <literal>off</literal>,
35493550
to disable, there are two modes: <literal>on</literal>, and
35503551
<literal>always</literal>. During normal operation, there is no
@@ -3555,35 +3556,19 @@ include_dir 'conf.d'
35553556
<xref linkend="continuous-archiving-in-standby"/> for details.
35563557
</para>
35573558
<para>
3559+
<varname>archive_mode</varname> is a separate setting from
3560+
<varname>archive_command</varname> and
3561+
<varname>archive_library</varname> so that
3562+
<varname>archive_command</varname> and
3563+
<varname>archive_library</varname> can be changed without leaving
3564+
archiving mode.
35583565
This parameter can only be set at server start.
35593566
<varname>archive_mode</varname> cannot be enabled when
35603567
<varname>wal_level</varname> is set to <literal>minimal</literal>.
35613568
</para>
35623569
</listitem>
35633570
</varlistentry>
35643571

3565-
<varlistentry id="guc-archive-library" xreflabel="archive_library">
3566-
<term><varname>archive_library</varname> (<type>string</type>)
3567-
<indexterm>
3568-
<primary><varname>archive_library</varname> configuration parameter</primary>
3569-
</indexterm>
3570-
</term>
3571-
<listitem>
3572-
<para>
3573-
The library to use for archiving completed WAL file segments. If set to
3574-
an empty string (the default), archiving via shell is enabled, and
3575-
<xref linkend="guc-archive-command"/> is used. Otherwise, the specified
3576-
shared library is used for archiving. For more information, see
3577-
<xref linkend="backup-archiving-wal"/> and
3578-
<xref linkend="archive-modules"/>.
3579-
</para>
3580-
<para>
3581-
This parameter can only be set in the
3582-
<filename>postgresql.conf</filename> file or on the server command line.
3583-
</para>
3584-
</listitem>
3585-
</varlistentry>
3586-
35873572
<varlistentry id="guc-archive-command" xreflabel="archive_command">
35883573
<term><varname>archive_command</varname> (<type>string</type>)
35893574
<indexterm>
@@ -3607,10 +3592,10 @@ include_dir 'conf.d'
36073592
This parameter can only be set in the <filename>postgresql.conf</filename>
36083593
file or on the server command line. It is ignored unless
36093594
<varname>archive_mode</varname> was enabled at server start and
3610-
<varname>archive_library</varname> specifies to archive via shell command.
3595+
<varname>archive_library</varname> is set to an empty string.
36113596
If <varname>archive_command</varname> is an empty string (the default) while
3612-
<varname>archive_mode</varname> is enabled and <varname>archive_library</varname>
3613-
specifies archiving via shell, WAL archiving is temporarily
3597+
<varname>archive_mode</varname> is enabled (and <varname>archive_library</varname>
3598+
is set to an empty string), WAL archiving is temporarily
36143599
disabled, but the server continues to accumulate WAL segment files in
36153600
the expectation that a command will soon be provided. Setting
36163601
<varname>archive_command</varname> to a command that does nothing but
@@ -3622,6 +3607,28 @@ include_dir 'conf.d'
36223607
</listitem>
36233608
</varlistentry>
36243609

3610+
<varlistentry id="guc-archive-library" xreflabel="archive_library">
3611+
<term><varname>archive_library</varname> (<type>string</type>)
3612+
<indexterm>
3613+
<primary><varname>archive_library</varname> configuration parameter</primary>
3614+
</indexterm>
3615+
</term>
3616+
<listitem>
3617+
<para>
3618+
The library to use for archiving completed WAL file segments. If set to
3619+
an empty string (the default), archiving via shell is enabled, and
3620+
<xref linkend="guc-archive-command"/> is used. Otherwise, the specified
3621+
shared library is used for archiving. For more information, see
3622+
<xref linkend="backup-archiving-wal"/> and
3623+
<xref linkend="archive-modules"/>.
3624+
</para>
3625+
<para>
3626+
This parameter can only be set in the
3627+
<filename>postgresql.conf</filename> file or on the server command line.
3628+
</para>
3629+
</listitem>
3630+
</varlistentry>
3631+
36253632
<varlistentry id="guc-archive-timeout" xreflabel="archive_timeout">
36263633
<term><varname>archive_timeout</varname> (<type>integer</type>)
36273634
<indexterm>
@@ -3630,7 +3637,7 @@ include_dir 'conf.d'
36303637
</term>
36313638
<listitem>
36323639
<para>
3633-
The <xref linkend="guc-archive-library"/> is only invoked for
3640+
The <xref linkend="guc-archive-command"/> or <xref linkend="guc-archive-library"/> is only invoked for
36343641
completed WAL segments. Hence, if your server generates little WAL
36353642
traffic (or has slack periods where it does so), there could be a
36363643
long delay between the completion of a transaction and its safe

doc/src/sgml/high-availability.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
935935
In lieu of using replication slots, it is possible to prevent the removal
936936
of old WAL segments using <xref linkend="guc-wal-keep-size"/>, or by
937937
storing the segments in an archive using
938-
<xref linkend="guc-archive-library"/>.
938+
<xref linkend="guc-archive-command"/> or <xref linkend="guc-archive-library"/>.
939939
However, these methods often result in retaining more WAL segments than
940940
required, whereas replication slots retain only the number of segments
941941
known to be needed. On the other hand, replication slots can retain so
@@ -1386,10 +1386,10 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)'
13861386
to <literal>always</literal>, and the standby will call the archive
13871387
command for every WAL segment it receives, whether it's by restoring
13881388
from the archive or by streaming replication. The shared archive can
1389-
be handled similarly, but the <varname>archive_library</varname> must
1389+
be handled similarly, but the <varname>archive_command</varname> or <varname>archive_library</varname> must
13901390
test if the file being archived exists already, and if the existing file
13911391
has identical contents. This requires more care in the
1392-
<varname>archive_library</varname>, as it must
1392+
<varname>archive_command</varname> or <varname>archive_library</varname>, as it must
13931393
be careful to not overwrite an existing file with different contents,
13941394
but return success if the exactly same file is archived twice. And
13951395
all that must be done free of race conditions, if two servers attempt

doc/src/sgml/ref/pg_receivewal.sgml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ PostgreSQL documentation
4040
<para>
4141
<application>pg_receivewal</application> streams the write-ahead
4242
log in real time as it's being generated on the server, and does not wait
43-
for segments to complete like <xref linkend="guc-archive-library"/> does.
43+
for segments to complete like <xref linkend="guc-archive-command"/> and
44+
<xref linkend="guc-archive-library"/> do.
4445
For this reason, it is not necessary to set
4546
<xref linkend="guc-archive-timeout"/> when using
4647
<application>pg_receivewal</application>.
@@ -486,11 +487,13 @@ PostgreSQL documentation
486487

487488
<para>
488489
When using <application>pg_receivewal</application> instead of
490+
<xref linkend="guc-archive-command"/> or
489491
<xref linkend="guc-archive-library"/> as the main WAL backup method, it is
490492
strongly recommended to use replication slots. Otherwise, the server is
491493
free to recycle or remove write-ahead log files before they are backed up,
492494
because it does not have any information, either
493-
from <xref linkend="guc-archive-library"/> or the replication slots, about
495+
from <xref linkend="guc-archive-command"/> or
496+
<xref linkend="guc-archive-library"/> or the replication slots, about
494497
how far the WAL stream has been archived. Note, however, that a
495498
replication slot will fill up the server's disk space if the receiver does
496499
not keep up with fetching the WAL data.

doc/src/sgml/wal.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@
636636
WAL files plus one additional WAL file are
637637
kept at all times. Also, if WAL archiving is used, old segments cannot be
638638
removed or recycled until they are archived. If WAL archiving cannot keep up
639-
with the pace that WAL is generated, or if <varname>archive_library</varname>
639+
with the pace that WAL is generated, or if <varname>archive_command</varname>
640+
or <varname>archive_library</varname>
640641
fails repeatedly, old WAL files will accumulate in <filename>pg_wal</filename>
641642
until the situation is resolved. A slow or failed standby server that
642643
uses a replication slot will have the same effect (see

0 commit comments

Comments
 (0)