@ -593,7 +593,7 @@ tar -cf backup.tar /usr/local/pgsql/data
provide the database administrator with flexibility,
<productname>PostgreSQL</productname> tries not to make any assumptions about how
the archiving will be done. Instead, <productname>PostgreSQL</productname> lets
the administrator specify an archive library to be executed to copy a
the administrator specify a shell command or a n archive library to be executed to copy a
completed segment file to wherever it needs to go. This could be as simple
as a shell command that uses <literal>cp</literal>, or it could invoke a
complex C function — it's all up to you.
@ -603,13 +603,15 @@ tar -cf backup.tar /usr/local/pgsql/data
To enable WAL archiving, set the <xref linkend="guc-wal-level"/>
configuration parameter to <literal>replica</literal> or higher,
<xref linkend="guc-archive-mode"/> to <literal>on</literal>,
and specify the library to use in the <xref
specify the shell command to use in the <xref
linkend="guc-archive-command"/> configuration parameter
or specify the library to use in the <xref
linkend="guc-archive-library"/> configuration parameter. In practice
these settings will always be placed in the
<filename>postgresql.conf</filename> file.
One simple way to archive is to set <varname>archive_library</varname> to
an empty string and to specify a shell command in
<xref linkend="guc-archive-command"/>.
</para>
<para>
In <varname>archive_command</varname>,
<literal>%p</literal> is replaced by the path name of the file to
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
</para>
<para>
Another way to archive is to use a custom archive module as the
<varname>archive_library</varname>. Since such modules are written in
<literal>C</literal>, creating your own may require considerably more effort
than writing a shell command. However, archive modules can be more
performant than archiving via shell, and they will have access to many
useful server resources. For more information about archive modules, see
<xref linkend="archive-modules"/>.
</para>
<para>
The archive library will be executed under the ownership of the same
The archive command will be executed under the ownership of the same
user that the <productname>PostgreSQL</productname> server is running as. Since
the series of WAL files being archived contains effectively everything
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
</para>
<para>
It is important that the archive function return <literal>true</literal> if
and only if it succeeds. If <literal>true</literal> is returned ,
It is important that the archive command return zero exit status if and
only if it succeeds. Upon getting a zero result ,
<productname>PostgreSQL</productname> will assume that the file has been
successfully archived, and will remove or recycle it. However, a return
value of <literal>false</literal> tells
<productname>PostgreSQL</productname> that the file was not archived; it
will try again periodically until it succeeds. If you are archiving via a
shell command, the appropriate return values can be achieved by returning
<literal>0</literal> if the command succeeds and a nonzero value if it
fails.
successfully archived, and will remove or recycle it. However, a nonzero
status tells <productname>PostgreSQL</productname> that the file was not archived;
it will try again periodically until it succeeds.
</para>
<para>
Another way to archive is to use a custom archive module as the
<varname>archive_library</varname>. Since such modules are written in
<literal>C</literal>, creating your own may require considerably more effort
than writing a shell command. However, archive modules can be more
performant than archiving via shell, and they will have access to many
useful server resources. For more information about archive modules, see
<xref linkend="archive-modules"/>.
</para>
<para>
If the archive function emits an <literal>ERROR</literal> or
<literal>FATAL</literal>, the archiver process aborts and gets restarted by
the postmaster. If you are archiving via shell command,
<literal>FATAL</literal> is emitted if the command is terminated by a signal
(other than <systemitem>SIGTERM</systemitem>
that is used as part of a server shutdown)
or an error by the shell with an exit status greater than 125 (such as
command not found). In such cases, the failure is not reported in
<xref linkend="pg-stat-archiver-view"/>.
When the archive command is terminated by a signal (other than
<systemitem>SIGTERM</systemitem> that is used as part of a server
shutdown) or an error by the shell with an exit status greater than
125 (such as command not found), or if the archive function emits an
<literal>ERROR</literal> or <literal>FATAL</literal>, the archiver process
aborts and gets restarted by the postmaster. In such cases, the failure is
not reported in <xref linkend="pg-stat-archiver-view"/>.
</para>
<para>
The archive library should generally be designed to refuse to overwrite
Archive commands and libraries should generally be designed to refuse to overwrite
any pre-existing archive file. This is an important safety feature to
preserve the integrity of your archive in case of administrator error
(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
re-archive a WAL file that was previously archived. For example, if the
system crashes before the server makes a durable record of archival
success, the server will attempt to archive the file again after
restarting (provided archiving is still enabled). When an archive library
encounters a pre-existing file, it should return <literal>true</literal>
restarting (provided archiving is still enabled). When an archive command or library
encounters a pre-existing file, it should return a zero status or <literal>true</literal>, respectively,
if the WAL file has identical contents to the pre-existing archive and the
pre-existing archive is fully persisted to storage. If a pre-existing
file contains different contents than the WAL file being archived, the
archive library <emphasis>must</emphasis> return
<literal>false</literal>.
archive command or library <emphasis>must</emphasis> return a nonzero status or
<literal>false</literal>, respectively .
</para>
<para>
@ -713,7 +709,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
<para>
While designing your archiving setup, consider what will happen if
the archive library fails repeatedly because some aspect requires
the archive command or library fails repeatedly because some aspect requires
operator intervention or the archive runs out of space. For example, this
could occur if you write to tape without an autochanger; when the tape
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
</para>
<para>
The speed of the archive library is unimportant as long as it can keep up
The speed of the archive command or library is unimportant as long as it can keep up
with the average rate at which your server generates WAL data. Normal
operation continues even if the archiving process falls a little behind.
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
</para>
<para>
In writing your archive library, you should assume that the file names to
In writing your archive command or library, you should assume that the file names to
be archived can be up to 64 characters long and can contain any
combination of ASCII letters, digits, and dots. It is not necessary to
preserve the original relative path but it is necessary to preserve the file
name.
preserve the original relative path (<literal>%p</literal>) but it is necessary to
preserve the file name (<literal>%f</literal>) .
</para>
<para>
@ -761,7 +757,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
</para>
<para>
The archive function is only invoked on completed WAL segments. Hence,
The archive command or function is only invoked on completed WAL segments. Hence,
if your server generates only little WAL traffic (or has slack periods
where it does so), there could be a long delay between the completion
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
turned on during execution of one of these statements, WAL would not
contain enough information for archive recovery. (Crash recovery is
unaffected.) For this reason, <varname>wal_level</varname> can only be changed at
server start. However, <varname>archive_library</varname> can be changed with a
server start. However, <varname>archive_command</varname> and <varname>archive_ library</varname> can be changed with a
configuration file reload. If you are archiving via shell and wish to
temporarily stop archiving,
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);
On a standby, <varname>archive_mode</varname> must be <literal>always</literal> in order
for <function>pg_backup_stop</function> to wait.
Archiving of these files happens automatically since you have
already configured <varname>archive_library</varname> or
already configured <varname>archive_command</varname> or <varname>archive_ library</varname> or
<varname>archive_command</varname>.
In most cases this happens quickly, but you are advised to monitor your
archive system to ensure there are no delays.
If the archive process has fallen behind because of failures of the
archive library or archive command, it will keep retrying
archive command or library , it will keep retrying
until the archive succeeds and the backup is complete.
If you wish to place a time limit on the execution of
<function>pg_backup_stop</function>, set an appropriate