Created
June 16, 2025 20:24
-
-
Save diodonfrost/c2dacb15a147edf65aa00e762df8d184 to your computer and use it in GitHub Desktop.
Create simple user with permissions on PostgreSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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