@@ -593,7 +593,7 @@ tar -cf backup.tar /usr/local/pgsql/data
593
593
provide the database administrator with flexibility,
594
594
<productname>PostgreSQL</productname> tries not to make any assumptions about how
595
595
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
597
597
completed segment file to wherever it needs to go. This could be as simple
598
598
as a shell command that uses <literal>cp</literal>, or it could invoke a
599
599
complex C function — it's all up to you.
@@ -603,13 +603,15 @@ tar -cf backup.tar /usr/local/pgsql/data
603
603
To enable WAL archiving, set the <xref linkend="guc-wal-level"/>
604
604
configuration parameter to <literal>replica</literal> or higher,
605
605
<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
607
609
linkend="guc-archive-library"/> configuration parameter. In practice
608
610
these settings will always be placed in the
609
611
<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>
613
615
In <varname>archive_command</varname>,
614
616
<literal>%p</literal> is replaced by the path name of the file to
615
617
archive, while <literal>%f</literal> is replaced by only the file name.
@@ -634,17 +636,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
634
636
</para>
635
637
636
638
<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
648
640
user that the <productname>PostgreSQL</productname> server is running as. Since
649
641
the series of WAL files being archived contains effectively everything
650
642
in your database, you will want to be sure that the archived data is
@@ -653,32 +645,36 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
653
645
</para>
654
646
655
647
<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 ,
658
650
<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"/>.
666
664
</para>
667
665
668
666
<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"/>.
678
674
</para>
679
675
680
676
<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
682
678
any pre-existing archive file. This is an important safety feature to
683
679
preserve the integrity of your archive in case of administrator error
684
680
(such as sending the output of two different servers to the same archive
@@ -691,13 +687,13 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
691
687
re-archive a WAL file that was previously archived. For example, if the
692
688
system crashes before the server makes a durable record of archival
693
689
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,
696
692
if the WAL file has identical contents to the pre-existing archive and the
697
693
pre-existing archive is fully persisted to storage. If a pre-existing
698
694
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 .
701
697
</para>
702
698
703
699
<para>
@@ -713,7 +709,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
713
709
714
710
<para>
715
711
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
717
713
operator intervention or the archive runs out of space. For example, this
718
714
could occur if you write to tape without an autochanger; when the tape
719
715
fills, nothing further can be archived until the tape is swapped.
@@ -728,7 +724,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
728
724
</para>
729
725
730
726
<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
732
728
with the average rate at which your server generates WAL data. Normal
733
729
operation continues even if the archiving process falls a little behind.
734
730
If archiving falls significantly behind, this will increase the amount of
@@ -740,11 +736,11 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
740
736
</para>
741
737
742
738
<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
744
740
be archived can be up to 64 characters long and can contain any
745
741
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>) .
748
744
</para>
749
745
750
746
<para>
@@ -761,7 +757,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
761
757
</para>
762
758
763
759
<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,
765
761
if your server generates only little WAL traffic (or has slack periods
766
762
where it does so), there could be a long delay between the completion
767
763
of a transaction and its safe recording in archive storage. To put
@@ -790,7 +786,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
790
786
turned on during execution of one of these statements, WAL would not
791
787
contain enough information for archive recovery. (Crash recovery is
792
788
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
794
790
configuration file reload. If you are archiving via shell and wish to
795
791
temporarily stop archiving,
796
792
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);
960
956
On a standby, <varname>archive_mode</varname> must be <literal>always</literal> in order
961
957
for <function>pg_backup_stop</function> to wait.
962
958
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
964
960
<varname>archive_command</varname>.
965
961
In most cases this happens quickly, but you are advised to monitor your
966
962
archive system to ensure there are no delays.
967
963
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
969
965
until the archive succeeds and the backup is complete.
970
966
If you wish to place a time limit on the execution of
971
967
<function>pg_backup_stop</function>, set an appropriate
0 commit comments