How does point-in-time recovery work in PostgreSQL?
AdvancedConceptPostgreSQL
Answer
Short answer
PITR combines a base backup (a copy of the data directory) with continuously archived WAL files. To recover, you restore the base backup and replay WAL up to a chosen moment — for example one second before someone ran a bad DELETE.
Pieces
# postgresql.conf
wal_level = replica
archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p' # or copy to S3
Base backups with pg_basebackup or tools like pgBackRest, Barman or WAL-G.
Recovery (PG 12+)
# postgresql.conf on the restored server
restore_command = 'pgbackrest --stanza=main archive-get %f "%p"'
recovery_target_time = '2026-11-26 14:31:59+05:30'
recovery_target_action = 'promote'
touch $PGDATA/recovery.signal && systemctl start postgresql
Managed services
RDS / Azure Flexible Server do all of this for you: choose "restore to point in time" and a timestamp within the retention window (up to 35 days). It creates a new instance.
What to say in the interview
"PITR needs a base backup plus archived WAL. You restore the base backup and replay WAL to a recovery_target_time just before the incident. We use pgBackRest or WAL-G self-managed, and on RDS it's a console/API restore to a new instance within the retention window."
More on PostgreSQL
How do you set up PostgreSQL and log in with psql?BeginnerHow do you create a database, tables, users and query data in PostgreSQL?BeginnerHow do you back up and restore a PostgreSQL database?BeginnerWhat is PostgreSQL and why is it so popular?BeginnerHow is PostgreSQL organised: cluster, database, schema and table?BeginnerHow do you connect to PostgreSQL from the command line?Beginner