Skip to content

Instantly share code, notes, and snippets.

@surendra0507
Last active November 12, 2021 13:39
Show Gist options
  • Save surendra0507/3011278db996d8d8f13446a47bc7c029 to your computer and use it in GitHub Desktop.
Save surendra0507/3011278db996d8d8f13446a47bc7c029 to your computer and use it in GitHub Desktop.

Revisions

  1. Surendra revised this gist Nov 12, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion read-access-pg-user.sql
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,4 @@ ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO cents_rd_gro

    -- Create a final user with password
    CREATE USER cents_rd WITH PASSWORD 'bhoom';
    GRANT cents_rd_group TO postgres_ro;
    GRANT cents_rd_group TO cents_rd;
  2. Surendra created this gist Nov 12, 2021.
    18 changes: 18 additions & 0 deletions read-access-pg-user.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    --
    -- Read only
    --

    -- Create a group
    CREATE ROLE cents_rd_group;

    -- Grant access to existing tables
    GRANT USAGE ON SCHEMA public TO cents_rd_group;
    GRANT SELECT ON ALL TABLES IN SCHEMA public TO cents_rd_group;
    GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO cents_rd_group;

    -- Grant access to future tables on select
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO cents_rd_group;

    -- Create a final user with password
    CREATE USER cents_rd WITH PASSWORD 'bhoom';
    GRANT cents_rd_group TO postgres_ro;