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 be used as an
12
<literal>archive_cleanup_command</literal> to clean up WAL file archives when
13
running as a standby server (see <xref linkend="warm-standby">).
14
<application>pg_archivecleanup</> can also be used as a standalone program to
15
clean WAL file archives.
19
<application>pg_archivecleanup</application> features include:
24
Written in C, so very portable and easy to install
29
Easy-to-modify source code, with specifically designated
30
sections to modify for your own needs
39
To configure a standby
40
server to use <application>pg_archivecleanup</>, put this into its
41
<filename>recovery.conf</filename> configuration file:
43
archive_cleanup_command = 'pg_archivecleanup <replaceable>archivelocation</> %r'
45
where <replaceable>archivelocation</> is the directory from which WAL segment
46
files should be removed.
49
When used within <xref linkend="archive-cleanup-command">, all WAL files
50
logically preceding the value of the <literal>%r</> argument will be removed
51
from <replaceable>archivelocation</>. This minimizes the number of files
52
that need to be retained, while preserving crash-restart capability. Use of
53
this parameter is appropriate if the <replaceable>archivelocation</> is a
54
transient staging area for this particular standby server, but
55
<emphasis>not</> when the <replaceable>archivelocation</> is intended as a
56
long-term WAL archive area, or when multiple standby servers are recovering
57
from the same archive location.
60
The full syntax of <application>pg_archivecleanup</>'s command line is
62
pg_archivecleanup <optional> <replaceable>option</> ... </optional> <replaceable>archivelocation</> <replaceable>restartwalfile</>
64
When used as a standalone program all WAL files logically preceding the
65
<literal>restartwalfile</> will be removed <replaceable>archivelocation</>.
66
In this mode, if you specify a <filename>.backup</> file name, then only the file prefix
67
will be used as the <literal>restartwalfile</>. This allows you to remove
68
all WAL files archived prior to a specific base backup without error.
69
For example, the following example will remove all files older than
70
WAL file name <filename>000000010000003700000010</>:
72
pg_archivecleanup -d archive 000000010000003700000010.00000020.backup
74
pg_archivecleanup: keep WAL file "archive/000000010000003700000010" and later
75
pg_archivecleanup: removing file "archive/00000001000000370000000F"
76
pg_archivecleanup: removing file "archive/00000001000000370000000E"
78
<application>pg_archivecleanup</application> assumes that
79
<replaceable>archivelocation</> is a directory readable and writable by the
85
<title><application>pg_archivecleanup</> Options</title>
88
<application>pg_archivecleanup</application> accepts the following command-line arguments:
93
<term><option>-d</option></term>
96
Print lots of debug logging output on <filename>stderr</>.
107
<title>Examples</title>
109
<para>On Linux or Unix systems, you might use:
111
archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>cleanup.log'
113
where the archive directory is physically located on the standby server,
114
so that the <varname>archive_command</> is accessing it across NFS,
115
but the files are local to the standby.
121
produce debugging output in <filename>cleanup.log</>
126
remove no-longer-needed files from the archive directory
134
<title>Supported Server Versions</title>
137
<application>pg_archivecleanup</application> is designed to work with
138
<productname>PostgreSQL</> 8.0 and later when used as a standalone utility,
139
or with <productname>PostgreSQL</> 9.0 and later when used as an
140
archive cleanup command.
145
<title>Author</title>
148
Simon Riggs <email>simon@2ndquadrant.com</email>