1 <!-- $PostgreSQL: pgsql/doc/src/sgml/pgstandby.sgml,v 2.6 2008/12/15 22:08:35 momjian Exp $ -->
4 <title>pg_standby</title>
6 <indexterm zone="pgstandby">
7 <primary>pg_standby</primary>
11 <application>pg_standby</> supports creation of a <quote>warm standby</>
12 database server. It is designed to be a production-ready program, as well
13 as a customizable template should you require specific modifications.
17 <application>pg_standby</> is designed to be a waiting
18 <literal>restore_command</literal>, which is needed to turn a standard
19 archive recovery into a warm standby operation. Other
20 configuration is required as well, all of which is described in the main
21 server manual (see <xref linkend="warm-standby">).
25 <application>pg_standby</application> features include:
30 Supports copy or link for restoring WAL files
35 Written in C, so very portable and easy to install
40 Easy-to-modify source code, with specifically designated
41 sections to modify for your own needs
46 Already tested on Linux and Windows
55 To configure a standby
56 server to use <application>pg_standby</>, put this into its
57 <filename>recovery.conf</filename> configuration file:
60 restore_command = 'pg_standby <replaceable>archiveDir</> %f %p %r'
63 where <replaceable>archiveDir</> is the directory from which WAL segment
64 files should be restored.
67 The full syntax of <application>pg_standby</>'s command line is
70 pg_standby <optional> <replaceable>option</> ... </optional> <replaceable>archivelocation</> <replaceable>nextwalfile</> <replaceable>xlogfilepath</> <optional> <replaceable>restartwalfile</> </optional>
73 When used within <literal>restore_command</literal>, the <literal>%f</> and
74 <literal>%p</> macros should be specified for <replaceable>nextwalfile</>
75 and <replaceable>xlogfilepath</> respectively, to provide the actual file
76 and path required for the restore.
79 If <replaceable>restartwalfile</> is specified, normally by using the
80 <literal>%r</literal> macro, then all WAL files logically preceding this
81 file will be removed from <replaceable>archivelocation</>. This minimizes
82 the number of files that need to be retained, while preserving
83 crash-restart capability. Use of this parameter is appropriate if the
84 <replaceable>archivelocation</> is a transient staging area for this
85 particular standby server, but <emphasis>not</> when the
86 <replaceable>archivelocation</> is intended as a long-term WAL archive area.
89 <application>pg_standby</application> assumes that
90 <replaceable>archivelocation</> is a directory readable by the
91 server-owning user. If <replaceable>restartwalfile</> (or <literal>-k</>)
93 the <replaceable>archivelocation</> directory must be writable too.
97 <title><application>pg_standby</> options</title>
101 <entry>Option</entry>
102 <entry>Default</entry>
103 <entry>Description</entry>
108 <entry><literal>-c</></entry>
111 Use <literal>cp</> or <literal>copy</> command to restore WAL files
116 <entry><literal>-d</></entry>
118 <entry>Print lots of debug logging output on <filename>stderr</>.</entry>
121 <entry><literal>-k</> <replaceable>numfiles</></entry>
124 Remove files from <replaceable>archivelocation</replaceable> so that
125 no more than this many WAL files before the current one are kept in the
126 archive. Zero (the default) means not to remove any files from
127 <replaceable>archivelocation</replaceable>.
128 This parameter will be silently ignored if
129 <replaceable>restartwalfile</replaceable> is specified, since that
130 specification method is more accurate in determining the correct
131 archive cut-off point.
132 Use of this parameter is <emphasis>deprecated</> as of
133 <productname>PostgreSQL</> 8.3; it is safer and more efficient to
134 specify a <replaceable>restartwalfile</replaceable> parameter. A too
135 small setting could result in removal of files that are still needed
136 for a restart of the standby server, while a too large setting wastes
141 <entry><literal>-l</></entry>
144 Use <literal>ln</> command to restore WAL files from archive.
145 Link is more efficient than copy, but the default is copy since link
146 will not work in all scenarios.
147 On Windows, this option uses the <literal>mklink</> command
148 to provide a file-to-file symbolic link. <literal>-l</> will
149 not work on versions of Windows prior to Vista.
153 <entry><literal>-r</> <replaceable>maxretries</></entry>
156 Set the maximum number of times to retry the copy or link command if it
157 fails. After each failure, we wait for <replaceable>sleeptime</> *
158 <replaceable>num_retries</>
159 so that the wait time increases progressively. So by default,
160 we will wait 5 secs, 10 secs, then 15 secs before reporting
161 the failure back to the standby server. This will be
162 interpreted as end of recovery and the standby will come
163 up fully as a result.
167 <entry><literal>-s</> <replaceable>sleeptime</></entry>
170 Set the number of seconds (up to 60) to sleep between tests to see
171 if the WAL file to be restored is available in the archive yet.
172 The default setting is not necessarily recommended;
173 consult <xref linkend="warm-standby"> for discussion.
177 <entry><literal>-t</> <replaceable>triggerfile</></entry>
180 Specify a trigger file whose presence should cause recovery to end
181 whether or not the next WAL file is available.
182 It is recommended that you use a structured filename to
183 avoid confusion as to which server is being triggered
184 when multiple servers exist on the same system; for example
185 <filename>/tmp/pgsql.trigger.5432</>.
189 <entry><literal>-w</> <replaceable>maxwaittime</></entry>
192 Set the maximum number of seconds to wait for the next WAL file,
193 after which recovery will end and the standby will come up.
194 A setting of zero (the default) means wait forever.
195 The default setting is not necessarily recommended;
196 consult <xref linkend="warm-standby"> for discussion.
204 <literal>--help</literal> is not supported since
205 <application>pg_standby</application> is not intended for interactive use,
206 except during development and testing.
212 <title>Examples</title>
214 <para>On Linux or Unix systems, you might use:</para>
217 archive_command = 'cp %p .../archive/%f'
219 restore_command = 'pg_standby -l -d -s 2 -t /tmp/pgsql.trigger.5442 .../archive %f %p %r 2>>standby.log'
222 where the archive directory is physically located on the standby server,
223 so that the <literal>archive_command</> is accessing it across NFS,
224 but the files are local to the standby (enabling use of <literal>ln</>).
230 use the <literal>ln</> command to restore WAL files from archive
235 produce debugging output in <filename>standby.log</>
240 sleep for 2 seconds between checks for next WAL file availability
245 stop waiting only when a trigger file called
246 <filename>/tmp/pgsql.trigger.5442</> appears
251 remove no-longer-needed files from the archive directory
256 <para>On Windows, you might use:</para>
259 archive_command = 'copy %p ...\\archive\\%f'
261 restore_command = 'pg_standby -d -s 5 -t C:\pgsql.trigger.5442 ...\archive %f %p %r 2>>standby.log'
264 Note that backslashes need to be doubled in the
265 <literal>archive_command</>, but <emphasis>not</emphasis> in the
266 <literal>restore_command</>. This will:
271 use the <literal>copy</> command to restore WAL files from archive
276 produce debugging output in <filename>standby.log</>
281 sleep for 5 seconds between checks for next WAL file availability
286 stop waiting only when a trigger file called
287 <filename>C:\pgsql.trigger.5442</> appears
292 remove no-longer-needed files from the archive directory
298 The <literal>copy</> command on Windows sets the final file size
299 before the file is completely copied, which would ordinarly confuse
300 <application>pg_standby</application>. Therefore
301 <application>pg_standby</application> waits <literal>sleeptime</>
302 seconds once it sees the proper file size. GNUWin32's <literal>cp</>
303 sets the file size only after the file copy is complete.
307 Using the Since the Windows example uses <literal>copy</> at both ends, either
308 or both servers might be accessing the archive directory across the
315 <title>Supported server versions</title>
318 <application>pg_standby</application> is designed to work with
319 <productname>PostgreSQL</> 8.2 and later.
322 <productname>PostgreSQL</> 8.3 provides the <literal>%r</literal> macro,
323 which is designed to let <application>pg_standby</application> know the
324 last file it needs to keep. With <productname>PostgreSQL</> 8.2, the
325 <literal>-k</literal> option must be used if archive cleanup is
326 required. This option remains available in 8.3, but its use is deprecated.
331 <title>Author</title>
334 Simon Riggs <email>simon@2ndquadrant.com</email>