Skip to content

Matches page titles and page text. Forty pages, indexed at build time.

Databases and roles

Create and delete databases from the service page, each with its own connection strings. Roles are yours to create in SQL. Why one is a limit and the other a guideline.

A service holds multiple logical databases at no extra charge. We do not charge per database.

Databases and roles are created through different paths on purpose: databases through the platform, roles by you in SQL. The reason is in the words we are allowed to use about each.

Your service's databases

A new service is created with one logical database, appdb. It is what the connection examples throughout this documentation use.

Each database in a service has its own data. They share the service's compute, storage, backups and users: one PostgreSQL instance holds them all.

Create a database

On the service's page, open Configuration. The Databases section lists every database and how many your plan allows. Choose Create database and give it a name. It appears in the list when it is ready.

A name is lowercase letters, numbers and underscores, starting with a letter, up to 63 characters. It is narrower than PostgreSQL allows on purpose: the name appears in your connection strings, in our backup records and in log lines.

postgres, template0 and template1 are PostgreSQL's own. They are not listed, do not count against your plan, and cannot be created or deleted.

One database is created or deleted at a time on a service. A second request while one is under way is refused, and you can make it as soon as the first has finished.

Owners and admins can create databases, and so can developers on the service's project.

Through SQL, no

Your managed elevated role does not hold CREATEDB, so CREATE DATABASE is refused:

text
ERROR:  permission denied to create database

That is a deliberate design decision with one purpose: it makes the published database limit a real limit rather than a claim. Every database passes through the platform, which counts it. A limit that is documented and not enforced is a guideline that will be exceeded, discovered during an incident, and argued about.

Your plan's database count is on plan limits.

Connect to a database

Every database has its own direct and pooled connection strings. On the Connect tab, choose the database in the Database list, and every string and example on the tab is rewritten for it. The host names and the user are the same for every database in the service; only the database at the end of the string changes:

text
postgresql://app_writer:<password>@db-<id>.<location>.baltadb.net:5432/core?sslmode=verify-full

The pooled endpoint serves every database too, in transaction mode.

Delete a database

Owners and admins can delete a database. Choose Delete database beside it, type its name to confirm, and confirm with your password. The deletion is recorded in your organisation's audit log.

Deleting removes the database and all its data. Backups taken before the deletion still hold it until they expire. Until then it can be recovered by restoring a clone of the service to a point before the deletion. Restoring in place would also take every other database back to that point.

Two databases cannot be deleted here:

  • appdb, the database the service was created with. Our availability checks and restore verification connect to it. Deleting the service removes it.
  • The last remaining database. A service keeps at least one.

Backups and restores

Backups are of the whole PostgreSQL instance, so every database in the service is in every backup. A restore, in place or as a clone, brings back every database the service had at the point you restore to.

Through the API

GET, POST and DELETE on /services/:id/databases. A delete names the database, carries the typed name and a step-up confirmation, as the dashboard's does.

Create a role

Roles are yours. Your managed elevated role holds CREATEROLE, so you create and manage them with ordinary SQL:

sql
CREATE ROLE app_user LOGIN PASSWORD '<password>';
GRANT CONNECT ON DATABASE appdb TO app_user;

The role count is a guideline, not a limit. Because CREATEROLE is granted we cannot enforce a ceiling, and we are not going to print a number and call it enforced when it is not. Your CREATE ROLE will not silently fail.

The shape that works

One database per application. One role per component that connects, rather than one shared role:

RoleForTypical grants
app_userThe application's normal trafficCONNECT, USAGE on schema, DML on its tables
app_migratorSchema migrations, run from your deploy pipelineOwnership of the schema, DDL
app_readonlyReporting and analyticsCONNECT, USAGE, SELECT

Separate roles mean a leaked application credential cannot drop a table, and an audit of who did what has an answer.

The grants themselves, including the default-privileges step that people forget, are on privileges.

What you will see

sql
SELECT rolname, rolcanlogin, rolcreatedb, rolcreaterole, rolsuper
FROM pg_roles
WHERE rolname NOT LIKE 'pg\_%'
ORDER BY rolname;

Your managed elevated role reads rolcreaterole true and rolcreatedb and rolsuper false. Roles you create for your application should read false on all three.

What you do not get

You do not get superuser, and you do not get host access. See the privilege model for what the managed elevated role can and cannot do, and why each boundary is where it is.

Troubleshooting

permission denied to create database. Expected. CREATEDB is withheld so the database count is enforceable. Create the database from the service's Databases section instead.

database "core" does not exist from a connection string. The database is still being created, or has been deleted. The Databases section says which.

must have admin option on role when granting. CREATEROLE from PostgreSQL 16 onward lets a role administer only the roles it created. Grant from the role that created the target, or from the managed elevated role.

A role you created cannot see a table. It has CONNECT but not USAGE on the schema, or not the object privilege. Check both, then check default privileges: grants on existing tables do not cover tables created later.