Cloud.PostgresSnapshot
An on-demand snapshot of a managed Postgres instance: “We flush
the primary’s data to disk first, so the snapshot is consistent.” The
deploy waits until the snapshot is available (a failed one fails with
WaitFailed and is removed again).
Snapshots and schedules. A PostgresScheduledSnapshot is a
schedule that takes snapshots of the same kind (snapshotType: "scheduled") on its own; this resource is one manual snapshot, taken
when it is created and kept until it is destroyed. Snapshots a schedule
took are never managed or listed by this resource.
Cost. The snapshot bills by sizeBytes (“The size of the disk when the
snapshot was taken, in bytes. We bill by this size.”); “Database snapshots
are billed like server snapshots and share their quotas.”
Replace, never update. The API has no update for it: a new name,
metadata or postgresId takes a new snapshot and deletes the old one.
The snapshot outlives its instance (deleting the instance keeps it), so it
is read and deleted by its own id.
Restore is not modelled. Restoring is an action, not desired state:
restore_postgres_snapshot creates a new instance from the snapshot
(new IDs, hostname and passwords) and restore_postgres rolls the origin
instance back. Neither fits a prop, and Postgres’s create takes no
snapshot id to pair with, so nothing here restores; call
Cloud.restorePostgresSnapshot from betterstack-alchemy/sdk/services
when you need one.
Ownership. The alchemy marker in metadata identifies the snapshots
this stack created: an interrupted create is found again by the next
deploy, and list returns only Alchemy-created snapshots.
Zone. A child doesn’t take its zone from its parent: it uses its own
availabilityZone, else the credentials’ zone. When the parent lives in
another zone, pass the parent’s along (availabilityZone: parent.availabilityZone), or every call for it answers NotFound.
Taking a snapshot
Section titled “Taking a snapshot”A snapshot before a risky migration
const db = yield* BetterStack.Cloud.Postgres("db", { type: "PG1" });const beforeMigration = yield* BetterStack.Cloud.PostgresSnapshot("before-migration", { postgresId: db.id, name: "db-before-migration", metadata: { reason: "migration" },});Looking up a snapshot
Section titled “Looking up a snapshot”By name under an instance
const existing = BetterStack.Cloud.PostgresSnapshot.lookup({ postgresId: "42", name: "db-before-migration",});postgresId string required
The ID of the PostgreSQL instance to create a snapshot of.
availabilityZone string
Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.
metadata Record<string, string>
Your own tags, as string keys and values. Can't be changed after the snapshot is created: a change replaces the snapshot.
name string
The snapshot's name. Defaults to the instance name followed by the date, such as db-2026-11-24. Can't end in -replica-seed- and four hex characters.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
id string always set
The snapshot's ID, a UUID.
postgresId string always set
The ID of the [Postgres](/reference/cloud/postgres/) instance the snapshot was taken from.
createdAt string
When the snapshot was taken. In ISO 8601 format, such as 2026-07-01T12:00:00Z.
failureReason string | null
Why creating the snapshot failed, or null unless the snapshot failed.
lock PostgresSnapshotLock | null
Our lock on the snapshot, or null unless we've locked it. Every action on a PostgreSQL snapshot works while the snapshot is locked.
metadata unknown
Your own tags as string pairs.
name string
The snapshot's name.
serverId string | null
The ID of the server that ran the instance's primary when the snapshot was taken. Becomes null some time after that server is deleted.
sizeBytes number | null
The size of the disk when the snapshot was taken, in bytes. We bill by this size. size_bytes is null until the snapshot is taken.
snapshotType "manual" | "scheduled"
Whether the snapshot was taken on request or by a schedule. Possible values: manual, scheduled.
status string
The snapshot's status. After you create a snapshot, get it until its status is available. Only an available snapshot can be restored.<br/>Valid values:<br/>pending: We're creating the snapshot.<br/>available: The snapshot is ready, and you can restore it.<br/>failed: Creating the snapshot failed. failure_reason says why.<br/>deleting: We're deleting the snapshot.
updatedAt string
When the snapshot was last updated. In ISO 8601 format, such as 2026-07-01T12:00:00Z.
Lookup
Section titled “Lookup”PostgresSnapshot.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
availabilityZone string
Zone, such as us-west-2a. Defaults to the credentials' zone.
postgresId string
The instance's ID (not needed to find it: snapshots are addressed by id). Only snapshots of this instance.