archive_command
No restart — takes effect on reloadshell command template
The shell command that copies each completed WAL segment to durable storage.
What it does
When archive_mode is on, PostgreSQL calls archive_command for every finished WAL segment, substituting %p (full path) and %f (filename). It must return 0 on success — non-zero makes PostgreSQL retry. Most operators use a battle-tested backup tool here rather than a hand-rolled copy.
How to tune it
Use a real backup tool — pgBackRest, WAL-G, or barman — and let it generate the command. PostgreSQL 15+ also supports archive_library, a loadable module that avoids the per-segment shell-spawn overhead.
FAQ
- Why not just use 'cp %p /archive/%f' as archive_command?
- Plain cp doesn't handle the failure modes you need to survive: partial writes, missing directories, retention, atomicity. A backup tool's archive command (pgBackRest, WAL-G) handles those correctly and is reusable for restore.