Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created June 6, 2013 19:30
Show Gist options
  • Save mark-cooper/5724228 to your computer and use it in GitHub Desktop.
Save mark-cooper/5724228 to your computer and use it in GitHub Desktop.
POSTGRES: Create read only user
# POSTGRES READ ONLY USER
database = 'evergreen'
username = 'eg_viewer'
password = '1a2b3c4d5e' # something good
schemas = [
'actor',
'asset',
'biblio',
'config',
# etc.
]
puts "-- POSTGRES READ ONLY USER"
puts
puts "BEGIN;"
puts
puts "CREATE USER #{username} WITH ENCRYPTED PASSWORD '#{password}';"
puts "GRANT CONNECT ON DATABASE #{database} TO #{username};"
puts
schemas.each do |schema|
puts "GRANT USAGE ON SCHEMA #{schema} to #{username};"
puts "GRANT SELECT ON ALL SEQUENCES IN SCHEMA #{schema} TO #{username};"
puts "GRANT SELECT ON ALL TABLES IN SCHEMA #{schema} TO #{username};"
puts
end
puts "COMMIT;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment