Skip to content

Instantly share code, notes, and snippets.

@charlespeach
Last active August 29, 2015 13:57
Show Gist options
  • Save charlespeach/9539235 to your computer and use it in GitHub Desktop.
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
#!/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
@charlespeach
Copy link
Author

GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO role; is needed aswel. Will look at how to drop this down to SELECT only

@dznz
Copy link

dznz commented Aug 15, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment