Last active
April 3, 2023 13:56
-
-
Save rpromyshlennikov/6228d0dacea2fcbb5988057fa86388d6 to your computer and use it in GitHub Desktop.
Grant all on DB to new user
This file contains 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
GRANT CONNECT ON DATABASE "db-name" TO "user-name"; | |
\c "db-name"; -- REQUIRED!! | |
GRANT USAGE ON SCHEMA "schema-name" TO "user-name"; | |
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA "schema-name" TO "user-name"; | |
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA "schema-name" TO "user-name"; | |
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "schema-name" TO "user-name"; | |
GRANT ALL PRIVILEGES ON DATABASE "db-name" TO "user-name"; | |
REVOKE USAGE ON SCHEMA "schema-name" FROM "user-name"; | |
REVOKE SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA "schema-name" FROM "user-name"; | |
REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA "schema-name" FROM "user-name"; | |
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "schema-name" FROM "user-name"; | |
REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA "schema-name" FROM "user-name"; | |
REVOKE ALL PRIVILEGES ON DATABASE "postgres" FROM "user-name"; | |
REVOKE CONNECT ON DATABASE "db-name" FROM "user-name"; | |
DROP USER "user-name"; |
There is a simpler way for creating users/DBs if you don't need to set granular permission.
CREATE USER my_username WITH PASSWORD 'my_password';
ALTER ROLE my_username WITH SUPERUSER;
CREATE DATABASE database_name;
GRANT ALL PRIVILEGES ON DATABASE "database_name" to my_username;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initial setup: