Skip to content

Instantly share code, notes, and snippets.

@fxkraus
Created July 4, 2017 15:35
Show Gist options
  • Select an option

  • Save fxkraus/a8a59e31b57c98aa264be74f915df6d1 to your computer and use it in GitHub Desktop.

Select an option

Save fxkraus/a8a59e31b57c98aa264be74f915df6d1 to your computer and use it in GitHub Desktop.

Revisions

  1. fxkraus created this gist Jul 4, 2017.
    9 changes: 9 additions & 0 deletions postgresql_create_ro_user.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    CREATE USER username WITH PASSWORD 'the_password';
    GRANT CONNECT ON DATABASE the_database TO username;
    GRANT USAGE ON SCHEMA public TO username;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO username;

    -- has to be executed while connected to the actual database
    \c the_database
    GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO the_database;
    GRANT SELECT ON ALL TABLES IN SCHEMA public to the_database;