DEV Community

Sandip Basnet
Sandip Basnet

Posted on

1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more