2 19.5. Write Ahead Log #
8 19.5.5. Archive Recovery
9 19.5.6. Recovery Target
10 19.5.7. WAL Summarization
12 For additional information on tuning these settings, see Section 28.5.
17 wal_level determines how much information is written to the WAL.
18 The default value is replica, which writes enough data to
19 support WAL archiving and replication, including running
20 read-only queries on a standby server. minimal removes all
21 logging except the information required to recover from a crash
22 or immediate shutdown. Finally, logical adds information
23 necessary to support logical decoding. Each level includes the
24 information logged at all lower levels. This parameter can only
25 be set at server start.
27 The minimal level generates the least WAL volume. It logs no row
28 information for permanent relations in transactions that create
29 or rewrite them. This can make operations much faster (see
30 Section 14.4.7). Operations that initiate this optimization
33 ALTER ... SET TABLESPACE
36 REFRESH MATERIALIZED VIEW (without CONCURRENTLY)
40 However, minimal WAL does not contain sufficient information for
41 point-in-time recovery, so replica or higher must be used to
42 enable continuous archiving (archive_mode) and streaming binary
43 replication. In fact, the server will not even start in this
44 mode if max_wal_senders is non-zero. Note that changing
45 wal_level to minimal makes previous base backups unusable for
46 point-in-time recovery and standby servers.
48 In logical level, the same information is logged as with
49 replica, plus information needed to extract logical change sets
50 from the WAL. Using a level of logical will increase the WAL
51 volume, particularly if many tables are configured for REPLICA
52 IDENTITY FULL and many UPDATE and DELETE statements are
55 In releases prior to 9.6, this parameter also allowed the values
56 archive and hot_standby. These are still accepted but mapped to
60 If this parameter is on, the PostgreSQL server will try to make
61 sure that updates are physically written to disk, by issuing
62 fsync() system calls or various equivalent methods (see
63 wal_sync_method). This ensures that the database cluster can
64 recover to a consistent state after an operating system or
67 While turning off fsync is often a performance benefit, this can
68 result in unrecoverable data corruption in the event of a power
69 failure or system crash. Thus it is only advisable to turn off
70 fsync if you can easily recreate your entire database from
73 Examples of safe circumstances for turning off fsync include the
74 initial loading of a new database cluster from a backup file,
75 using a database cluster for processing a batch of data after
76 which the database will be thrown away and recreated, or for a
77 read-only database clone which gets recreated frequently and is
78 not used for failover. High quality hardware alone is not a
79 sufficient justification for turning off fsync.
81 For reliable recovery when changing fsync off to on, it is
82 necessary to force all modified buffers in the kernel to durable
83 storage. This can be done while the cluster is shutdown or while
84 fsync is on by running initdb --sync-only, running sync,
85 unmounting the file system, or rebooting the server.
87 In many situations, turning off synchronous_commit for
88 noncritical transactions can provide much of the potential
89 performance benefit of turning off fsync, without the attendant
90 risks of data corruption.
92 fsync can only be set in the postgresql.conf file or on the
93 server command line. If you turn this parameter off, also
94 consider turning off full_page_writes.
96 synchronous_commit (enum) #
97 Specifies how much WAL processing must complete before the
98 database server returns a “success” indication to the client.
99 Valid values are remote_apply, on (the default), remote_write,
102 If synchronous_standby_names is empty, the only meaningful
103 settings are on and off; remote_apply, remote_write and local
104 all provide the same local synchronization level as on. The
105 local behavior of all non-off modes is to wait for local flush
106 of WAL to disk. In off mode, there is no waiting, so there can
107 be a delay between when success is reported to the client and
108 when the transaction is later guaranteed to be safe against a
109 server crash. (The maximum delay is three times
110 wal_writer_delay.) Unlike fsync, setting this parameter to off
111 does not create any risk of database inconsistency: an operating
112 system or database crash might result in some recent
113 allegedly-committed transactions being lost, but the database
114 state will be just the same as if those transactions had been
115 aborted cleanly. So, turning synchronous_commit off can be a
116 useful alternative when performance is more important than exact
117 certainty about the durability of a transaction. For more
118 discussion see Section 28.4.
120 If synchronous_standby_names is non-empty, synchronous_commit
121 also controls whether transaction commits will wait for their
122 WAL records to be processed on the standby server(s).
124 When set to remote_apply, commits will wait until replies from
125 the current synchronous standby(s) indicate they have received
126 the commit record of the transaction and applied it, so that it
127 has become visible to queries on the standby(s), and also
128 written to durable storage on the standbys. This will cause much
129 larger commit delays than previous settings since it waits for
130 WAL replay. When set to on, commits wait until replies from the
131 current synchronous standby(s) indicate they have received the
132 commit record of the transaction and flushed it to durable
133 storage. This ensures the transaction will not be lost unless
134 both the primary and all synchronous standbys suffer corruption
135 of their database storage. When set to remote_write, commits
136 will wait until replies from the current synchronous standby(s)
137 indicate they have received the commit record of the transaction
138 and written it to their file systems. This setting ensures data
139 preservation if a standby instance of PostgreSQL crashes, but
140 not if the standby suffers an operating-system-level crash
141 because the data has not necessarily reached durable storage on
142 the standby. The setting local causes commits to wait for local
143 flush to disk, but not for replication. This is usually not
144 desirable when synchronous replication is in use, but is
145 provided for completeness.
147 This parameter can be changed at any time; the behavior for any
148 one transaction is determined by the setting in effect when it
149 commits. It is therefore possible, and useful, to have some
150 transactions commit synchronously and others asynchronously. For
151 example, to make a single multistatement transaction commit
152 asynchronously when the default is the opposite, issue SET LOCAL
153 synchronous_commit TO OFF within the transaction.
155 Table 19.1 summarizes the capabilities of the synchronous_commit
158 Table 19.1. synchronous_commit Modes
160 synchronous_commit setting local durable commit standby durable commit
161 after PG crash standby durable commit after OS crash standby query
169 wal_sync_method (enum) #
170 Method used for forcing WAL updates out to disk. If fsync is off
171 then this setting is irrelevant, since WAL file updates will not
172 be forced out at all. Possible values are:
174 + open_datasync (write WAL files with open() option O_DSYNC)
175 + fdatasync (call fdatasync() at each commit)
176 + fsync (call fsync() at each commit)
177 + fsync_writethrough (call fsync() at each commit, forcing
178 write-through of any disk write cache)
179 + open_sync (write WAL files with open() option O_SYNC)
181 Not all of these choices are available on all platforms. The
182 default is the first method in the above list that is supported
183 by the platform, except that fdatasync is the default on Linux
184 and FreeBSD. The default is not necessarily ideal; it might be
185 necessary to change this setting or other aspects of your system
186 configuration in order to create a crash-safe configuration or
187 achieve optimal performance. These aspects are discussed in
188 Section 28.1. This parameter can only be set in the
189 postgresql.conf file or on the server command line.
191 full_page_writes (boolean) #
192 When this parameter is on, the PostgreSQL server writes the
193 entire content of each disk page to WAL during the first
194 modification of that page after a checkpoint. This is needed
195 because a page write that is in process during an operating
196 system crash might be only partially completed, leading to an
197 on-disk page that contains a mix of old and new data. The
198 row-level change data normally stored in WAL will not be enough
199 to completely restore such a page during post-crash recovery.
200 Storing the full page image guarantees that the page can be
201 correctly restored, but at the price of increasing the amount of
202 data that must be written to WAL. (Because WAL replay always
203 starts from a checkpoint, it is sufficient to do this during the
204 first change of each page after a checkpoint. Therefore, one way
205 to reduce the cost of full-page writes is to increase the
206 checkpoint interval parameters.)
208 Turning this parameter off speeds normal operation, but might
209 lead to either unrecoverable data corruption, or silent data
210 corruption, after a system failure. The risks are similar to
211 turning off fsync, though smaller, and it should be turned off
212 only based on the same circumstances recommended for that
215 Turning off this parameter does not affect use of WAL archiving
216 for point-in-time recovery (PITR) (see Section 25.3).
218 This parameter can only be set in the postgresql.conf file or on
219 the server command line. The default is on.
221 wal_log_hints (boolean) #
222 When this parameter is on, the PostgreSQL server writes the
223 entire content of each disk page to WAL during the first
224 modification of that page after a checkpoint, even for
225 non-critical modifications of so-called hint bits.
227 If data checksums are enabled, hint bit updates are always
228 WAL-logged and this setting is ignored. You can use this setting
229 to test how much extra WAL-logging would occur if your database
230 had data checksums enabled.
232 This parameter can only be set at server start. The default
235 wal_compression (enum) #
236 This parameter enables compression of WAL using the specified
237 compression method. When enabled, the PostgreSQL server
238 compresses full page images written to WAL (e.g. when
239 full_page_writes is on, during a base backup, etc.). A
240 compressed page image will be decompressed during WAL replay.
241 The supported methods are pglz, lz4 (if PostgreSQL was compiled
242 with --with-lz4) and zstd (if PostgreSQL was compiled with
243 --with-zstd). The default value is off. Only superusers and
244 users with the appropriate SET privilege can change this
247 Enabling compression can reduce the WAL volume without
248 increasing the risk of unrecoverable data corruption, but at the
249 cost of some extra CPU spent on the compression during WAL
250 logging and on the decompression during WAL replay.
252 wal_init_zero (boolean) #
253 If set to on (the default), this option causes new WAL files to
254 be filled with zeroes. On some file systems, this ensures that
255 space is allocated before we need to write WAL records. However,
256 Copy-On-Write (COW) file systems may not benefit from this
257 technique, so the option is given to skip the unnecessary work.
258 If set to off, only the final byte is written when the file is
259 created so that it has the expected size.
261 wal_recycle (boolean) #
262 If set to on (the default), this option causes WAL files to be
263 recycled by renaming them, avoiding the need to create new ones.
264 On COW file systems, it may be faster to create new ones, so the
265 option is given to disable this behavior.
267 wal_buffers (integer) #
268 The amount of shared memory used for WAL data that has not yet
269 been written to disk. The default setting of -1 selects a size
270 equal to 1/32nd (about 3%) of shared_buffers, but not less than
271 64kB nor more than the size of one WAL segment, typically 16MB.
272 This value can be set manually if the automatic choice is too
273 large or too small, but any positive value less than 32kB will
274 be treated as 32kB. If this value is specified without units, it
275 is taken as WAL blocks, that is XLOG_BLCKSZ bytes, typically
276 8kB. This parameter can only be set at server start.
278 The contents of the WAL buffers are written out to disk at every
279 transaction commit, so extremely large values are unlikely to
280 provide a significant benefit. However, setting this value to at
281 least a few megabytes can improve write performance on a busy
282 server where many clients are committing at once. The
283 auto-tuning selected by the default setting of -1 should give
284 reasonable results in most cases.
286 wal_writer_delay (integer) #
287 Specifies how often the WAL writer flushes WAL, in time terms.
288 After flushing WAL the writer sleeps for the length of time
289 given by wal_writer_delay, unless woken up sooner by an
290 asynchronously committing transaction. If the last flush
291 happened less than wal_writer_delay ago and less than
292 wal_writer_flush_after worth of WAL has been produced since,
293 then WAL is only written to the operating system, not flushed to
294 disk. If this value is specified without units, it is taken as
295 milliseconds. The default value is 200 milliseconds (200ms).
296 Note that on some systems, the effective resolution of sleep
297 delays is 10 milliseconds; setting wal_writer_delay to a value
298 that is not a multiple of 10 might have the same results as
299 setting it to the next higher multiple of 10. This parameter can
300 only be set in the postgresql.conf file or on the server command
303 wal_writer_flush_after (integer) #
304 Specifies how often the WAL writer flushes WAL, in volume terms.
305 If the last flush happened less than wal_writer_delay ago and
306 less than wal_writer_flush_after worth of WAL has been produced
307 since, then WAL is only written to the operating system, not
308 flushed to disk. If wal_writer_flush_after is set to 0 then WAL
309 data is always flushed immediately. If this value is specified
310 without units, it is taken as WAL blocks, that is XLOG_BLCKSZ
311 bytes, typically 8kB. The default is 1MB. This parameter can
312 only be set in the postgresql.conf file or on the server command
315 wal_skip_threshold (integer) #
316 When wal_level is minimal and a transaction commits after
317 creating or rewriting a permanent relation, this setting
318 determines how to persist the new data. If the data is smaller
319 than this setting, write it to the WAL log; otherwise, use an
320 fsync of affected files. Depending on the properties of your
321 storage, raising or lowering this value might help if such
322 commits are slowing concurrent transactions. If this value is
323 specified without units, it is taken as kilobytes. The default
324 is two megabytes (2MB).
326 commit_delay (integer) #
327 Setting commit_delay adds a time delay before a WAL flush is
328 initiated. This can improve group commit throughput by allowing
329 a larger number of transactions to commit via a single WAL
330 flush, if system load is high enough that additional
331 transactions become ready to commit within the given interval.
332 However, it also increases latency by up to the commit_delay for
333 each WAL flush. Because the delay is just wasted if no other
334 transactions become ready to commit, a delay is only performed
335 if at least commit_siblings other transactions are active when a
336 flush is about to be initiated. Also, no delays are performed if
337 fsync is disabled. If this value is specified without units, it
338 is taken as microseconds. The default commit_delay is zero (no
339 delay). Only superusers and users with the appropriate SET
340 privilege can change this setting.
342 In PostgreSQL releases prior to 9.3, commit_delay behaved
343 differently and was much less effective: it affected only
344 commits, rather than all WAL flushes, and waited for the entire
345 configured delay even if the WAL flush was completed sooner.
346 Beginning in PostgreSQL 9.3, the first process that becomes
347 ready to flush waits for the configured interval, while
348 subsequent processes wait only until the leader completes the
351 commit_siblings (integer) #
352 Minimum number of concurrent open transactions to require before
353 performing the commit_delay delay. A larger value makes it more
354 probable that at least one other transaction will become ready
355 to commit during the delay interval. The default is five
358 19.5.2. Checkpoints #
360 checkpoint_timeout (integer) #
361 Maximum time between automatic WAL checkpoints. If this value is
362 specified without units, it is taken as seconds. The valid range
363 is between 30 seconds and one day. The default is five minutes
364 (5min). Increasing this parameter can increase the amount of
365 time needed for crash recovery. This parameter can only be set
366 in the postgresql.conf file or on the server command line.
368 checkpoint_completion_target (floating point) #
369 Specifies the target of checkpoint completion, as a fraction of
370 total time between checkpoints. The default is 0.9, which
371 spreads the checkpoint across almost all of the available
372 interval, providing fairly consistent I/O load while also
373 leaving some time for checkpoint completion overhead. Reducing
374 this parameter is not recommended because it causes the
375 checkpoint to complete faster. This results in a higher rate of
376 I/O during the checkpoint followed by a period of less I/O
377 between the checkpoint completion and the next scheduled
378 checkpoint. This parameter can only be set in the
379 postgresql.conf file or on the server command line.
381 checkpoint_flush_after (integer) #
382 Whenever more than this amount of data has been written while
383 performing a checkpoint, attempt to force the OS to issue these
384 writes to the underlying storage. Doing so will limit the amount
385 of dirty data in the kernel's page cache, reducing the
386 likelihood of stalls when an fsync is issued at the end of the
387 checkpoint, or when the OS writes data back in larger batches in
388 the background. Often that will result in greatly reduced
389 transaction latency, but there also are some cases, especially
390 with workloads that are bigger than shared_buffers, but smaller
391 than the OS's page cache, where performance might degrade. This
392 setting may have no effect on some platforms. If this value is
393 specified without units, it is taken as blocks, that is BLCKSZ
394 bytes, typically 8kB. The valid range is between 0, which
395 disables forced writeback, and 2MB. The default is 256kB on
396 Linux, 0 elsewhere. (If BLCKSZ is not 8kB, the default and
397 maximum values scale proportionally to it.) This parameter can
398 only be set in the postgresql.conf file or on the server command
401 checkpoint_warning (integer) #
402 Write a message to the server log if checkpoints caused by the
403 filling of WAL segment files happen closer together than this
404 amount of time (which suggests that max_wal_size ought to be
405 raised). If this value is specified without units, it is taken
406 as seconds. The default is 30 seconds (30s). Zero disables the
407 warning. No warnings will be generated if checkpoint_timeout is
408 less than checkpoint_warning. This parameter can only be set in
409 the postgresql.conf file or on the server command line.
411 max_wal_size (integer) #
412 Maximum size to let the WAL grow during automatic checkpoints.
413 This is a soft limit; WAL size can exceed max_wal_size under
414 special circumstances, such as heavy load, a failing
415 archive_command or archive_library, or a high wal_keep_size
416 setting. If this value is specified without units, it is taken
417 as megabytes. The default is 1 GB. Increasing this parameter can
418 increase the amount of time needed for crash recovery. This
419 parameter can only be set in the postgresql.conf file or on the
422 min_wal_size (integer) #
423 As long as WAL disk usage stays below this setting, old WAL
424 files are always recycled for future use at a checkpoint, rather
425 than removed. This can be used to ensure that enough WAL space
426 is reserved to handle spikes in WAL usage, for example when
427 running large batch jobs. If this value is specified without
428 units, it is taken as megabytes. The default is 80 MB. This
429 parameter can only be set in the postgresql.conf file or on the
434 archive_mode (enum) #
435 When archive_mode is enabled, completed WAL segments are sent to
436 archive storage by setting archive_command or archive_library.
437 In addition to off, to disable, there are two modes: on, and
438 always. During normal operation, there is no difference between
439 the two modes, but when set to always the WAL archiver is
440 enabled also during archive recovery or standby mode. In always
441 mode, all files restored from the archive or streamed with
442 streaming replication will be archived (again). See
443 Section 26.2.9 for details.
445 archive_mode is a separate setting from archive_command and
446 archive_library so that archive_command and archive_library can
447 be changed without leaving archiving mode. This parameter can
448 only be set at server start. archive_mode cannot be enabled when
449 wal_level is set to minimal.
451 archive_command (string) #
452 The local shell command to execute to archive a completed WAL
453 file segment. Any %p in the string is replaced by the path name
454 of the file to archive, and any %f is replaced by only the file
455 name. (The path name is relative to the working directory of the
456 server, i.e., the cluster's data directory.) Use %% to embed an
457 actual % character in the command. It is important for the
458 command to return a zero exit status only if it succeeds. For
459 more information see Section 25.3.1.
461 This parameter can only be set in the postgresql.conf file or on
462 the server command line. It is only used if archive_mode was
463 enabled at server start and archive_library is set to an empty
464 string. If both archive_command and archive_library are set, an
465 error will be raised. If archive_command is an empty string (the
466 default) while archive_mode is enabled (and archive_library is
467 set to an empty string), WAL archiving is temporarily disabled,
468 but the server continues to accumulate WAL segment files in the
469 expectation that a command will soon be provided. Setting
470 archive_command to a command that does nothing but return true,
471 e.g., /bin/true (REM on Windows), effectively disables
472 archiving, but also breaks the chain of WAL files needed for
473 archive recovery, so it should only be used in unusual
476 archive_library (string) #
477 The library to use for archiving completed WAL file segments. If
478 set to an empty string (the default), archiving via shell is
479 enabled, and archive_command is used. If both archive_command
480 and archive_library are set, an error will be raised. Otherwise,
481 the specified shared library is used for archiving. The WAL
482 archiver process is restarted by the postmaster when this
483 parameter changes. For more information, see Section 25.3.1 and
486 This parameter can only be set in the postgresql.conf file or on
487 the server command line.
489 archive_timeout (integer) #
490 The archive_command or archive_library is only invoked for
491 completed WAL segments. Hence, if your server generates little
492 WAL traffic (or has slack periods where it does so), there could
493 be a long delay between the completion of a transaction and its
494 safe recording in archive storage. To limit how old unarchived
495 data can be, you can set archive_timeout to force the server to
496 switch to a new WAL segment file periodically. When this
497 parameter is greater than zero, the server will switch to a new
498 segment file whenever this amount of time has elapsed since the
499 last segment file switch, and there has been any database
500 activity, including a single checkpoint (checkpoints are skipped
501 if there is no database activity). Note that archived files that
502 are closed early due to a forced switch are still the same
503 length as completely full files. Therefore, it is unwise to use
504 a very short archive_timeout — it will bloat your archive
505 storage. archive_timeout settings of a minute or so are usually
506 reasonable. You should consider using streaming replication,
507 instead of archiving, if you want data to be copied off the
508 primary server more quickly than that. If this value is
509 specified without units, it is taken as seconds. This parameter
510 can only be set in the postgresql.conf file or on the server
515 This section describes the settings that apply to recovery in general,
516 affecting crash recovery, streaming replication and archive-based
519 recovery_prefetch (enum) #
520 Whether to try to prefetch blocks that are referenced in the WAL
521 that are not yet in the buffer pool, during recovery. Valid
522 values are off, on and try (the default). The setting try
523 enables prefetching only if the operating system provides
524 support for issuing read-ahead advice.
526 Prefetching blocks that will soon be needed can reduce I/O wait
527 times during recovery with some workloads. See also the
528 wal_decode_buffer_size and maintenance_io_concurrency settings,
529 which limit prefetching activity.
531 wal_decode_buffer_size (integer) #
532 A limit on how far ahead the server can look in the WAL, to find
533 blocks to prefetch. If this value is specified without units, it
534 is taken as bytes. The default is 512kB.
536 19.5.5. Archive Recovery #
538 This section describes the settings that apply only for the duration of
539 the recovery. They must be reset for any subsequent recovery you wish
542 “Recovery” covers using the server as a standby or for executing a
543 targeted recovery. Typically, standby mode would be used to provide
544 high availability and/or read scalability, whereas a targeted recovery
545 is used to recover from data loss.
547 To start the server in standby mode, create a file called
548 standby.signal in the data directory. The server will enter recovery
549 and will not stop recovery when the end of archived WAL is reached, but
550 will keep trying to continue recovery by connecting to the sending
551 server as specified by the primary_conninfo setting and/or by fetching
552 new WAL segments using restore_command. For this mode, the parameters
553 from this section and Section 19.6.3 are of interest. Parameters from
554 Section 19.5.6 will also be applied but are typically not useful in
557 To start the server in targeted recovery mode, create a file called
558 recovery.signal in the data directory. If both standby.signal and
559 recovery.signal files are created, standby mode takes precedence.
560 Targeted recovery mode ends when the archived WAL is fully replayed, or
561 when recovery_target is reached. In this mode, the parameters from both
562 this section and Section 19.5.6 will be used.
564 restore_command (string) #
565 The local shell command to execute to retrieve an archived
566 segment of the WAL file series. This parameter is required for
567 archive recovery, but optional for streaming replication. Any %f
568 in the string is replaced by the name of the file to retrieve
569 from the archive, and any %p is replaced by the copy destination
570 path name on the server. (The path name is relative to the
571 current working directory, i.e., the cluster's data directory.)
572 Any %r is replaced by the name of the file containing the last
573 valid restart point. That is the earliest file that must be kept
574 to allow a restore to be restartable, so this information can be
575 used to truncate the archive to just the minimum required to
576 support restarting from the current restore. %r is typically
577 only used by warm-standby configurations (see Section 26.2).
578 Write %% to embed an actual % character.
580 It is important for the command to return a zero exit status
581 only if it succeeds. The command will be asked for file names
582 that are not present in the archive; it must return nonzero when
585 restore_command = 'cp /mnt/server/archivedir/%f "%p"'
586 restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
588 An exception is that if the command was terminated by a signal
589 (other than SIGTERM, which is used as part of a database server
590 shutdown) or an error by the shell (such as command not found),
591 then recovery will abort and the server will not start up.
593 This parameter can only be set in the postgresql.conf file or on
594 the server command line.
596 archive_cleanup_command (string) #
597 This optional parameter specifies a shell command that will be
598 executed at every restartpoint. The purpose of
599 archive_cleanup_command is to provide a mechanism for cleaning
600 up old archived WAL files that are no longer needed by the
601 standby server. Any %r is replaced by the name of the file
602 containing the last valid restart point. That is the earliest
603 file that must be kept to allow a restore to be restartable, and
604 so all files earlier than %r may be safely removed. This
605 information can be used to truncate the archive to just the
606 minimum required to support restart from the current restore.
607 The pg_archivecleanup module is often used in
608 archive_cleanup_command for single-standby configurations, for
611 archive_cleanup_command = 'pg_archivecleanup /mnt/server/archivedir %r'
613 Note however that if multiple standby servers are restoring from
614 the same archive directory, you will need to ensure that you do
615 not delete WAL files until they are no longer needed by any of
616 the servers. archive_cleanup_command would typically be used in
617 a warm-standby configuration (see Section 26.2). Write %% to
618 embed an actual % character in the command.
620 If the command returns a nonzero exit status then a warning log
621 message will be written. An exception is that if the command was
622 terminated by a signal or an error by the shell (such as command
623 not found), a fatal error will be raised.
625 This parameter can only be set in the postgresql.conf file or on
626 the server command line.
628 recovery_end_command (string) #
629 This parameter specifies a shell command that will be executed
630 once only at the end of recovery. This parameter is optional.
631 The purpose of the recovery_end_command is to provide a
632 mechanism for cleanup following replication or recovery. Any %r
633 is replaced by the name of the file containing the last valid
634 restart point, like in archive_cleanup_command.
636 If the command returns a nonzero exit status then a warning log
637 message will be written and the database will proceed to start
638 up anyway. An exception is that if the command was terminated by
639 a signal or an error by the shell (such as command not found),
640 the database will not proceed with startup.
642 This parameter can only be set in the postgresql.conf file or on
643 the server command line.
645 19.5.6. Recovery Target #
647 By default, recovery will recover to the end of the WAL log. The
648 following parameters can be used to specify an earlier stopping point.
649 At most one of recovery_target, recovery_target_lsn,
650 recovery_target_name, recovery_target_time, or recovery_target_xid can
651 be used; if more than one of these is specified in the configuration
652 file, an error will be raised. These parameters can only be set at
655 recovery_target = 'immediate' #
656 This parameter specifies that recovery should end as soon as a
657 consistent state is reached, i.e., as early as possible. When
658 restoring from an online backup, this means the point where
659 taking the backup ended.
661 Technically, this is a string parameter, but 'immediate' is
662 currently the only allowed value.
664 recovery_target_name (string) #
665 This parameter specifies the named restore point (created with
666 pg_create_restore_point()) to which recovery will proceed.
668 recovery_target_time (timestamp) #
669 This parameter specifies the time stamp up to which recovery
670 will proceed. The precise stopping point is also influenced by
671 recovery_target_inclusive.
673 The value of this parameter is a time stamp in the same format
674 accepted by the timestamp with time zone data type, except that
675 you cannot use a time zone abbreviation (unless the
676 timezone_abbreviations variable has been set earlier in the
677 configuration file). Preferred style is to use a numeric offset
678 from UTC, or you can write a full time zone name, e.g.,
679 Europe/Helsinki not EEST.
681 recovery_target_xid (string) #
682 This parameter specifies the transaction ID up to which recovery
683 will proceed. Keep in mind that while transaction IDs are
684 assigned sequentially at transaction start, transactions can
685 complete in a different numeric order. The transactions that
686 will be recovered are those that committed before (and
687 optionally including) the specified one. The precise stopping
688 point is also influenced by recovery_target_inclusive.
690 recovery_target_lsn (pg_lsn) #
691 This parameter specifies the LSN of the write-ahead log location
692 up to which recovery will proceed. The precise stopping point is
693 also influenced by recovery_target_inclusive. This parameter is
694 parsed using the system data type pg_lsn.
696 The following options further specify the recovery target, and affect
697 what happens when the target is reached:
699 recovery_target_inclusive (boolean) #
700 Specifies whether to stop just after the specified recovery
701 target (on), or just before the recovery target (off). Applies
702 when recovery_target_lsn, recovery_target_time, or
703 recovery_target_xid is specified. This setting controls whether
704 transactions having exactly the target WAL location (LSN),
705 commit time, or transaction ID, respectively, will be included
706 in the recovery. Default is on.
708 recovery_target_timeline (string) #
709 Specifies recovering into a particular timeline. The value can
710 be a numeric timeline ID or a special value. The value current
711 recovers along the same timeline that was current when the base
712 backup was taken. The value latest recovers to the latest
713 timeline found in the archive, which is useful in a standby
714 server. latest is the default.
716 To specify a timeline ID in hexadecimal (for example, if
717 extracted from a WAL file name or history file), prefix it with
718 a 0x. For instance, if the WAL file name is
719 00000011000000A10000004F, then the timeline ID is 0x11 (or 17
722 You usually only need to set this parameter in complex
723 re-recovery situations, where you need to return to a state that
724 itself was reached after a point-in-time recovery. See
725 Section 25.3.6 for discussion.
727 recovery_target_action (enum) #
728 Specifies what action the server should take once the recovery
729 target is reached. The default is pause, which means recovery
730 will be paused. promote means the recovery process will finish
731 and the server will start to accept connections. Finally
732 shutdown will stop the server after reaching the recovery
735 The intended use of the pause setting is to allow queries to be
736 executed against the database to check if this recovery target
737 is the most desirable point for recovery. The paused state can
738 be resumed by using pg_wal_replay_resume() (see Table 9.99),
739 which then causes recovery to end. If this recovery target is
740 not the desired stopping point, then shut down the server,
741 change the recovery target settings to a later target and
742 restart to continue recovery.
744 The shutdown setting is useful to have the instance ready at the
745 exact replay point desired. The instance will still be able to
746 replay more WAL records (and in fact will have to replay WAL
747 records since the last checkpoint next time it is started).
749 Note that because recovery.signal will not be removed when
750 recovery_target_action is set to shutdown, any subsequent start
751 will end with immediate shutdown unless the configuration is
752 changed or the recovery.signal file is removed manually.
754 This setting has no effect if no recovery target is set. If
755 hot_standby is not enabled, a setting of pause will act the same
756 as shutdown. If the recovery target is reached while a promotion
757 is ongoing, a setting of pause will act the same as promote.
759 In any case, if a recovery target is configured but the archive
760 recovery ends before the target is reached, the server will shut
761 down with a fatal error.
763 19.5.7. WAL Summarization #
765 These settings control WAL summarization, a feature which must be
766 enabled in order to perform an incremental backup.
768 summarize_wal (boolean) #
769 Enables the WAL summarizer process. Note that WAL summarization
770 can be enabled either on a primary or on a standby. This
771 parameter can only be set in the postgresql.conf file or on the
772 server command line. The default is off.
774 The server cannot be started with summarize_wal=on if wal_level
775 is set to minimal. If summarize_wal=on is configured after
776 server startup while wal_level=minimal, the summarizer will run
777 but refuse to generate summary files for any WAL generated with
780 wal_summary_keep_time (integer) #
781 Configures the amount of time after which the WAL summarizer
782 automatically removes old WAL summaries. The file timestamp is
783 used to determine which files are old enough to remove.
784 Typically, you should set this comfortably higher than the time
785 that could pass between a backup and a later incremental backup
786 that depends on it. WAL summaries must be available for the
787 entire range of WAL records between the preceding backup and the
788 new one being taken; if not, the incremental backup will fail.
789 If this parameter is set to zero, WAL summaries will not be
790 automatically deleted, but it is safe to manually remove files
791 that you know will not be required for future incremental
792 backups. This parameter can only be set in the postgresql.conf
793 file or on the server command line. If this value is specified
794 without units, it is taken as minutes. The default is 10 days.
795 If summarize_wal = off, existing WAL summaries will not be
796 removed regardless of the value of this parameter, because the
797 WAL summarizer will not run.