codekingpro/portable-devtools
115k
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 16.3 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 an4 <code class="literal">archive_cleanup_command</code> to clean up WAL file archives when5 running as a standby server (see <a class="xref" href="warm-standby.html" title="27.2. Log-Shipping Standby Servers">Section 27.2</a>).6 <span class="application">pg_archivecleanup</span> can also be used as a standalone program to7 clean WAL file archives.8 </p><p>9 To configure a standby10 server to use <span class="application">pg_archivecleanup</span>, put this into its11 <code class="filename">postgresql.conf</code> configuration file:12</p><pre class="programlisting">13archive_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 segment16 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 files19 logically preceding the value of the <code class="literal">%r</code> argument will be removed20 from <em class="replaceable"><code>archivelocation</code></em>. This minimizes the number of files21 that need to be retained, while preserving crash-restart capability. Use of22 this parameter is appropriate if the <em class="replaceable"><code>archivelocation</code></em> is a23 transient staging area for this particular standby server, but24 <span class="emphasis"><em>not</em></span> when the <em class="replaceable"><code>archivelocation</code></em> is intended as a25 long-term WAL archive area, or when multiple standby servers are recovering26 from the same archive location.27 </p><p>28 When used as a standalone program all WAL files logically preceding the29 <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 the32 <em class="replaceable"><code>oldestkeptwalfile</code></em>. This treatment of <code class="filename">.backup</code>33 file name allows you to remove34 all WAL files archived prior to a specific base backup without error.35 For example, the following example will remove all files older than36 WAL file name <code class="filename">000000010000003700000010</code>:37</p><pre class="programlisting">38pg_archivecleanup -d archive 000000010000003700000010.00000020.backup39 40pg_archivecleanup: keep WAL file "archive/000000010000003700000010" and later41pg_archivecleanup: removing file "archive/00000001000000370000000F"42pg_archivecleanup: removing file "archive/00000001000000370000000E"43</pre><p>44 </p><p>45 <span class="application">pg_archivecleanup</span> assumes that46 <em class="replaceable"><code>archivelocation</code></em> is a directory readable and writable by the47 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">-d</code></span></dt><dd><p>52 Print lots of debug logging output on <code class="filename">stderr</code>.53 </p></dd><dt><span class="term"><code class="option">-n</code></span></dt><dd><p>54 Print the names of the files that would have been removed on <code class="filename">stdout</code> (performs a dry run).55 </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>56 Print the <span class="application">pg_archivecleanup</span> version and exit.57 </p></dd><dt><span class="term"><code class="option">-x</code> <em class="replaceable"><code>extension</code></em></span></dt><dd><p>58 Provide an extension59 that will be stripped from all file names before deciding if they60 should be deleted. This is typically useful for cleaning up archives61 that have been compressed during storage, and therefore have had an62 extension added by the compression program. For example: <code class="literal">-x63 .gz</code>.64 </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>65 Show help about <span class="application">pg_archivecleanup</span> command line66 arguments, and exit.67 </p></dd></dl></div><p>68 </p></div><div class="refsect1" id="id-1.9.5.4.7"><h2>Environment</h2><p>69 The environment variable <code class="envar">PG_COLOR</code> specifies whether to use70 color in diagnostic messages. Possible values are71 <code class="literal">always</code>, <code class="literal">auto</code> and72 <code class="literal">never</code>.73 </p></div><div class="refsect1" id="id-1.9.5.4.8"><h2>Notes</h2><p>74 <span class="application">pg_archivecleanup</span> is designed to work with75 <span class="productname">PostgreSQL</span> 8.0 and later when used as a standalone utility,76 or with <span class="productname">PostgreSQL</span> 9.0 and later when used as an77 archive cleanup command.78 </p><p>79 <span class="application">pg_archivecleanup</span> is written in C and has an80 easy-to-modify source code, with specifically designated sections to modify81 for your own needs82 </p></div><div class="refsect1" id="id-1.9.5.4.9"><h2>Examples</h2><p>On Linux or Unix systems, you might use:83</p><pre class="programlisting">84archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>cleanup.log'85</pre><p>86 where the archive directory is physically located on the standby server,87 so that the <code class="varname">archive_command</code> is accessing it across NFS,88 but the files are local to the standby.89 This will:90 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>91 produce debugging output in <code class="filename">cleanup.log</code>92 </p></li><li class="listitem"><p>93 remove no-longer-needed files from the archive directory94 </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 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">pg_checksums</span></td></tr></table></div></body></html>