by
1,287 15

Add read only user to PG 9 on DB, cookbook snippet.

Add read only user to PG 9 on DB, cookbook snippet.: 
add_read_only_pg_user.rb
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/2581568/Add-read-only-user-to-PG-9-on-DB--cookbo?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
# Create a user with Login sql = [%(CREATE ROLE <username> WITH PASSWORD '<password>' LOGIN)] # # Allow to connect sql << %(GRANT CONNECT ON DATABASE reports TO <username>) # # Allow to use schema sql << %(GRANT USAGE ON SCHEMA public TO <username>) # # grant on current objects sql << %(GRANT SELECT ON ALL TABLES IN SCHEMA public TO <username>) # # grant on future objects sql << %(ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO <username>) %x(psql reports postgres -c "#{sql.join(';')}")
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus