4 pg_archivecleanup — clean up PostgreSQL WAL archive files
8 pg_archivecleanup [option...] archivelocation oldestkeptwalfile
12 pg_archivecleanup is designed to be used as an archive_cleanup_command
13 to clean up WAL file archives when running as a standby server (see
14 Section 26.2). pg_archivecleanup can also be used as a standalone
15 program to clean WAL file archives.
17 To configure a standby server to use pg_archivecleanup, put this into
18 its postgresql.conf configuration file:
19 archive_cleanup_command = 'pg_archivecleanup archivelocation %r'
21 where archivelocation is the directory from which WAL segment files
24 When used within archive_cleanup_command, all WAL files logically
25 preceding the value of the %r argument will be removed from
26 archivelocation. This minimizes the number of files that need to be
27 retained, while preserving crash-restart capability. Use of this
28 parameter is appropriate if the archivelocation is a transient staging
29 area for this particular standby server, but not when the
30 archivelocation is intended as a long-term WAL archive area, or when
31 multiple standby servers are recovering from the same archive location.
33 When used as a standalone program all WAL files logically preceding the
34 oldestkeptwalfile will be removed from archivelocation. In this mode,
35 if you specify a .partial or .backup file name, then only the file
36 prefix will be used as the oldestkeptwalfile. This treatment of .backup
37 file name allows you to remove all WAL files archived prior to a
38 specific base backup without error. For example, the following example
39 will remove all files older than WAL file name
40 000000010000003700000010:
41 pg_archivecleanup -d archive 000000010000003700000010.00000020.backup
43 pg_archivecleanup: keep WAL file "archive/000000010000003700000010" and later
44 pg_archivecleanup: removing file "archive/00000001000000370000000F"
45 pg_archivecleanup: removing file "archive/00000001000000370000000E"
47 pg_archivecleanup assumes that archivelocation is a directory readable
48 and writable by the server-owning user.
52 pg_archivecleanup accepts the following command-line arguments:
55 --clean-backup-history
56 Remove backup history files as well. See Section 25.3.2 for
57 details about backup history files.
61 Print lots of debug logging output on stderr.
65 Print the names of the files that would have been removed on
66 stdout (performs a dry run).
70 Print the pg_archivecleanup version and exit.
73 --strip-extension=extension
74 Provide an extension that will be stripped from all file names
75 before deciding if they should be deleted. This is typically
76 useful for cleaning up archives that have been compressed during
77 storage, and therefore have had an extension added by the
78 compression program. For example: -x .gz.
82 Show help about pg_archivecleanup command line arguments, and
87 The environment variable PG_COLOR specifies whether to use color in
88 diagnostic messages. Possible values are always, auto and never.
92 pg_archivecleanup is designed to work with PostgreSQL 8.0 and later
93 when used as a standalone utility, or with PostgreSQL 9.0 and later
94 when used as an archive cleanup command.
96 pg_archivecleanup is written in C and has an easy-to-modify source
97 code, with specifically designated sections to modify for your own
102 On Linux or Unix systems, you might use:
103 archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>clean
106 where the archive directory is physically located on the standby
107 server, so that the archive_command is accessing it across NFS, but the
108 files are local to the standby. This will:
109 * produce debugging output in cleanup.log
110 * remove no-longer-needed files from the archive directory