Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save diodonfrost/c2dacb15a147edf65aa00e762df8d184 to your computer and use it in GitHub Desktop.

Select an option

Save diodonfrost/c2dacb15a147edf65aa00e762df8d184 to your computer and use it in GitHub Desktop.

Revisions

  1. diodonfrost created this gist Jun 16, 2025.
    14 changes: 14 additions & 0 deletions postgresql-create-user-with-permissions.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    -- 1. Create the user role
    CREATE USER app_user PASSWORD 'secure_password';

    -- 2. Give them access to the database
    GRANT CONNECT ON DATABASE ma_base TO app_user;

    -- 3. Give them access to the schema
    GRANT USAGE ON SCHEMA public TO app_user;

    -- 4. Give them privileges on the tables
    GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO app_user;

    -- 5. For future tables
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO app_user;