Skip to content

feat(postgres): add clone command for point-in-time recovery - #855

Merged
frodesundby merged 2 commits into
mainfrom
feat/postgres-clone
Nov 18, 2026
Merged

frodesundby merged 2 commits into
mainfrom
feat/postgres-clone

Conversation

@frodesundby

@frodesundby frodesundby commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds nais postgres clone <source> <name>, which creates a new Postgres from the backups of an existing one in the same team and environment. The source is not changed and no applications are moved to the clone.

nais postgres clone my-postgres my-clone -t my-team                        # latest available point
nais postgres clone my-postgres my-clone -t my-team --at "2026-11-16 12:00"  # point in time, local time
  • --at is optional. A local time like "2026-11-16 12:00" or RFC 3339 with an offset is accepted, in whole seconds and not in the future. Without it the clone is made from now minus 10 minutes, to stay inside archived WAL.
  • Daylight saving: a local time skipped in spring is rejected; a repeated hour in autumn resolves to the earlier occurrence (the same as Console).
  • Version and extensions come from the source. HA, CPU, memory and disk default to the source's and can be overridden with --high-availability, --cpu, --memory and --disk-size. The disk cannot be smaller than the source's (enforced by the API).
  • The confirmation shows the source, the point in time, the earliest possible point, and for each setting whether it is inherited or overridden.
  • nais postgres get now shows Cloned from, Clone point and Clone status, and a recovery object in JSON (UTC).
  • schema.graphql is updated from the live API, which also pulls in unrelated PostgresCost and ImageVulnerabilityFacets.

It uses the existing createPostgres mutation with the optional recovery { sourcePostgres, targetTime } input, so no API or operator changes are needed. create is unchanged.

Testing

  • Unit tests for time parsing (Europe/Oslo, summer time, both daylight saving cases), the backup window, inheritance and overrides, an end-to-end command test against a fake API (the mutation input, and that invalid input never reaches create), and get output.
  • mise run test and mise run check pass.
  • Run against frogres in nav-dev (nais, dev-gcp) with the default point, now − 1 minute and now − 5 seconds. All three clones completed and were deleted afterwards.

Not verified

  • The data in a clone was not inspected, only that recovery completed.
  • A source with no writes (the log is only archived on activity) was not tested. The default 10-minute buffer is a heuristic for active databases, and a point after the last archived WAL of an idle database might not be recoverable.

nais postgres clone <source> <name> creates a new database from the source's backups in the same team and environment. The source is not changed and no applications are moved.

--at selects the point in time, as a local time like "2026-11-16 12:00" or RFC 3339 with an offset. Without it the clone is made from the latest available point, 10 minutes ago, to stay inside archived WAL. A local time skipped by a daylight saving change is rejected and a repeated one resolves to its earlier occurrence.

PostgreSQL version and extensions come from the source. High availability, CPU, memory and disk default to the source's and can be overridden; the disk cannot be smaller than the source's.

get now reports the clone source, point and status. Update the GraphQL schema from the live API.
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📝 Changelog preview

Below is a preview of the Changelog that will be added to the next release. Only commit messages that follow the Conventional Commits specification will be included in the Changelog.

v8.6.0 - 2026-11-18

Full Changelog: v8.5.0...v8.6.0

🚀 Features

  • (postgres) Add clone command for point-in-time recovery (94e7132)

🐛 Bug Fixes

  • (postgres) Resolve repeated local times using the zone's actual offsets (b49ee04)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The daylight-saving overlap check assumes a one-hour rollback, causing half-hour transitions to select a recovery point 30 minutes later than promised.

1 open issue
What changed in this PR

Adds nais postgres clone <source> <name> for point-in-time recovery using the existing creation mutation. Clones remain in the source’s team and environment without changing the source or moving applications.

Changes:

  • Adds optional recovery-time selection, backup-window validation, configuration overrides, and confirmation.
  • Extends postgres get with recovery origin, time, and progress in human-readable and JSON output.
  • Updates the GraphQL schema and generated client, with tests for cloning and recovery output.
File Description
schema.graphql Adds recovery types and refreshes cost and vulnerability fields.
internal/​postgres/​instance.go Makes recovery input optional in the creation mutation.
internal/​postgres/​get.go Queries recovery metadata.
internal/​postgres/​command/​postgres.go Registers the clone command.
internal/​postgres/​command/​get.go Displays recovery details in text and JSON.
internal/​postgres/​command/​flag/​flag.go Defines recovery-time and configuration flags.
internal/​postgres/​command/​clone.go Implements cloning, time parsing, validation, and confirmation.
internal/​postgres/​command/​clone_test.go Tests parsing, validation, mutation inputs, and recovery output.
internal/​postgres/​clone.go Fetches source configuration and backup-window metadata.
internal/​naisapi/​gql/​generated.go Generates client support for recovery inputs and queries.

Review effort: Balanced

Comment thread internal/postgres/command/clone.go Resolved
…ffsets

The overlap check assumed every clock change is one hour, so a half-hour change such as Australia/Lord_Howe resolved a repeated time to the later occurrence. Enumerate the offsets in effect around the date instead; a time that no offset produces does not exist, and a repeated one resolves to the earliest instant. Cover half-hour repeats and gaps.
@frodesundby
frodesundby merged commit b8717e9 into main Nov 18, 2026
22 checks passed
@frodesundby
frodesundby deleted the feat/postgres-clone branch November 18, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants