Cloud.PostgresDatabase
A database inside a managed Postgres instance. Free: the instance
is what bills.
It can’t be changed: a new name or postgresId replaces it (the old
database, and its data, is dropped). The API has no read endpoint for one
database, so it is read by listing the instance’s databases; deleting the
instance removes its databases with it.
Grant a PostgresUser access to it through its privileges.
Ownership. The API keeps no metadata for it and it has no generated name,
so nothing marks it as this stack’s: list enumerates it under every parent, and a
create interrupted before its state was saved is not recognised by the next deploy
(which creates it again, or gets the API’s conflict when its identity is unique).
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.
Creating a database
Section titled “Creating a database”A second database with a user that can write to it
const pg = yield* BetterStack.Cloud.Postgres("db", { type: "PG1" });const reports = yield* BetterStack.Cloud.PostgresDatabase("reports", { postgresId: pg.id, name: "reports",});// Keyed by the database's output, so the user is created after it exists.yield* BetterStack.Cloud.PostgresUser("reporter", { postgresId: pg.id, username: "reporter", privileges: Output.map(reports.name, (database) => ({ [database]: "read_write" })),});Looking up an existing database
Section titled “Looking up an existing database”Reference a database by id
const existing = BetterStack.Cloud.PostgresDatabase.lookup({ postgresId: "42", id: "7" });name string required
The database name, up to 63 lowercase letters, digits and underscores, starting with a letter or underscore. Can't be postgres, template0 or template1.
postgresId string required
The ID of the parent this postgres belongs to.
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.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
id string always set
The database's ID.
name string always set
The database name (always known: the API returns the one it was created with).
postgresId string always set
The ID of the [Postgres](/reference/cloud/postgres/) instance it lives in.
createdAt string
When the database was created.
Lookup
Section titled “Lookup”PostgresDatabase.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
id string required
The database's ID.
postgresId string required
The ID of the [Postgres](/reference/cloud/postgres/) instance.
availabilityZone string
Zone the instance lives in. Defaults to the credentials' zone.