Created
November 8, 2013 08:46
-
-
Save onjin/7368162 to your computer and use it in GitHub Desktop.
grant select permission for given database (tables) to given database user
This file contains 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 | |
# | |
# Grant SELECT on database to given username | |
# ./grant_ro_pgsql_access.sh dbname dbuser | |
# | |
function usage { | |
echo "Usage: $0 dbname dbuser" | |
} | |
DB=$1 | |
USER=$2 | |
if [ -z "$DB" -o -z "$USER" ]; then | |
usage | |
exit 0; | |
fi | |
psql -U postgres -qAt -c "select 'grant select on ' || tablename || ' to \"${USER}\";' from pg_tables where schemaname = 'public'" ${DB} | psql -U postgres ${DB} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment