DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Write-Ahead Log / Archive Recovery

restore_command

Sets the shell command that will be called to retrieve an archived WAL file.

  • Default: '' (empty)
  • Type: string
  • Applies: Reload

In plain words

The opposite of archive_command: during point-in-time recovery, or on a standby that reads from the archive, PostgreSQL runs this command to fetch each WAL file it needs. %f is the file name wanted, %p the path to copy it to. It must exit with a non-zero code when the file does not exist.

For DBAs and operators

Example: restore_command = 'cp /mnt/archive/%f "%p"' (or the restore command of your backup tool). Required for archive recovery (recovery.signal); optional on a standby (standby.signal) that can also stream. Since PostgreSQL 12 it lives in postgresql.conf, and since 14 it can be changed with a reload.

  • PostgreSQL asks for files that may not exist (e.g. 00000002.history, the next segment): "not found" with a non-zero exit is normal and not an error.
  • A command killed by a signal (other than SIGTERM at shutdown) or exit code above 125 aborts recovery.
  • %r gives the oldest file still needed (mostly for cleanup tools).

LOG: restored log file "00000001000000000000000C" from archive

On a standby the startup process cycles: archive via restore_command, then pg_wal, then streaming, waiting wal_retrieve_retry_interval between rounds when nothing is available.

How to change it

Change in postgresql.conf or ALTER SYSTEM, then run SELECT pg_reload_conf().

See it in context

Archiving and point-in-time recovery Startup process Crash recovery

Related parameters

archive_command archive_cleanup_command recovery_end_command recovery_target_time wal_retrieve_retry_interval

All Write-Ahead Log parameters