Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/pgarchivecleanup.sgml`
df741423c3cdf2ce8458e8bf534e86cd7249a1ef6e934f720000000100000ec1
<!--
doc/src/sgml/ref/pgarchivecleanup.sgml
PostgreSQL documentation
-->

<refentry id="pgarchivecleanup">
 <indexterm zone="pgarchivecleanup">
  <primary>pg_archivecleanup</primary>
 </indexterm>

 <refmeta>
  <refentrytitle><application>pg_archivecleanup</application></refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo>Application</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>pg_archivecleanup</refname>
  <refpurpose>clean up <productname>PostgreSQL</productname> WAL archive files</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
  <cmdsynopsis>
   <command>pg_archivecleanup</command>
   <arg rep="repeat"><replaceable>option</replaceable></arg>
   <arg choice="plain"><replaceable>archivelocation</replaceable></arg>
   <arg choice="plain"><replaceable>oldestkeptwalfile</replaceable></arg>
  </cmdsynopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

 <para>
  <application>pg_archivecleanup</application> is designed to be used as an
  <literal>archive_cleanup_command</literal> to clean up WAL file archives when
  running as a standby server (see <xref linkend="warm-standby"/>).
  <application>pg_archivecleanup</application> can also be used as a standalone program to
  clean WAL file archives.
 </para>

  <para>
   To configure a standby
   server to use <application>pg_archivecleanup</application>, put this into its
   <filename>postgresql.conf</filename> configuration file:
<programlisting>
archive_cleanup_command = 'pg_archivecleanup <replaceable>archivelocation</replaceable> %r'
</programlisting>
   where <replaceable>archivelocation</replaceable> is the directory from which WAL segment
   files should be removed.
  </para>
  <para>
   When used within <xref linkend="guc-archive-cleanup-command"/>, all WAL files
   logically preceding the value of the <literal>%r</literal> argument will be removed
   from <replaceable>archivelocation</replaceable>. This minimizes the number of files
   that need to be retained, while preserving crash-restart capability.  Use of
   this parameter is appropriate if the <replaceable>archivelocation</replaceable> is a
   transient staging area for this particular standby server, but
   <emphasis>not</emphasis> when the <replaceable>archivelocation</replaceable> is intended as a
   long-term WAL archive area, or when multiple standby servers are recovering
   from the same archive location.
  </para>
  <para>
   When used as a standalone program all WAL files logically preceding the
   <replaceable>oldestkeptwalfile</replaceable> will be removed from <replaceable>archivelocation</replaceable>.
   In this mode, if you specify a <filename>.partial</filename> or <filename>.backup</filename>
   file name, then only the file prefix will be used as the
   <replaceable>oldestkeptwalfile</replaceable>. This treatment of <filename>.backup</filename>
   file name allows you to remove
   all WAL files archived prior to a specific base backup without error.
   For example, the following example will remove all files older than
   WAL file name <filename>000000010000003700000010</filename>:
<programlisting>
pg_archivecleanup -d archive 000000010000003700000010.00000020.backup

pg_archivecleanup:  keep WAL file "archive/000000010000003700000010" and later
pg_archivecleanup:  removing file "archive/00000001000000370000000F"
pg_archivecleanup:  removing file "archive/00000001000000370000000E"
</programlisting>
  </para>
  <para>
   <application>pg_archivecleanup</application> assumes that
   <replaceable>archivelocation</replaceable> is a directory readable and writable by the
   server-owning user.
  </para>
 </refsect1>

 <refsect1>
  <title>Options</title>

   <para>
    <application>pg_archivecleanup</application> accepts the following command-line arguments:

 

Title: pg_archivecleanup
Summary
pg_archivecleanup is a utility for cleaning up WAL (Write-Ahead Logging) archive files in PostgreSQL. It's designed to be used as an archive_cleanup_command when running as a standby server or as a standalone program. It removes WAL files that are no longer needed for recovery, based on the oldest WAL file that needs to be kept.