Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. -- Create a group with read-only access
  2. CREATE ROLE readonly;
  3.  
  4. -- Grant access on public sheme to existing tables
  5. GRANT USAGE ON SCHEMA public TO readonly;
  6. ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly; -- grant access to future tables
  7.  
  8. -- Grant access to specific database, repeat code below for each database
  9. GRANT CONNECT ON DATABASE db_name to readonly;
  10. ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO readonly; -- grant access to future tables
  11. GRANT USAGE ON SCHEMA public to readonly;
  12. GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly;
  13. GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
  14.  
  15. -- Create a user with password
  16. CREATE USER ro_user WITH ENCRYPTED PASSWORD 'ro_password';
  17. GRANT readaccess TO ro_user;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement