---
title: How to Modify User Privileges in PostgreSQL Databases
description: Modify user privileges in PostgreSQL managed database clusters, like creating a read-only user.
product: Databases
url: https://docs.digitalocean.com/products/databases/postgresql/how-to/modify-user-privileges/
last_updated: "2026-10-26"
---

> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document).

# How to Modify User Privileges in PostgreSQL Databases

PostgreSQL is an open source, object-relational database built for extensibility, data integrity, and speed. Its concurrency support makes it fully ACID-compliant, and it supports dynamic loading and catalog-driven operations to let users customize its data types, functions, and more.

By default, PostgreSQL database clusters include a user, `doadmin`, with full access to every database you create. Instead of using `doadmin` to access the database, we recommend creating additional users with only the minimum required privileges, following the [principle of least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege).

Every database cluster is publicly accessible by default. To limit access, you can [add trusted sources](https://docs.digitalocean.com/products/databases/postgresql/how-to/secure/index.html.md#firewalls) or manage user permissions by following this guide.

You can [create a new user in the Control Panel](https://docs.digitalocean.com/products/databases/postgresql/how-to/manage-users-and-databases/index.html.md), but setting a user’s privileges currently requires a command-line PostgreSQL client such as [`psql`](https://www.postgresql.org/docs/current/app-psql.html).

## Modify PostgreSQL User Permissions

First, retrieve your cluster’s [connection details](https://docs.digitalocean.com/products/databases/postgresql/how-to/connect/index.html.md#connection-details) using the Control Panel, API, or CLI. Then, connect to your cluster as the admin user, `doadmin`, by passing the connection URI to `psql`.

The URI sets the client `sslmode` parameter to `require`, which encrypts traffic in transit but does not verify the server identity.

```shell
psql "postgresql://doadmin:<your-password>@<your-cluster-hostname>:<your-cluster-port>/defaultdb?sslmode=require"
```

On PostgreSQL Standard Edition clusters, you can use `sslmode=verify-full` to [increase TLS verification with `sslmode`](https://docs.digitalocean.com/products/databases/postgresql/how-to/secure/index.html.md#ssl-modes) by also verifying the server identity. To use `sslmode=verify-full`, set `sslrootcert` to the path of your [downloaded CA certificate](https://docs.digitalocean.com/products/databases/postgresql/how-to/connect/index.html.md#download-the-ssl-certificate).

```shell
psql "postgresql://doadmin:<your-password>@<your-cluster-hostname>:<your-cluster-port>/defaultdb?sslmode=verify-full&sslrootcert=<path-to-ca-certificate>"
```

On PostgreSQL Advanced Edition clusters, you can use `sslmode=verify-full` to increase TLS verification. Advanced Edition clusters verify the server certificate against your system’s trust store. `libpq`-based clients such as `psql` also require `sslrootcert=system` in the connection URI and need `libpq` 16 or later:

```shell
psql "postgresql://doadmin:<your-password>@<your-cluster-hostname>:<your-cluster-port>/defaultdb?sslmode=verify-full&sslrootcert=system"
```

This brings you into the interactive shell for PostgreSQL, which changes your command prompt to `defaultdb=>`.

Next, connect to the database where you want to modify the user’s privileges.

```psql
defaultdb=> \connect example_database
```

Connecting to the database changes the command prompt to the database’s name and displays output like this:

```text
Output
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
You are now connected to database "example_database" as user "doadmin".
```

The commands you need to execute depend on the permissions you want the user to have. See [PostgreSQL privileges documentation](https://www.postgresql.org/docs/current/ddl-priv.html) for available grant and revoke options.

The following examples use a user named `example-user`. In SQL statements, enclose user names that contain hyphens or periods in double quotes. On Advanced Edition clusters, user names can contain only lowercase letters, numbers, hyphens, and periods.

As an example, to make a read-only user, first revoke any database-level privileges the user has on the target database, then grant `CONNECT` access and `USAGE` on the `public` schema. Add `SELECT` privileges on existing tables and set default `SELECT` privileges for tables created in the future.

```sql
REVOKE ALL ON DATABASE example_database FROM "example-user";
GRANT CONNECT ON DATABASE example_database TO "example-user";
GRANT USAGE ON SCHEMA public TO "example-user";
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "example-user";
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO "example-user";
```

The final command sets default privileges for tables that `doadmin` creates after you run it. To set defaults for tables created by another role, add `FOR ROLE other_role` to the `ALTER DEFAULT PRIVILEGES` command.

Run these commands on each database where you want to grant these privileges.

On PostgreSQL Advanced Edition clusters, new users also have the `CREATEDB` role attribute, which lets them create databases on the cluster. `GRANT` and `REVOKE` don’t change role attributes, so a user configured with the commands above can still run `CREATE DATABASE`. To remove the attribute, run the following command:

```sql
ALTER ROLE "example-user" NOCREATEDB;
```

Role attributes apply to the whole cluster, so you only need to run this command once.

You can also modify these commands to give the user different permissions. For example, to allow read and write access, add `GRANT INSERT ON ALL TABLES IN SCHEMA public TO "example-user";` and `ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT INSERT ON TABLES TO "example-user";` while keeping the existing `SELECT` grants.

## Configure a PMM Monitoring User

[Percona Monitoring and Management (PMM)](https://docs.percona.com/percona-monitoring-and-management/3/index.html) collects PostgreSQL metrics and Query Analytics (QAN) data from a dedicated database user. Managed PostgreSQL does not allow superuser access (see [PostgreSQL Limits](https://docs.digitalocean.com/products/databases/postgresql/details/limits/index.html.md)), but you can configure PMM without superuser privileges by granting [predefined PostgreSQL roles](https://www.postgresql.org/docs/current/predefined-roles.html) to a monitoring user.

This section describes the DigitalOcean-specific grants the monitoring user needs after creation on Managed PostgreSQL Standard Edition. For deploying the PMM 1-Click App and creating the user with the PMM Integration helper, see [How to Monitor Managed PostgreSQL with PMM 1-Click App](https://docs.digitalocean.com/products/databases/postgresql/how-to/monitor-with-pmm/index.html.md). The helper does not support [PostgreSQL Advanced Edition](https://docs.digitalocean.com/products/databases/postgresql/concepts/advanced-edition/index.html.md). For PMM product features and the PMM UI, see the [PMM documentation](https://docs.percona.com/percona-monitoring-and-management/3/index.html).

**Warning**:

  Third-party tools can change. Confirm compatibility with your PostgreSQL version and PMM release before production use.

### Prerequisites

Before you grant monitoring privileges, confirm the following:

- You deployed a PMM server and can add PostgreSQL instances from PMM (see the [PMM documentation](https://docs.percona.com/percona-monitoring-and-management/3/index.html) or [How to Monitor Managed PostgreSQL with PMM 1-Click App](https://docs.digitalocean.com/products/databases/postgresql/how-to/monitor-with-pmm/index.html.md)).
- You can [connect to the cluster](https://docs.digitalocean.com/products/databases/postgresql/how-to/connect/index.html.md) as `doadmin` using [`psql`](https://www.postgresql.org/docs/current/app-psql.html).
- You [added the PMM server as a trusted source](https://docs.digitalocean.com/products/databases/postgresql/how-to/secure/index.html.md#firewalls) on the database cluster so PMM can reach the database.

### Create the Monitoring User

Create a database user named `pmm_monitor` (or another name you choose) using the [Control Panel](https://cloud.digitalocean.com/databases?utm_source=docs-agent&utm_medium=md), `doctl`, or the API. See [Manage PostgreSQL Users and Databases](https://docs.digitalocean.com/products/databases/postgresql/how-to/manage-users-and-databases/index.html.md) for Control Panel steps and [Manage Database Users Using Automation](https://docs.digitalocean.com/products/databases/postgresql/how-to/manage-users-and-databases/index.html.md#manage-database-users-using-automation) for `doctl` and API examples.

The [PMM Integration helper](https://docs.digitalocean.com/products/databases/postgresql/how-to/monitor-with-pmm/index.html.md) can also create `pmm_monitor`. After the user exists, connect as `doadmin` and grant the privileges in the next section to enable Query Analytics.

### Grant Monitoring Privileges

[Connect to your database cluster](https://docs.digitalocean.com/products/databases/postgresql/how-to/connect/index.html.md) as `doadmin`, then connect to each database you want PMM to monitor for QAN:

```sql
\connect example_database
```

Run the following in each target database:

```sql
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
GRANT SELECT ON pg_stat_statements TO pmm_monitor;
```

Grant the predefined `pg_read_all_stats` role once while connected as `doadmin`. This role membership applies cluster-wide and provides read access to `pg_stat_*` views, `pg_stat_activity`, `pg_stat_replication`, and other statistics views without superuser access:

```sql
GRANT pg_read_all_stats TO pmm_monitor;
```

The [PMM documentation](https://docs.percona.com/percona-monitoring-and-management/3/index.html) also describes the `pg_monitor` predefined role for non-superuser monitoring. On Managed PostgreSQL, grant `pg_read_all_stats` instead. That role provides read access to the `pg_stat_*` views PMM needs without superuser privileges.

Repeat the extension and `GRANT SELECT ON pg_stat_statements` steps on every database where you want QAN. You only need to run `GRANT pg_read_all_stats` once.

After you configure the user, add the PostgreSQL instance in PMM using the monitoring user’s credentials, either with [the PMM Integration helper](https://docs.digitalocean.com/products/databases/postgresql/how-to/monitor-with-pmm/index.html.md) or in the PMM UI. See the [PMM documentation](https://docs.percona.com/percona-monitoring-and-management/3/index.html).

**Note**:

  Managed PostgreSQL does not allow superuser privileges or installing agents such as `node_exporter` on database hosts. PMM Node Summary (host-level CPU, RAM, and disk metrics) remains empty. Database metrics and QAN work with the privileges above.

## Check PostgreSQL User Privileges

After you [connect to your database cluster](https://docs.digitalocean.com/products/databases/postgresql/how-to/connect/index.html.md), you can use the `\du` command to list users that currently exist and see their role attributes. This command shows roles, not table-level grants.

```psql
\du
```

```text
Output
                                       List of roles
 Role name     |                         Attributes                         | Member of
---------------+------------------------------------------------------------+-----------
 \_dodb        | Superuser, Replication                                     | {}
 doadmin       | Create role, Create DB, Replication, Bypass RLS            | {}
 postgres      | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 example-user  |                                                            | {}
```

This output is from a PostgreSQL Standard Edition cluster. On Advanced Edition clusters, the list includes different system roles, and new users such as `example-user` show the `Create DB` attribute unless you [remove it](#modify-postgresql-user-permissions).

You can verify that a privilege change completed successfully by querying the database privileges table for the user:

```sql
SELECT table_catalog, table_schema, table_name, privilege_type FROM information_schema.table_privileges WHERE grantee = 'example-user';
```

The output displays the new privileges. For example, if you granted only `SELECT` privileges, the output looks like this:

```text
Output
 table_catalog    | table_schema | table_name | privilege_type
------------------+--------------+------------+----------------
 example_database | public       | account    | SELECT
```

You can also verify that the user’s permissions changed by logging in to the database cluster as the new user, then connecting to the database and testing commands. For example, if you try to `INSERT` into a database as a read-only user, you receive an error like `ERROR: permission denied for table account`.