Skip to content

Instantly share code, notes, and snippets.

@blasterpal
Created August 28, 2013 12:57
Show Gist options
  • Select an option

  • Save blasterpal/6365745 to your computer and use it in GitHub Desktop.

Select an option

Save blasterpal/6365745 to your computer and use it in GitHub Desktop.
Add read only user to PG 9 on DB, cookbook snippet.
# Create a user with Login
sql = [%(CREATE ROLE jsmith WITH PASSWORD 'foobar' LOGIN)]
# # Allow to connect
sql << %(GRANT CONNECT ON DATABASE reports TO jsmith)
# # Allow to use schema
sql << %(GRANT USAGE ON SCHEMA public TO jsmith)
# # grant on current objects
sql << %(GRANT SELECT ON ALL TABLES IN SCHEMA public TO jsmith)
# # grant on future objects
sql << %(ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO jsmith)
%x(psql reports postgres -c "#{sql.join(';')}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment