1 <!-- doc/src/sgml/pgarchivecleanup.sgml -->
3 <sect1 id="pgarchivecleanup">
4 <title>pg_archivecleanup</title>
6 <indexterm zone="pgarchivecleanup">
7 <primary>pg_archivecleanup</primary>
11 <application>pg_archivecleanup</> is designed to cleanup an archive when used
12 as an <literal>archive_cleanup_command</literal> when running with
13 <literal>standby_mode = on</literal>. <application>pg_archivecleanup</> can
14 also be used as a standalone program to clean WAL file archives.
18 <application>pg_archivecleanup</application> features include:
23 Written in C, so very portable and easy to install
28 Easy-to-modify source code, with specifically designated
29 sections to modify for your own needs
38 To configure a standby
39 server to use <application>pg_archivecleanup</>, put this into its
40 <filename>recovery.conf</filename> configuration file:
42 archive_cleanup_command = 'pg_archivecleanup <replaceable>archiveDir</> %r'
44 where <replaceable>archiveDir</> is the directory from which WAL segment
45 files should be restored.
48 When used within <literal>archive_cleanup_command</literal>,
49 all WAL files logically preceding the value of the <literal>%r</>
50 will be removed <replaceable>archivelocation</>. This minimizes
51 the number of files that need to be retained, while preserving
52 crash-restart capability. Use of this parameter is appropriate if the
53 <replaceable>archivelocation</> is a transient staging area for this
54 particular standby server, but <emphasis>not</> when the
55 <replaceable>archivelocation</> is intended as a long-term WAL archive area.
58 The full syntax of <application>pg_archivecleanup</>'s command line is
60 pg_archivecleanup <optional> <replaceable>option</> ... </optional> <replaceable>archivelocation</> <replaceable>restartwalfile</>
62 When used as a standalone program all WAL files logically preceding the
63 <literal>restartwalfile</> will be removed <replaceable>archivelocation</>.
64 In this mode, if you specify a <filename>.backup</> file name, then only the file prefix
65 will be used as the <literal>restartwalfile</>. This allows you to remove
66 all WAL files archived prior to a specific base backup without error.
67 For example, the following example will remove all files older than
68 WAL file name <filename>000000010000003700000010</>:
70 pg_archivecleanup -d archive 000000010000003700000010.00000020.backup
72 pg_archivecleanup: keep WAL files 000000010000003700000010 and later
73 pg_archivecleanup: removing "archive/00000001000000370000000F"
74 pg_archivecleanup: removing "archive/00000001000000370000000E"
76 <application>pg_archivecleanup</application> assumes that
77 <replaceable>archivelocation</> is a directory readable and writable by the
83 <title><application>pg_archivecleanup</> Options</title>
86 <application>pg_archivecleanup</application> accepts the following command-line arguments:
91 <term><option>-d</option></term>
94 Print lots of debug logging output on <filename>stderr</>.
105 <title>Examples</title>
107 <para>On Linux or Unix systems, you might use:
109 archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>cleanup.log'
111 where the archive directory is physically located on the standby server,
112 so that the <literal>archive_command</> is accessing it across NFS,
113 but the files are local to the standby.
119 produce debugging output in <filename>cleanup.log</>
124 remove no-longer-needed files from the archive directory
132 <title>Supported server versions</title>
135 <application>pg_archivecleanup</application> is designed to work with
136 <productname>PostgreSQL</> 8.0 and later when used as a standalone utility,
137 or with <productname>PostgreSQL</> 9.0 and later when used as an
138 archive cleanup command.
143 <title>Author</title>
146 Simon Riggs <email>simon@2ndquadrant.com</email>