Guest User

Untitled

a guest
Jan 22nd, 2015
24
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- create your read-only user
  2. CREATE USER readonly WITH PASSWORD 'password';
  3.  
  4. -- grant usage on schemas
  5. SELECT 'GRANT USAGE ON SCHEMA ' || nspname || ' TO readonly;'
  6. FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema';
  7.  
  8. -- grant select on your tables
  9. SELECT 'GRANT SELECT ON ' || nsp.nspname || '.' || c.relname || ' TO readonly;'    
  10. FROM pg_class c JOIN pg_namespace nsp ON c.relnamespace = nsp.oid
  11. WHERE (c.relkind = 'r' OR c.relkind = 'v') AND nsp.nspname NOT LIKE 'pg_%' AND nsp.nspname != 'information_schema';
RAW Paste Data