Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 9 min read How-to mediumAdept

Time Travel with Serverless Postgres

Neon's copy-on-write database branching can recover from accidental data loss by creating branches at a past point in time or at a specific Postgres WAL Log Sequence Number (LSN). When the exact moment of a destructive query is unknown, you can binary-search the LSN range between a known-good branch and the current state. A Python script uses the Neon API to create a branch at each midpoint, run a validation query, and delete the branch. It converges on the exact LSN where the data broke, and you then branch from that point to restore.

Related posts

  • Using Neon branching for instant Point in time recovery

    Neon mediumAdept

    Neon's copy-on-write branching can restore a Postgres database to an earlier point in time by creating a branch from a timestamp or LSN within the retained WAL history window (seven days by default). Creating the branch from the console gives you a new compute endpoint and so a new connection string. To keep the existing connection string, a TypeScript script using the Neon API client creates an endpoint-less branch at the target timestamp, reassigns the existing compute endpoint to it, and sets it as the primary branch. Afterward, rename the old branch and delete its data to avoid storage charges.

  • Announcing Point-in-Time Restore

    Neon mediumAdept

    Neon's Branch Restore feature, now in the Neon Console, restores a Postgres branch to any LSN or timestamp within a configurable history retention window of up to 30 days. This is possible because Neon's separated storage and compute retain WAL history. Time Travel Assist lets you query the database as it was at a chosen point before committing, so you can pinpoint when data loss happened. Restores take a few seconds and briefly drop connections, much like a cold start. The post contrasts this with self-managed approaches: pg_dump offers no point-in-time recovery, while pg_basebackup with WAL archiving, pgBackRest or Barman can do it but cost operational effort.

  • I Dropped a Table in Production—Now What?

    Neon mediumAdept

    Neon's instant point-in-time recovery creates a new copy-on-write branch at a moment just before a dropped table. That branch is available in about one second regardless of database size, and production keeps running while it is created. Two recovery routes follow from this. One is to pg_dump the table out of the recovered branch and import it into production, which keeps all data written after the drop. The other is to use Branch Restore to swap production onto the recovered branch under the same connection string, which discards post-drop writes. RDS, by contrast, restores a snapshot to a new instance and replays WAL, which can take hours for multi-terabyte databases.

  • Point In Time Recovery Under the Hood in Serverless Postgres

    Neon mediumAdept

    Neon implements point-in-time recovery by treating Postgres as its WAL. WAL is streamed to Paxos-backed Safekeepers, then to multi-tenant Pageservers that build immutable image and delta layers keyed by key range and LSN. The post contrasts this with traditional Postgres PITR, which needs base backups, WAL archiving, tools like Barman and a standby server. Neon's GetPage@LSN instead rebuilds any page at any LSN on demand. Time Travel Assist uses this through ephemeral copy-on-write branches with a 10-second TTL, so you can query a past state before restoring.

  • Practical Guide to Database Branching

    Neon mediumAdept

    Neon's copy-on-write storage makes Postgres database branches instant and cheap: each branch shares the parent's base data, gets its own autoscaling compute that scales to zero, and can be created from any point within the history retention window. Recommended workflows include a protected production branch whose child branches get new credentials automatically, staging and per-developer or per-pull-request branches that are periodically reset from the parent, and anonymized branches (beta) as the parent when data contains PII. Point-in-time branches support recovering dropped tables, debugging bad migrations and audits without rolling back production. Ephemeral branches should be deleted promptly, and the restore window (6 hours on the Free plan, 1 day on paid plans) can be shortened to cut storage costs.

The quest for software engineering knowledge.

Look:
Layout: