-
Create a new user in PostgreSQL
CREATE USER <username> WITH PASSWORD '<password>';
-
GRANT CONNECT access
GRANT CONNECT ON DATABASE <database_name> TO <username>;
-
GRANT USAGE on schema
GRANT USAGE ON SCHEMA <schema_name> TO <username>;
-
GRANT SELECT access using any of the options below
-
Grant SELECT for a specific table:
GRANT SELECT ON <table_name> TO <username>;
-
Grant SELECT for multiple tables
GRANT SELECT ON ALL TABLES IN SCHEMA <schema_name> TO <username>;
-
To grant access to the new tables in the future automatically, the default needs to be altered
ALTER DEFAULT PRIVILEGES IN SCHEMA <schema_name> GRANT SELECT ON TABLES TO <username>;
-
Created
September 27, 2023 14:49
-
-
Save barbietunnie/eb7df40be7eb5d96f906a915854d0733 to your computer and use it in GitHub Desktop.
How to create a read-only PostgreSQL user
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment