Cloud.PostgresUser
A SQL user of a managed Postgres instance, with its access level
on each database. Free: the instance is what bills.
privileges changes in place; a new username or postgresId replaces
the user. The API has no read endpoint for one user, so it is read by
listing the instance’s users; deleting the instance removes its users
with it. The instance’s default admin user is managed by Better Stack
and is not a resource here.
Connecting: the attributes carry the user’s own password and URIs
(direct, pooled, and their public variants, as on Postgres), read
from the user’s credentials endpoint. A URI connects to database (the
API’s choice: defaultdb, else the first database); for another
database, use the parts (user, password with the instance’s host).
Secrets are Redacted.
Credentials: the deploy never resets the password on its own. Set
rotateCredentials to a new value to reset it once; a reset done in the
console or CLI is read on the next deploy, without a replace.
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 user
Section titled “Creating a user”A read-only user for reporting
const pg = yield* BetterStack.Cloud.Postgres("db", { type: "PG1", database: "app" });const reader = yield* BetterStack.Cloud.PostgresUser("reader", { postgresId: pg.id, username: "reader", privileges: { app: "read" },});// A Service's env: { DATABASE_URL: reader.pooledConnectionUri }const env = { PGHOST: pg.host, PGPORT: pg.port, PGUSER: reader.username, PGPASSWORD: reader.password, PGDATABASE: "app",};Looking up an existing user
Section titled “Looking up an existing user”Reference a user by id
const existing = BetterStack.Cloud.PostgresUser.lookup({ postgresId: "42", id: "7" });postgresId string required
The ID of the parent this postgres belongs to.
username string required
The user name in PostgreSQL. Accepts up to 63 lowercase letters, digits and underscores, starting with a letter or an underscore. Can't be changed after the user is created. Can't be postgres or pgbouncer or start with pg_.
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.
privileges Record<string, (string & {}) | "read" | "read_write" | "all" | "none">
The user's access to each database, mapping a database name to read, read_write, all or none, such as { app: "read_write" }. A database left out gets no access; each key must be a database of the instance. Changes in place (the whole map is replaced). Removing the prop keeps the current access; {} removes all of it.
rotateCredentials string
Rotate the credentials: every change of this value after create (for example a date, "2026-12") calls the API's rotate operation once on the next deploy, and the new secrets replace the old ones in the attributes (and so in every env that references them). Leaving it out, or keeping the same value, never rotates. A rotation done in the console or CLI is simply read on the next deploy.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
caCertificate string always set
The CA certificate (PEM) that signed the server's certificate.
connectionUri Redacted<string> always set
postgresql:// URI as this user, direct, from your private networks (sslmode=verify-full).
database string always set
The database the URIs connect to: defaultdb when the instance has it, else its first database.
id string always set
The user's ID.
password Redacted<string> always set
The user's password (credentials password).
pooledConnectionUri Redacted<string> always set
The same through PgBouncer.
postgresId string always set
The ID of the [Postgres](/reference/cloud/postgres/) instance it belongs to.
publicConnectionUri Redacted<string> always set
Direct, from the internet; undefined while the instance's publicAccess is off.
publicPooledConnectionUri Redacted<string> always set
Through PgBouncer, from the internet; undefined while publicAccess is off.
user string always set
The user name, as the credentials give it (the same as username).
createdAt string
When the user was created.
defaultUser boolean
Whether this is the instance's default admin user. We manage the default user's access, and the default user can't be deleted.
privileges PostgresUserPrivilegesMap
The user's access to each database, as an object that maps a database name to an access level, such as {"appdb": "read_write"}. A database that isn't in the object gets no access. read can read the tables in the public schema. read_write can also add, change and delete rows and run functions, but can't create tables. all can also create tables and schemas and maintain them, such as with VACUUM. none gives no access. Each key must be a database of this instance. Leave it out on create for no access to any database. An update replaces the whole object, and leaving it out removes all access.
username string
The user name in PostgreSQL. Accepts up to 63 lowercase letters, digits and underscores, starting with a letter or an underscore. Can't be changed after the user is created. Can't be postgres or pgbouncer or start with pg_.
Lookup
Section titled “Lookup”PostgresUser.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
id string required
The user'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.
See also
Section titled “See also”- Ownership. The API keeps no
metadatafor it and it has no generated name, so nothing marks it as this stack’s:listenumerates 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). - https://betterstack.com/docs/cloud/api/postgres-users/credentials-postgres-user/