]> begriffs open source - ai-pg/blob - full-docs/html/pgarchivecleanup.html
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / html / pgarchivecleanup.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>pg_archivecleanup</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="app-initdb.html" title="initdb" /><link rel="next" href="app-pgchecksums.html" title="pg_checksums" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span class="application">pg_archivecleanup</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-initdb.html" title="initdb">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-server.html" title="PostgreSQL Server Applications">Up</a></td><th width="60%" align="center">PostgreSQL Server Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="app-pgchecksums.html" title="pg_checksums">Next</a></td></tr></table><hr /></div><div class="refentry" id="PGARCHIVECLEANUP"><div class="titlepage"></div><a id="id-1.9.5.4.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">pg_archivecleanup</span></span></h2><p>pg_archivecleanup — clean up <span class="productname">PostgreSQL</span> WAL archive files</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.5.4.4.1"><code class="command">pg_archivecleanup</code> [<em class="replaceable"><code>option</code></em>...]  <em class="replaceable"><code>archivelocation</code></em>   <em class="replaceable"><code>oldestkeptwalfile</code></em> </p></div></div><div class="refsect1" id="id-1.9.5.4.5"><h2>Description</h2><p>
3   <span class="application">pg_archivecleanup</span> is designed to be used as an
4   <code class="literal">archive_cleanup_command</code> to clean up WAL file archives when
5   running as a standby server (see <a class="xref" href="warm-standby.html" title="26.2. Log-Shipping Standby Servers">Section 26.2</a>).
6   <span class="application">pg_archivecleanup</span> can also be used as a standalone program to
7   clean WAL file archives.
8  </p><p>
9    To configure a standby
10    server to use <span class="application">pg_archivecleanup</span>, put this into its
11    <code class="filename">postgresql.conf</code> configuration file:
12 </p><pre class="programlisting">
13 archive_cleanup_command = 'pg_archivecleanup <em class="replaceable"><code>archivelocation</code></em> %r'
14 </pre><p>
15    where <em class="replaceable"><code>archivelocation</code></em> is the directory from which WAL segment
16    files should be removed.
17   </p><p>
18    When used within <a class="xref" href="runtime-config-wal.html#GUC-ARCHIVE-CLEANUP-COMMAND">archive_cleanup_command</a>, all WAL files
19    logically preceding the value of the <code class="literal">%r</code> argument will be removed
20    from <em class="replaceable"><code>archivelocation</code></em>. This minimizes the number of files
21    that need to be retained, while preserving crash-restart capability.  Use of
22    this parameter is appropriate if the <em class="replaceable"><code>archivelocation</code></em> is a
23    transient staging area for this particular standby server, but
24    <span class="emphasis"><em>not</em></span> when the <em class="replaceable"><code>archivelocation</code></em> is intended as a
25    long-term WAL archive area, or when multiple standby servers are recovering
26    from the same archive location.
27   </p><p>
28    When used as a standalone program all WAL files logically preceding the
29    <em class="replaceable"><code>oldestkeptwalfile</code></em> will be removed from <em class="replaceable"><code>archivelocation</code></em>.
30    In this mode, if you specify a <code class="filename">.partial</code> or <code class="filename">.backup</code>
31    file name, then only the file prefix will be used as the
32    <em class="replaceable"><code>oldestkeptwalfile</code></em>. This treatment of <code class="filename">.backup</code>
33    file name allows you to remove
34    all WAL files archived prior to a specific base backup without error.
35    For example, the following example will remove all files older than
36    WAL file name <code class="filename">000000010000003700000010</code>:
37 </p><pre class="programlisting">
38 pg_archivecleanup -d archive 000000010000003700000010.00000020.backup
39
40 pg_archivecleanup:  keep WAL file "archive/000000010000003700000010" and later
41 pg_archivecleanup:  removing file "archive/00000001000000370000000F"
42 pg_archivecleanup:  removing file "archive/00000001000000370000000E"
43 </pre><p>
44   </p><p>
45    <span class="application">pg_archivecleanup</span> assumes that
46    <em class="replaceable"><code>archivelocation</code></em> is a directory readable and writable by the
47    server-owning user.
48   </p></div><div class="refsect1" id="id-1.9.5.4.6"><h2>Options</h2><p>
49     <span class="application">pg_archivecleanup</span> accepts the following command-line arguments:
50
51     </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-b</code><br /></span><span class="term"><code class="option">--clean-backup-history</code></span></dt><dd><p>
52          Remove backup history files as well.
53          See <a class="xref" href="continuous-archiving.html#BACKUP-BASE-BACKUP" title="25.3.2. Making a Base Backup">Section 25.3.2</a> for details about backup
54          history files.
55        </p></dd><dt><span class="term"><code class="option">-d</code><br /></span><span class="term"><code class="option">--debug</code></span></dt><dd><p>
56         Print lots of debug logging output on <code class="filename">stderr</code>.
57        </p></dd><dt><span class="term"><code class="option">-n</code><br /></span><span class="term"><code class="option">--dry-run</code></span></dt><dd><p>
58         Print the names of the files that would have been removed on <code class="filename">stdout</code> (performs a dry run).
59        </p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
60         Print the <span class="application">pg_archivecleanup</span> version and exit.
61        </p></dd><dt><span class="term"><code class="option">-x <em class="replaceable"><code>extension</code></em></code><br /></span><span class="term"><code class="option">--strip-extension=<em class="replaceable"><code>extension</code></em></code></span></dt><dd><p>
62         Provide an extension
63         that will be stripped from all file names before deciding if they
64         should be deleted.  This is typically useful for cleaning up archives
65         that have been compressed during storage, and therefore have had an
66         extension added by the compression program.  For example: <code class="literal">-x
67         .gz</code>.
68        </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
69         Show help about <span class="application">pg_archivecleanup</span> command line
70         arguments, and exit.
71        </p></dd></dl></div><p>
72    </p></div><div class="refsect1" id="id-1.9.5.4.7"><h2>Environment</h2><p>
73    The environment variable <code class="envar">PG_COLOR</code> specifies whether to use
74    color in diagnostic messages. Possible values are
75    <code class="literal">always</code>, <code class="literal">auto</code> and
76    <code class="literal">never</code>.
77   </p></div><div class="refsect1" id="id-1.9.5.4.8"><h2>Notes</h2><p>
78    <span class="application">pg_archivecleanup</span> is designed to work with
79    <span class="productname">PostgreSQL</span> 8.0 and later when used as a standalone utility,
80    or with <span class="productname">PostgreSQL</span> 9.0 and later when used as an
81    archive cleanup command.
82   </p><p>
83    <span class="application">pg_archivecleanup</span> is written in C and has an
84    easy-to-modify source code, with specifically designated sections to modify
85    for your own needs
86   </p></div><div class="refsect1" id="id-1.9.5.4.9"><h2>Examples</h2><p>On Linux or Unix systems, you might use:
87 </p><pre class="programlisting">
88 archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2&gt;&gt;cleanup.log'
89 </pre><p>
90    where the archive directory is physically located on the standby server,
91    so that the <code class="varname">archive_command</code> is accessing it across NFS,
92    but the files are local to the standby.
93    This will:
94   </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
95      produce debugging output in <code class="filename">cleanup.log</code>
96     </p></li><li class="listitem"><p>
97      remove no-longer-needed files from the archive directory
98     </p></li></ul></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-initdb.html" title="initdb">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-server.html" title="PostgreSQL Server Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-pgchecksums.html" title="pg_checksums">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">initdb</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">pg_checksums</span></td></tr></table></div></body></html>