Skip to content

Instantly share code, notes, and snippets.

@joepreludian
Created July 12, 2015 17:52
Show Gist options
  • Select an option

  • Save joepreludian/83782cf38f33c591bc12 to your computer and use it in GitHub Desktop.

Select an option

Save joepreludian/83782cf38f33c591bc12 to your computer and use it in GitHub Desktop.
Granting schema to SQL
CREATE USER readonly WITH ENCRYPTED PASSWORD 'readonly';
GRANT USAGE ON SCHEMA public to readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly;
-- repeat code below for each database:
GRANT CONNECT ON DATABASE foo to readonly;
\c foo
GRANT USAGE ON SCHEMA public to readonly;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
@joepreludian
Copy link
Author

Simple Postgres creating roles with readonly perms;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment