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.
Create simple user with permissions on PostgreSQL
-- 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment