Last active
March 25, 2018 21:20
-
-
Save codersofthedark/2093d100db7ccfe6c75797ec7459285c to your computer and use it in GitHub Desktop.
Create PSQL User and give read access to it to all tables in all schemas
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
CREATE USER "someuser" WITH PASSWORD 'somepassword'; | |
GRANT india_group TO "someuser"; | |
GRANT "prateekthakore" TO "sharad.sachdeva"; | |
GRANT CONNECT ON DATABASE somedatabase TO "someuser" | |
DO $do$ | |
DECLARE | |
theSchema text; | |
BEGIN | |
FOR theSchema IN SELECT DISTINCT table_schema FROM information_schema.tables | |
LOOP | |
EXECUTE format($$ GRANT USAGE ON SCHEMA %I TO "someUser" $$, theSchema); | |
EXECUTE format($$ GRANT SELECT ON ALL SEQUENCES IN SCHEMA %I TO "someUser" $$, theSchema); | |
EXECUTE format($$ GRANT SELECT ON ALL TABLES IN SCHEMA %I TO "someUser" $$, theSchema); | |
END LOOP; | |
END; | |
$do$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment