Skip to content

Commit ba50834

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 18ac08f commit ba50834

File tree

5 files changed

+88
-81
lines changed

5 files changed

+88
-81
lines changed

doc/src/sgml/backup.sgml

Lines changed: 44 additions & 48 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,32 +645,36 @@ 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
@@ -691,13 +687,13 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
691687
re-archive a WAL file that was previously archived. For example, if the
692688
system crashes before the server makes a durable record of archival
693689
success, the server will attempt to archive the file again after
694-
restarting (provided archiving is still enabled). When an archive library
695-
encounters a pre-existing file, it should return <literal>true</literal>
690+
restarting (provided archiving is still enabled). When an archive command or library
691+
encounters a pre-existing file, it should return a zero status or <literal>true</literal>, respectively,
696692
if the WAL file has identical contents to the pre-existing archive and the
697693
pre-existing archive is fully persisted to storage. If a pre-existing
698694
file contains different contents than the WAL file being archived, the
699-
archive library <emphasis>must</emphasis> return
700-
<literal>false</literal>.
695+
archive command or library <emphasis>must</emphasis> return a nonzero status or
696+
<literal>false</literal>, respectively.
701697
</para>
702698

703699
<para>
@@ -713,7 +709,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
713709

714710
<para>
715711
While designing your archiving setup, consider what will happen if
716-
the archive library fails repeatedly because some aspect requires
712+
the archive command or library fails repeatedly because some aspect requires
717713
operator intervention or the archive runs out of space. For example, this
718714
could occur if you write to tape without an autochanger; when the tape
719715
fills, nothing further can be archived until the tape is swapped.
@@ -728,7 +724,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
728724
</para>
729725

730726
<para>
731-
The speed of the archive library is unimportant as long as it can keep up
727+
The speed of the archive command or library is unimportant as long as it can keep up
732728
with the average rate at which your server generates WAL data. Normal
733729
operation continues even if the archiving process falls a little behind.
734730
If archiving falls significantly behind, this will increase the amount of
@@ -740,11 +736,11 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
740736
</para>
741737

742738
<para>
743-
In writing your archive library, you should assume that the file names to
739+
In writing your archive command or library, you should assume that the file names to
744740
be archived can be up to 64 characters long and can contain any
745741
combination of ASCII letters, digits, and dots. It is not necessary to
746-
preserve the original relative path but it is necessary to preserve the file
747-
name.
742+
preserve the original relative path (<literal>%p</literal>) but it is necessary to
743+
preserve the file name (<literal>%f</literal>).
748744
</para>
749745

750746
<para>
@@ -761,7 +757,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
761757
</para>
762758

763759
<para>
764-
The archive function is only invoked on completed WAL segments. Hence,
760+
The archive command or function is only invoked on completed WAL segments. Hence,
765761
if your server generates only little WAL traffic (or has slack periods
766762
where it does so), there could be a long delay between the completion
767763
of a transaction and its safe recording in archive storage. To put
@@ -790,7 +786,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 &amp;&amp; cp pg_wal/0
790786
turned on during execution of one of these statements, WAL would not
791787
contain enough information for archive recovery. (Crash recovery is
792788
unaffected.) For this reason, <varname>wal_level</varname> can only be changed at
793-
server start. However, <varname>archive_library</varname> can be changed with a
789+
server start. However, <varname>archive_command</varname> and <varname>archive_library</varname> can be changed with a
794790
configuration file reload. If you are archiving via shell and wish to
795791
temporarily stop archiving,
796792
one way to do it is to set <varname>archive_command</varname> to the empty
@@ -960,12 +956,12 @@ SELECT * FROM pg_backup_stop(wait_for_archive => true);
960956
On a standby, <varname>archive_mode</varname> must be <literal>always</literal> in order
961957
for <function>pg_backup_stop</function> to wait.
962958
Archiving of these files happens automatically since you have
963-
already configured <varname>archive_library</varname> or
959+
already configured <varname>archive_command</varname> or <varname>archive_library</varname> or
964960
<varname>archive_command</varname>.
965961
In most cases this happens quickly, but you are advised to monitor your
966962
archive system to ensure there are no delays.
967963
If the archive process has fallen behind because of failures of the
968-
archive library or archive command, it will keep retrying
964+
archive command or library, it will keep retrying
969965
until the archive succeeds and the backup is complete.
970966
If you wish to place a time limit on the execution of
971967
<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
@@ -3503,7 +3503,7 @@ include_dir 'conf.d'
35033503
Maximum size to let the WAL grow during automatic
35043504
checkpoints. This is a soft limit; WAL size can exceed
35053505
<varname>max_wal_size</varname> under special circumstances, such as
3506-
heavy load, a failing <varname>archive_library</varname>, or a high
3506+
heavy load, a failing <varname>archive_command</varname> or <varname>archive_library</varname>, or a high
35073507
<varname>wal_keep_size</varname> setting.
35083508
If this value is specified without units, it is taken as megabytes.
35093509
The default is 1 GB.
@@ -3552,6 +3552,7 @@ include_dir 'conf.d'
35523552
<para>
35533553
When <varname>archive_mode</varname> is enabled, completed WAL segments
35543554
are sent to archive storage by setting
3555+
<xref linkend="guc-archive-command"/> or
35553556
<xref linkend="guc-archive-library"/>. In addition to <literal>off</literal>,
35563557
to disable, there are two modes: <literal>on</literal>, and
35573558
<literal>always</literal>. During normal operation, there is no
@@ -3562,35 +3563,19 @@ include_dir 'conf.d'
35623563
<xref linkend="continuous-archiving-in-standby"/> for details.
35633564
</para>
35643565
<para>
3566+
<varname>archive_mode</varname> is a separate setting from
3567+
<varname>archive_command</varname> and
3568+
<varname>archive_library</varname> so that
3569+
<varname>archive_command</varname> and
3570+
<varname>archive_library</varname> can be changed without leaving
3571+
archiving mode.
35653572
This parameter can only be set at server start.
35663573
<varname>archive_mode</varname> cannot be enabled when
35673574
<varname>wal_level</varname> is set to <literal>minimal</literal>.
35683575
</para>
35693576
</listitem>
35703577
</varlistentry>
35713578

3572-
<varlistentry id="guc-archive-library" xreflabel="archive_library">
3573-
<term><varname>archive_library</varname> (<type>string</type>)
3574-
<indexterm>
3575-
<primary><varname>archive_library</varname> configuration parameter</primary>
3576-
</indexterm>
3577-
</term>
3578-
<listitem>
3579-
<para>
3580-
The library to use for archiving completed WAL file segments. If set to
3581-
an empty string (the default), archiving via shell is enabled, and
3582-
<xref linkend="guc-archive-command"/> is used. Otherwise, the specified
3583-
shared library is used for archiving. For more information, see
3584-
<xref linkend="backup-archiving-wal"/> and
3585-
<xref linkend="archive-modules"/>.
3586-
</para>
3587-
<para>
3588-
This parameter can only be set in the
3589-
<filename>postgresql.conf</filename> file or on the server command line.
3590-
</para>
3591-
</listitem>
3592-
</varlistentry>
3593-
35943579
<varlistentry id="guc-archive-command" xreflabel="archive_command">
35953580
<term><varname>archive_command</varname> (<type>string</type>)
35963581
<indexterm>
@@ -3614,10 +3599,10 @@ include_dir 'conf.d'
36143599
This parameter can only be set in the <filename>postgresql.conf</filename>
36153600
file or on the server command line. It is ignored unless
36163601
<varname>archive_mode</varname> was enabled at server start and
3617-
<varname>archive_library</varname> specifies to archive via shell command.
3602+
<varname>archive_library</varname> is set to an empty string.
36183603
If <varname>archive_command</varname> is an empty string (the default) while
3619-
<varname>archive_mode</varname> is enabled and <varname>archive_library</varname>
3620-
specifies archiving via shell, WAL archiving is temporarily
3604+
<varname>archive_mode</varname> is enabled (and <varname>archive_library</varname>
3605+
is set to an empty string), WAL archiving is temporarily
36213606
disabled, but the server continues to accumulate WAL segment files in
36223607
the expectation that a command will soon be provided. Setting
36233608
<varname>archive_command</varname> to a command that does nothing but
@@ -3629,6 +3614,28 @@ include_dir 'conf.d'
36293614
</listitem>
36303615
</varlistentry>
36313616

3617+
<varlistentry id="guc-archive-library" xreflabel="archive_library">
3618+
<term><varname>archive_library</varname> (<type>string</type>)
3619+
<indexterm>
3620+
<primary><varname>archive_library</varname> configuration parameter</primary>
3621+
</indexterm>
3622+
</term>
3623+
<listitem>
3624+
<para>
3625+
The library to use for archiving completed WAL file segments. If set to
3626+
an empty string (the default), archiving via shell is enabled, and
3627+
<xref linkend="guc-archive-command"/> is used. Otherwise, the specified
3628+
shared library is used for archiving. For more information, see
3629+
<xref linkend="backup-archiving-wal"/> and
3630+
<xref linkend="archive-modules"/>.
3631+
</para>
3632+
<para>
3633+
This parameter can only be set in the
3634+
<filename>postgresql.conf</filename> file or on the server command line.
3635+
</para>
3636+
</listitem>
3637+
</varlistentry>
3638+
36323639
<varlistentry id="guc-archive-timeout" xreflabel="archive_timeout">
36333640
<term><varname>archive_timeout</varname> (<type>integer</type>)
36343641
<indexterm>
@@ -3637,7 +3644,7 @@ include_dir 'conf.d'
36373644
</term>
36383645
<listitem>
36393646
<para>
3640-
The <xref linkend="guc-archive-library"/> is only invoked for
3647+
The <xref linkend="guc-archive-command"/> or <xref linkend="guc-archive-library"/> is only invoked for
36413648
completed WAL segments. Hence, if your server generates little WAL
36423649
traffic (or has slack periods where it does so), there could be a
36433650
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>.
@@ -488,11 +489,13 @@ PostgreSQL documentation
488489

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

0 commit comments

Comments
 (0)