Commit ce2cf896 authored by Michał 'rysiek' Woźniak's avatar Michał 'rysiek' Woźniak
Browse files

bugfixes -- psql expects a database to connect to, otherwise uses the role...

bugfixes -- psql expects a database to connect to, otherwise uses the role name as the database name, which doesn't always exist; postgres database usually does...
parent 3d3317c5
......@@ -314,8 +314,8 @@ function create_readonly_postgres_user() {
|| display_error_and_quit "Error creating the $RUSER_NAME role and granting SELECT on pg_authid."
# get the list of roles
ROLES="$( PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -Aqt -c '\dg' | grep '|' | cut -d '|' -f 1 )" \
|| display_error_and_quit "Error getting list of databases"
ROLES="$( PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -Aqt -c '\dg' postgres | grep '|' | cut -d '|' -f 1 )" \
|| display_error_and_quit "Error getting list of roles"
# and for each role
for ROLE in $ROLES; do
......@@ -323,13 +323,13 @@ function create_readonly_postgres_user() {
PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -c "
ALTER DEFAULT PRIVILEGES FOR ROLE $ROLE GRANT SELECT ON TABLES TO $RUSER_NAME;
ALTER DEFAULT PRIVILEGES FOR ROLE $ROLE GRANT SELECT ON SEQUENCES TO $RUSER_NAME;
ALTER DEFAULT PRIVILEGES FOR ROLE $ROLE GRANT EXECUTE ON FUNCTIONS TO $RUSER_NAME;" \
ALTER DEFAULT PRIVILEGES FOR ROLE $ROLE GRANT EXECUTE ON FUNCTIONS TO $RUSER_NAME;" postgres \
|| display_error_and_quit "Error altering default privileges for role $ROLE"
done
# get the list of databases
DATABASES="$( PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -lAqt | grep '|' | cut -d '|' -f 1 | egrep -v "template[0-9]" )" \
DATABASES="$( PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -lAqt postgres | grep '|' | cut -d '|' -f 1 | egrep -v "template[0-9]" )" \
|| display_error_and_quit "Error getting list of databases"
# do we have any databases?
......@@ -342,11 +342,11 @@ function create_readonly_postgres_user() {
for DATABASE in $DATABASES; do
# grant CONNECT
PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -c "GRANT CONNECT ON DATABASE $DATABASE TO $RUSER_NAME;" \
PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -c "GRANT CONNECT ON DATABASE $DATABASE TO $RUSER_NAME;" postgres \
|| display_error_and_quit "Error granting CONNECT on database $DATABASE"
# get all schemas
SCHEMAS="$( PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -Aqt -c '\dn' | grep '|' | cut -d '|' -f 1 )" \
SCHEMAS="$( PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -U "$PG_USER" -Aqt -c '\dn' postgres | grep '|' | cut -d '|' -f 1 )" \
|| display_error_and_quit "Error getting list of schemas"
# let's go through the schemas, then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment