Mark Huth has uploaded a new change for review. Change subject: ensure restored engine db objects are owned by engine user ......................................................................
ensure restored engine db objects are owned by engine user When restoring a DB from a 3.1 system that upgraded from 3.0, onto another 3.1 system that wasn't upgraded from 3.0, then you encounter permission denied messages from postgresql because the engine DB objects are owned by the postgres user instead of the engine user. This patch checks to see if the engine DB objects are owned by the engine user and if not, alters the ownership. Change-Id: I5f16f66066d9056c97a32f180c02d8bd248d1eac Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=923614 Signed-off-by: Mark Huth <[email protected]> --- M backend/manager/dbscripts/dbcustomfunctions.sh M backend/manager/dbscripts/restore.sh 2 files changed, 28 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/77/13377/1 diff --git a/backend/manager/dbscripts/dbcustomfunctions.sh b/backend/manager/dbscripts/dbcustomfunctions.sh index 181f162..3df73c4 100755 --- a/backend/manager/dbscripts/dbcustomfunctions.sh +++ b/backend/manager/dbscripts/dbcustomfunctions.sh @@ -15,6 +15,7 @@ USERNAME="" VERBOSE=false LOGFILE="$ME.log" + DBOBJECT_OWNER="engine" LC_ALL="C" export LC_ALL @@ -36,3 +37,25 @@ execute_file "create_dwh_views.sql" ${DATABASE} ${SERVERNAME} ${PORT} > /dev/null } +verify_dbobject_ownership() { + cmd="select c.relname \ + from pg_class c join pg_roles r on r.oid = c.relowner join pg_namespace n on n.oid = c.relnamespace \ + where c.relkind in ('r','v','S') \ + and n.nspname = 'public' and r.rolname != '${DBOBJECT_OWNER}';" + res=$(execute_command "${cmd}" engine ${SERVERNAME} ${PORT}) + if [ -n "${res}" ]; then + cmd="" + echo "Changing ownership of objects in database '$DATABASE' to owner '$DBOBJECT_OWNER' started..." + for tab in $(echo $res); do + cmd=${cmd}"alter table $tab owner to ${DBOBJECT_OWNER}; " + done + echo $cmd | psql -h $SERVERNAME -p $PORT -U $USERNAME -d $DATABASE --set ON_ERROR_STOP=1 + echo -n "Changing ownership of objects in database '$DATABASE' to owner '$DBOBJECT_OWNER' " + if [ $? -eq 0 ]; then + echo "completed." + else + echo "failed." + return 1 + fi + fi +} diff --git a/backend/manager/dbscripts/restore.sh b/backend/manager/dbscripts/restore.sh index aa6532d..de034d8 100755 --- a/backend/manager/dbscripts/restore.sh +++ b/backend/manager/dbscripts/restore.sh @@ -77,8 +77,12 @@ ./upgrade.sh -s ${SERVERNAME} -p ${PORT} -d ${DATABASE} -u ${USERNAME} -c fi popd>/dev/null - exit 0 else usage exit 1 fi + +verify_dbobject_ownership +if [ $? -ne 0 ]; then + exit 1 +fi -- To view, visit http://gerrit.ovirt.org/13377 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5f16f66066d9056c97a32f180c02d8bd248d1eac Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Mark Huth <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
