1PG_ARCHIVECLEANUP(1) PostgreSQL 9.2.24 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 25.2, “Log-Shipping Standby Servers”, in the documentation).
15 pg_archivecleanup can also be used as a standalone program to clean WAL
16 file archives.
17
18 To configure a standby server to use pg_archivecleanup, put this into
19 its recovery.conf configuration file:
20
21 archive_cleanup_command = 'pg_archivecleanup archivelocation %r'
22
23 where archivelocation is the directory from which WAL segment files
24 should be removed.
25
26 When used within archive_cleanup_command, all WAL files logically
27 preceding the value of the %r argument will be removed from
28 archivelocation. This minimizes the number of files that need to be
29 retained, while preserving crash-restart capability. Use of this
30 parameter is appropriate if the archivelocation is a transient staging
31 area for this particular standby server, but not when the
32 archivelocation is intended as a long-term WAL archive area, or when
33 multiple standby servers are recovering from the same archive location.
34
35 When used as a standalone program all WAL files logically preceding the
36 oldestkeptwalfile will be removed from archivelocation. In this mode,
37 if you specify a .backup file name, then only the file prefix will be
38 used as the oldestkeptwalfile. This allows you to remove all WAL files
39 archived prior to a specific base backup without error. For example,
40 the following example 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, --version
63 Print the pg_archivecleanup version and exit.
64
65 -x extension
66 When using the program as a standalone utility, provide an
67 extension that will be stripped from all file names before deciding
68 if they should be deleted. This is typically useful for cleaning up
69 archives that have been compressed during storage, and therefore
70 have had an extension added by the compression program. For
71 example: -x .gz.
72
73 -?, --help
74 Show help about pg_archivecleanup command line arguments, and exit.
75
77 pg_archivecleanup is designed to work with PostgreSQL 8.0 and later
78 when used as a standalone utility, or with PostgreSQL 9.0 and later
79 when used as an archive cleanup command.
80
81 pg_archivecleanup is written in C and has an easy-to-modify source
82 code, with specifically designated sections to modify for your own
83 needs
84
86 On Linux or Unix systems, you might use:
87
88 archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>cleanup.log'
89
90 where the archive directory is physically located on the standby
91 server, so that the archive_command is accessing it across NFS, but the
92 files are local to the standby. This will:
93
94 · produce debugging output in cleanup.log
95
96 · remove no-longer-needed files from the archive directory
97
99 Simon Riggs <simon@2ndquadrant.com>
100
102 pg_standby(1)
103
104
105
106PostgreSQL 9.2.24 2017-11-06 PG_ARCHIVECLEANUP(1)