|
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/pgarchivecleanup.sgml,v 1.1 2010/06/14 17:25:24 sriggs Exp $ --> |
| 2 | + |
| 3 | +<sect1 id="pgarchivecleanup"> |
| 4 | + <title>pg_archivecleanup</title> |
| 5 | + |
| 6 | + <indexterm zone="pgarchivecleanup"> |
| 7 | + <primary>pg_archivecleanup</primary> |
| 8 | + </indexterm> |
| 9 | + |
| 10 | + <para> |
| 11 | + <application>pg_archivecleanup</> is designed to cleanup an archive when used |
| 12 | + as an <literal>archive_cleanup_command</literal> when running with |
| 13 | + <literal>standby_mode = on</literal>. <application>pg_archivecleanup</> can |
| 14 | + also be used as a standalone program to clean WAL file archives. |
| 15 | + </para> |
| 16 | + |
| 17 | + <para> |
| 18 | + <application>pg_archivecleanup</application> features include: |
| 19 | + </para> |
| 20 | + <itemizedlist> |
| 21 | + <listitem> |
| 22 | + <para> |
| 23 | + Written in C, so very portable and easy to install |
| 24 | + </para> |
| 25 | + </listitem> |
| 26 | + <listitem> |
| 27 | + <para> |
| 28 | + Easy-to-modify source code, with specifically designated |
| 29 | + sections to modify for your own needs |
| 30 | + </para> |
| 31 | + </listitem> |
| 32 | + </itemizedlist> |
| 33 | + |
| 34 | + <sect2> |
| 35 | + <title>Usage</title> |
| 36 | + |
| 37 | + <para> |
| 38 | + To configure a standby |
| 39 | + server to use <application>pg_archivecleanup</>, put this into its |
| 40 | + <filename>recovery.conf</filename> configuration file: |
| 41 | + </para> |
| 42 | + <programlisting> |
| 43 | +archive_cleanup_command = 'pg_archivecleanup <replaceable>archiveDir</> %r' |
| 44 | + </programlisting> |
| 45 | + <para> |
| 46 | + where <replaceable>archiveDir</> is the directory from which WAL segment |
| 47 | + files should be restored. |
| 48 | + </para> |
| 49 | + <para> |
| 50 | + When used within <literal>archive_cleanup_command</literal>, |
| 51 | + all WAL files logically preceding the value of the <literal>%r</> |
| 52 | + will be removed <replaceable>archivelocation</>. This minimizes |
| 53 | + the number of files that need to be retained, while preserving |
| 54 | + crash-restart capability. Use of this parameter is appropriate if the |
| 55 | + <replaceable>archivelocation</> is a transient staging area for this |
| 56 | + particular standby server, but <emphasis>not</> when the |
| 57 | + <replaceable>archivelocation</> is intended as a long-term WAL archive area. |
| 58 | + </para> |
| 59 | + <para> |
| 60 | + The full syntax of <application>pg_archivecleanup</>'s command line is |
| 61 | + </para> |
| 62 | + <synopsis> |
| 63 | +pg_archivecleanup <optional> <replaceable>option</> ... </optional> <replaceable>archivelocation</> <replaceable>restartwalfile</> |
| 64 | + </synopsis> |
| 65 | + <para> |
| 66 | + When used as a standalone program all WAL files logically preceding the |
| 67 | + <literal>restartwalfile</> will be removed <replaceable>archivelocation</>. |
| 68 | + In this mode, if you specify a .backup filename, then only the file prefix |
| 69 | + will be used as the <literal>restartwalfile</>. This allows you to remove |
| 70 | + all WAL files archived prior to a specific base backup without error. |
| 71 | + For example, the following example will remove all files older than |
| 72 | + WAL filename 000000010000003700000010: |
| 73 | + </para> |
| 74 | + <programlisting> |
| 75 | +pg_archivecleanup -d archive 000000010000003700000010.00000020.backup |
| 76 | + |
| 77 | +pg_archivecleanup: keep WAL files 000000010000003700000010 and later |
| 78 | +pg_archivecleanup: removing "archive/00000001000000370000000F" |
| 79 | +pg_archivecleanup: removing "archive/00000001000000370000000E" |
| 80 | + </programlisting> |
| 81 | + <para> |
| 82 | + <application>pg_archivecleanup</application> assumes that |
| 83 | + <replaceable>archivelocation</> is a directory readable and writable by the |
| 84 | + server-owning user. |
| 85 | + </para> |
| 86 | + </sect2> |
| 87 | + |
| 88 | + <sect2> |
| 89 | + <title><application>pg_archivecleanup</> Options</title> |
| 90 | + |
| 91 | + <para> |
| 92 | + <application>pg_archivecleanup</application> accepts the following command-line arguments: |
| 93 | + |
| 94 | + <variablelist> |
| 95 | + |
| 96 | + <varlistentry> |
| 97 | + <term><option>-d</option></term> |
| 98 | + <listitem> |
| 99 | + <para> |
| 100 | + Print lots of debug logging output on <filename>stderr</>. |
| 101 | + </para> |
| 102 | + </listitem> |
| 103 | + </varlistentry> |
| 104 | + |
| 105 | + </variablelist> |
| 106 | + </para> |
| 107 | + |
| 108 | + </sect2> |
| 109 | + |
| 110 | + <sect2> |
| 111 | + <title>Examples</title> |
| 112 | + |
| 113 | + <para>On Linux or Unix systems, you might use:</para> |
| 114 | + |
| 115 | + <programlisting> |
| 116 | +archive_cleanup_command = 'pg_archivecleanup -d .../archive %r 2>>cleanup.log' |
| 117 | + </programlisting> |
| 118 | + <para> |
| 119 | + where the archive directory is physically located on the standby server, |
| 120 | + so that the <literal>archive_command</> is accessing it across NFS, |
| 121 | + but the files are local to the standby. |
| 122 | + This will: |
| 123 | + </para> |
| 124 | + <itemizedlist> |
| 125 | + <listitem> |
| 126 | + <para> |
| 127 | + produce debugging output in <filename>standby.log</> |
| 128 | + </para> |
| 129 | + </listitem> |
| 130 | + <listitem> |
| 131 | + <para> |
| 132 | + remove no-longer-needed files from the archive directory |
| 133 | + </para> |
| 134 | + </listitem> |
| 135 | + </itemizedlist> |
| 136 | + |
| 137 | + </sect2> |
| 138 | + |
| 139 | + <sect2> |
| 140 | + <title>Supported server versions</title> |
| 141 | + |
| 142 | + <para> |
| 143 | + <application>pg_archivecleanup</application> is designed to work with |
| 144 | + <productname>PostgreSQL</> 8.0 and later when used as a standalone utility, |
| 145 | + or with <productname>PostgreSQL</> 9.0 and later when used as an |
| 146 | + archive cleanup command. |
| 147 | + </para> |
| 148 | + </sect2> |
| 149 | + |
| 150 | + <sect2> |
| 151 | + <title>Author</title> |
| 152 | + |
| 153 | + <para> |
| 154 | + Simon Riggs <email>simon@2ndquadrant.com</email> |
| 155 | + </para> |
| 156 | + </sect2> |
| 157 | + |
| 158 | +</sect1> |
0 commit comments