2 .\" Title: pg_archivecleanup
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "PG_ARCHIVECLEANUP" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 pg_archivecleanup \- clean up PostgreSQL WAL archive files
33 .HP \w'\fBpg_archivecleanup\fR\ 'u
34 \fBpg_archivecleanup\fR [\fIoption\fR...] \fIarchivelocation\fR \fIoldestkeptwalfile\fR
38 is designed to be used as an
39 archive_cleanup_command
40 to clean up WAL file archives when running as a standby server (see
43 can also be used as a standalone program to clean WAL file archives\&.
45 To configure a standby server to use
46 pg_archivecleanup, put this into its
54 archive_cleanup_command = \*(Aqpg_archivecleanup \fIarchivelocation\fR %r\*(Aq
62 is the directory from which WAL segment files should be removed\&.
65 archive_cleanup_command, all WAL files logically preceding the value of the
67 argument will be removed from
68 \fIarchivelocation\fR\&. This minimizes the number of files that need to be retained, while preserving crash\-restart capability\&. Use of this parameter is appropriate if the
70 is a transient staging area for this particular standby server, but
74 is intended as a long\-term WAL archive area, or when multiple standby servers are recovering from the same archive location\&.
76 When used as a standalone program all WAL files logically preceding the
77 \fIoldestkeptwalfile\fR
79 \fIarchivelocation\fR\&. In this mode, if you specify a
83 file name, then only the file prefix will be used as the
84 \fIoldestkeptwalfile\fR\&. This treatment of
86 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
87 000000010000003700000010:
93 pg_archivecleanup \-d archive 000000010000003700000010\&.00000020\&.backup
95 pg_archivecleanup: keep WAL file "archive/000000010000003700000010" and later
96 pg_archivecleanup: removing file "archive/00000001000000370000000F"
97 pg_archivecleanup: removing file "archive/00000001000000370000000E"
105 \fIarchivelocation\fR
106 is a directory readable and writable by the server\-owning user\&.
110 accepts the following command\-line arguments:
114 \fB\-\-clean\-backup\-history\fR
116 Remove backup history files as well\&. See
118 for details about backup history files\&.
125 Print lots of debug logging output on
133 Print the names of the files that would have been removed on
135 (performs a dry run)\&.
147 \fB\-x \fR\fB\fIextension\fR\fR
149 \fB\-\-strip\-extension=\fR\fB\fIextension\fR\fR
151 Provide an extension that will be stripped from all file names before deciding if they should be deleted\&. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program\&. For example:
161 command line arguments, and exit\&.
165 The environment variable
167 specifies whether to use color in diagnostic messages\&. Possible values are
175 is designed to work with
177 8\&.0 and later when used as a standalone utility, or with
179 9\&.0 and later when used as an archive cleanup command\&.
182 is written in C and has an easy\-to\-modify source code, with specifically designated sections to modify for your own needs
185 On Linux or Unix systems, you might use:
191 archive_cleanup_command = \*(Aqpg_archivecleanup \-d /mnt/standby/archive %r 2>>cleanup\&.log\*(Aq
197 where the archive directory is physically located on the standby server, so that the
198 \fIarchive_command\fR
199 is accessing it across NFS, but the files are local to the standby\&. This will:
209 produce debugging output in
221 remove no\-longer\-needed files from the archive directory