dev

Deploy Postgres PITR

Point-in-time recovery via pgBackRest WAL archiving for standalone Postgres

Deploy Postgres PITR

/var/lib/postgresql/data

Postgres-PITR

Bucket

Just deployed

Deploy and Host Postgres PITR on Railway

PostgreSQL with point-in-time recovery powered by pgBackRest. Every committed transaction is continuously archived to a Railway Bucket, letting you restore your database to any specific timestamp within your retention window — down to the second.

About Hosting Postgres PITR

Hosting Postgres PITR on Railway provisions a Railway Bucket alongside your existing Postgres service and streams WAL (Write-Ahead Log) segments to it continuously using pgBackRest's async archiver. pgBackRest ships pre-installed in the Postgres image and activates automatically when WAL_ARCHIVE_BUCKET is detected on startup — no manual installation or configuration needed. Railway's Backups panel handles the full restore workflow: pick a target timestamp, and Railway provisions a new volume from the nearest base snapshot, replays WAL to your target, and promotes the database. Residual failover RPO is 60 seconds (archive_timeout) plus failover-detection time.

Common Use Cases

  • Recovering from accidental DROP TABLE, DELETE, or row-level data corruption
  • Rolling back a failed migration to a known-good state before changes were applied
  • Meeting compliance or audit requirements for point-in-time data recoverability
  • Debugging production incidents by inspecting the exact database state at any past moment
  • Creating a safety net before major schema changes or Postgres version upgrades

Dependencies for Postgres PITR Hosting

  • Postgres — A running Railway Postgres service (standalone). HA clusters use a dedicated rolling-restart flow to enable PITR without disrupting quorum.
  • Railway Bucket — Provisioned automatically by this template; stores WAL segments and full base backups.
  • pgBackRest — Pre-installed in the ghcr.io/railwayapp-templates/postgres-ssl image; no separate installation required.

Deployment Dependencies

Implementation Details

This template overlays six WAL_ARCHIVE_* environment variables onto your existing Postgres service. The image detects WAL_ARCHIVE_BUCKET on startup, writes archive_mode = on and archive_command into the Postgres configuration, runs stanza-create once, and begins pushing WAL segments asynchronously. A 5 GiB local spool buffer absorbs brief S3 outages without stalling Postgres. To restore, select a target timestamp in the Backups panel — Railway identifies the nearest base backup, provisions a new volume, and replays WAL forward using pgbackrest archive-get until the target time.

Why Deploy Postgres PITR on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Postgres PITR on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


Template Content