Last active
August 29, 2015 13:57
-
-
Save charlespeach/9539235 to your computer and use it in GitHub Desktop.
Grant select access to a user for all tables in a postgres database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
tables=$(psql database_name -A -t -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';") | |
for table in $tables | |
do | |
echo "Granting select to username on $table" | |
psql database_name -c "GRANT SELECT ON $table to username;" | |
done |
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO role;
is needed aswel. Will look at how to drop this down to SELECT only
Check this out: http://wiki.postgresql.org/images/d/d1/Managing_rights_in_postgresql.pdf as an alternative approach.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did this because as far as I know, you cannot change the permissions for a user at the database level, only the table level.