PostgreSQL Backup & Recovery

archive_command

Learn how PostgreSQL archive_command works, what makes it reliable, and how to avoid hidden failure modes that break recovery.

Definition

Configuration parameter that specifies the shell command to execute to archive a completed WAL segment.

What archive_command Does

archive_command is the shell command PostgreSQL executes when a WAL segment is ready to be archived.

It receives placeholders for source path and WAL filename and must return success only when durable copy is complete.

A weak command script creates invisible recovery risk even if backups look healthy.

Reliability Requirements

  • Idempotent behavior for retries
  • Strict non-zero exit on failure
  • Durable destination and permission checks
  • Observability for failures and latency

Operational Pitfalls

Commands that suppress errors, write to unstable destinations, or skip integrity checks can break your WAL chain.

Treat archive_command as a critical production pipeline, not a one-time setup.

  • No silent ignore of failed copy operations
  • No best-effort local-only targets
  • No unmonitored script drift after infra changes

Related Recovery Path

archive_command writes WAL out; restore_command reads it back during recovery.

Both ends must be tested together in drills to validate actual PITR readiness.

Frequently Asked Questions

What should archive_command return on success?
It should return zero only when WAL is durably archived and retrievable.
Can archive_command use cloud object storage?
Yes. Many teams archive to S3-compatible object storage with versioning and lifecycle policies.
Why do archive_command failures become serious incidents?
Because failures can create WAL gaps that are discovered only during restore when PITR is needed most.
How should teams monitor archive_command?
Track failure rate, latency, queue/lag, and end-to-end restore viability in periodic drills.
Is a successful command log enough?
No. You also need artifact integrity and replay validation during restore tests.