1PG_ARCHIVECLEANUP(1) PostgreSQL 13.3 Documentation PG_ARCHIVECLEANUP(1)
2
3
4
6 pg_archivecleanup - clean up PostgreSQL WAL archive files
7
9 pg_archivecleanup [option...] archivelocation oldestkeptwalfile
10
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.
16
17 To configure a standby server to use pg_archivecleanup, put this into
18 its postgresql.conf configuration file:
19
20 archive_cleanup_command = 'pg_archivecleanup archivelocation %r'
21
22 where archivelocation is the directory from which WAL segment files
23 should be removed.
24
25 When used within archive_cleanup_command, all WAL files logically
26 preceding the value of the %r argument will be removed from
27 archivelocation. This minimizes the number of files that need to be
28 retained, while preserving crash-restart capability. Use of this
29 parameter is appropriate if the archivelocation is a transient staging
30 area for this particular standby server, but not when the
31 archivelocation is intended as a long-term WAL archive area, or when
32 multiple standby servers are recovering from the same archive location.
33
34 When used as a standalone program all WAL files logically preceding the
35 oldestkeptwalfile will be removed from archivelocation. In this mode,
36 if you specify a .partial or .backup file name, then only the file
37 prefix will be used as the oldestkeptwalfile. This treatment of .backup
38 file name allows you to remove all WAL files archived prior to a
39 specific base backup without error. For example, the following example
40 will remove all files older than WAL file name
41 000000010000003700000010:
42
43 pg_archivecleanup -d archive 000000010000003700000010.00000020.backup
44
45 pg_archivecleanup: keep WAL file "archive/000000010000003700000010" and later
46 pg_archivecleanup: removing file "archive/00000001000000370000000F"
47 pg_archivecleanup: removing file "archive/00000001000000370000000E"
48
49 pg_archivecleanup assumes that archivelocation is a directory readable
50 and writable by the server-owning user.
51
53 pg_archivecleanup accepts the following command-line arguments:
54
55 -d
56 Print lots of debug logging output on stderr.
57
58 -n
59 Print the names of the files that would have been removed on stdout
60 (performs a dry run).
61
62 -V
63 --version
64 Print the pg_archivecleanup version and exit.
65
66 -x extension
67 Provide an extension that will be stripped from all file names
68 before deciding if they should be deleted. This is typically useful
69 for cleaning up archives that have been compressed during storage,
70 and therefore have had an extension added by the compression
71 program. For example: -x .gz.
72
73 -?
74 --help
75 Show help about pg_archivecleanup command line arguments, and exit.
76
78 The environment variable PG_COLOR specifies whether to use color in
79 diagnostic messages. Possible values are always, auto and never.
80
82 pg_archivecleanup is designed to work with PostgreSQL 8.0 and later
83 when used as a standalone utility, or with PostgreSQL 9.0 and later
84 when used as an archive cleanup command.
85
86 pg_archivecleanup is written in C and has an easy-to-modify source
87 code, with specifically designated sections to modify for your own
88 needs
89
91 On Linux or Unix systems, you might use:
92
93 archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>cleanup.log'
94
95 where the archive directory is physically located on the standby
96 server, so that the archive_command is accessing it across NFS, but the
97 files are local to the standby. This will:
98
99 • produce debugging output in cleanup.log
100
101 • remove no-longer-needed files from the archive directory
102
104 pg_standby(1)
105
106
107
108PostgreSQL 13.3 2021 PG_ARCHIVECLEANUP(1)