DEV Community

Sandip Basnet
Sandip Basnet

Posted on

Create user with read only permission in PostgreSQL

Steps:

  1. create role:

    CREATE ROLE readaccess;

  2. grant access to existing tables:

GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;

  1. grant access to future tables:

    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;

  2. Create user with password:

    CREATE USER grafana WITH PASSWORD 'secretpass@dev';

  3. grant access to user: GRANT readaccess TO grafana;

Top comments (0)