Guest User

Untitled

a guest
Jan 23rd, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. -- Drop user
  2. DROP USER bob;
  3. -- Drop privileges
  4. DROP OWNED BY bob;
  5.  
  6.  
  7. -- Create a group
  8. CREATE ROLE readonly;
  9.  
  10. -- Create a final user with password
  11. CREATE USER bob WITH ENCRYPTED PASSWORD 'secret';
  12. GRANT readonly TO bob;
  13.  
  14. -- Grant access to existing tables
  15. GRANT USAGE ON SCHEMA public TO readonly;
  16. ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly;
  17.  
  18. -- repeat code below for each database:
  19. GRANT CONNECT ON DATABASE db_name to readonly;
  20. \c db_name
  21.  
  22. --- this grants privileges on new tables generated in new database "db_name"
  23. ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO readonly;
  24.  
  25. GRANT USAGE ON SCHEMA public to readonly;
  26. GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly;
  27. GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
Add Comment
Please, Sign In to add comment