daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 151 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top