---
title: "Manage Users and Databases"
description: "Create, inspect, rotate and delete users and databases of a Managed PostgreSQL service with the exo CLI, and see where SQL takes over."
url: https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/manage-users-and-databases/
product: "PostgreSQL"
section: product
last_updated: 2026-11-10
---
> For AI agents: the documentation index is at https://community.exoscale.com/llms.txt. Every page is available as markdown at `<page URL>index.md` or with `Accept: text/markdown`.

# Manage Users and Databases

Create, inspect, rotate and delete the users and databases of a Managed PostgreSQL service with the `exo` CLI, and see how they relate to the roles you create in SQL.

## Users and Roles

Every user of the service is a PostgreSQL role. The platform keeps a list of these roles and, for
some of them, their password:

- A user created with `exo dbaas user create` is a role with `LOGIN` and a password generated and
  stored by the platform. You can read the password back and rotate it without connecting to the
  database.
- A role created in SQL with `CREATE ROLE` or `CREATE USER` also appears in
  `exo dbaas user list` and `exo dbaas show`, as a `normal` user, including `NOLOGIN` group
  roles. The platform holds no password for it until you run
  `exo dbaas user reset-credentials` on it.

Use platform-managed passwords for the identities your applications log in with, and SQL group
roles, such as `readonly` or `app_readwrite`, to bundle privileges.

## The avnadmin User

Every service has `avnadmin`, its primary user. `avnadmin` is not a superuser. It has
`CREATEDB`, `CREATEROLE`, `REPLICATION` and `BYPASSRLS`, and it is a member, through the
platform role `avnadmin_group`, of `pg_signal_backend`, `pg_read_all_stats`,
`pg_stat_scan_tables`, `pg_create_subscription` and, on PostgreSQL 18,
`pg_signal_autovacuum_worker`. It is not a member of `pg_monitor`, `pg_read_all_settings` or
`pg_read_all_data`.

Check the attributes of the role you are connected as:

```sql
SELECT rolname, rolsuper, rolcreatedb, rolcreaterole, rolreplication, rolbypassrls
  FROM pg_roles
 WHERE rolname = current_user;
```

List the roles it is a member of, directly or through other roles:

```sql
SELECT rolname AS granted_role
  FROM pg_roles
 WHERE pg_has_role(current_user, oid, 'MEMBER')
   AND rolname <> current_user
 ORDER BY 1;
```

On a new PostgreSQL 18 service this returns nine roles. The list grows as you add users:
`avnadmin` holds `ADMIN OPTION` on every user created with `exo dbaas user create`, so it can
grant those roles and change their attributes and passwords. It is also a member of every role it
creates in SQL, with the privileges of that role, because `createrole_self_grant` is set to
`inherit,set` on the service.

`avnadmin` is the user of the connection URI that the platform generates. Do not delete it.
Because it is a member of `pg_signal_backend`, `pg_cancel_backend()` and
`pg_terminate_backend()` work for the sessions of non-superuser roles.

## Create a User

```bash
exo dbaas user create SERVICE_NAME USERNAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service, for example `my-postgresql`.
- `USERNAME`: name of the user, 1 to 64 characters.
- `ZONE`: zone the service runs in, for example `ch-gva-2`.

The user gets `LOGIN` and a generated password, and no other attribute or role membership.

To create a user with the `REPLICATION` attribute, for example for logical replication, add
`--pg-allow-replication`:

```bash
exo dbaas user create SERVICE_NAME USERNAME -z ZONE --pg-allow-replication
```

The CLI accepts this flag only at creation. To change it on an existing user, use the API:

```bash
echo '{"allow-replication":true}' | \
  exo api update-dbaas-postgres-allow-replication SERVICE_NAME USERNAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `USERNAME`: name of an existing user.
- `ZONE`: zone the service runs in.

Send `false` to remove the attribute.

## Reveal and Reset Credentials

Read the stored password of a user:

```bash
exo dbaas user reveal-secrets SERVICE_NAME USERNAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `USERNAME`: name of the user.
- `ZONE`: zone the service runs in.

Rotate the password. Without `--password`, a new one is generated:

```bash
exo dbaas user reset-credentials SERVICE_NAME USERNAME -z ZONE
```

To choose the password, add `--password PASSWORD`, with 8 to 256 characters. The old password
stops working immediately: update the applications that use it.

> [!WARNING]
> Rotate the passwords of platform-managed users with `reset-credentials`, not with
> `ALTER ROLE ... PASSWORD` in SQL. After a password change in SQL, the platform no longer holds
> the password: `reveal-secrets` returns an empty password. Running `reset-credentials` again
> puts the password back under platform control.

## Read the Users and Databases

There is no API operation to list users or databases. Both are part of the service:

```bash
exo dbaas show SERVICE_NAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `ZONE`: zone the service runs in.

The `Users` row lists each user with its type, `primary` for `avnadmin` and `normal` for the
others, and the `Databases` row lists the databases. `exo dbaas user list` prints the same users,
and `exo dbaas user show SERVICE_NAME USERNAME -z ZONE` adds whether replication is allowed.
`exo dbaas database` has no `list` command.

For scripts:

```bash
exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q 'databases'
exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q 'users[].[username,type,"allow-replication"]'
```

> [!CAUTION]
> The full output of `exo api get-dbaas-service-pg` contains the password of every
> platform-managed user. Project only the fields you need, as above, or treat the output as a
> secret.

A role created in SQL can take a few seconds to appear in the list.

## Create a Database

```bash
exo dbaas database create SERVICE_NAME DATABASE_NAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `DATABASE_NAME`: name of the database, 1 to 40 characters.
- `ZONE`: zone the service runs in.

The database is owned by `avnadmin`, encoded in `UTF8`, with the `en_US.UTF-8` collation and
character classification, like `defaultdb`. To choose the collation, add `--pg-lc-collate`, for
example `--pg-lc-collate de_CH.UTF-8`. Check the result with:

```sql
SELECT datname, pg_get_userbyid(datdba) AS owner, datcollate, datctype
  FROM pg_database
 ORDER BY 1;
```

The `_aiven` database is used by the platform. Do not connect to it or change it.

## Delete a Database

```bash
exo dbaas database delete SERVICE_NAME DATABASE_NAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `DATABASE_NAME`: name of the database to delete.
- `ZONE`: zone the service runs in.

Add `-f` to skip the confirmation, for example in a script.

> [!CAUTION]
> Deleting a database deletes its data. To recover it, restore a backup or a point in time into a
> new service. See [Backups and Restore](https://community.exoscale.com/product/dbaas/how-to/backups-restore/index.md).

## Delete a User

```bash
exo dbaas user delete SERVICE_NAME USERNAME -z ZONE
```

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service.
- `USERNAME`: name of the user to delete.
- `ZONE`: zone the service runs in.

Add `-f` to skip the confirmation. The command also works for roles created in SQL.

The objects the user owns, in every database, are reassigned to `avnadmin`, and the privileges
granted to the user are removed. If an application must keep owning those objects, reassign them
first, in each database:

```sql
REASSIGN OWNED BY USERNAME TO NEW_OWNER;
```

Parameters:

- `USERNAME`: the user you are about to delete.
- `NEW_OWNER`: the role that takes over its objects.

## Bundle Privileges in Group Roles

Create `NOLOGIN` group roles in SQL, grant privileges to them, and grant the group roles to the
users. Adding an application then takes one `GRANT`. Run the following as `avnadmin`, connected
to the database concerned:

```sql
CREATE ROLE app_readwrite NOLOGIN;

GRANT CONNECT ON DATABASE defaultdb TO app_readwrite;
GRANT USAGE ON SCHEMA public TO app_readwrite;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO app_readwrite;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO app_readwrite;

ALTER DEFAULT PRIVILEGES FOR ROLE avnadmin IN SCHEMA public
  GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO app_readwrite;
ALTER DEFAULT PRIVILEGES FOR ROLE avnadmin IN SCHEMA public
  GRANT USAGE ON SEQUENCES TO app_readwrite;

GRANT app_readwrite TO myapp;
```

Replace `myapp` with the user of your application. The read-only equivalent, and how default
privileges depend on the role that creates the tables, are covered in
[Create Read-Only Users](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/create-read-only-users/index.md).

## Related Pages

- [Create Read-Only Users](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/create-read-only-users/index.md)
- [Claim Public Schema Ownership](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/claim-public-schema-ownership/index.md)
- [Upgrade Password Encryption to scram-sha-256](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/upgrade-password-encryption/index.md)
- [Backups and Restore](https://community.exoscale.com/product/dbaas/how-to/backups-restore/index.md)
- [Manage DBaaS with Terraform](https://community.exoscale.com/product/dbaas/how-to/terraform/index.md)

