Created
September 3, 2014 21:42
-
-
Save oztalha/0300f8a4f6f64f22c4ee to your computer and use it in GitHub Desktop.
Grant SELECT access to a user for all tables in a PostgreSql DB
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/bash | |
echo '---------------------------------------------------------------' | |
echo 'Grant SELECT access to a user for all tables in a PostgreSql DB' | |
echo '[USAGE]: ./scriptname username dbname' | |
echo '---------------------------------------------------------------' | |
for table in `echo "SELECT schemaname || '.' || relname FROM pg_stat_all_tables;" | psql $2 | grep -v "pg_" | grep "^ " | grep -v "\?column\?"`; | |
do | |
echo "GRANT SELECT ON TABLE $table TO $1;" | |
echo "GRANT SELECT ON TABLE $table TO $1;" | psql $2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment