Skip to content

Commit ae0bf59

Browse files
committed
Use DB owner to drop database
Find and use the current owner of the database when dropping the database during a restore operation.
1 parent 079a25c commit ae0bf59

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

application/restore.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ if [ -z "${result}" ]; then
2424
message="Database "${DB_NAME}" on host "${DB_HOST}" does not exist."
2525
echo "${MYNAME}: INFO: ${message}"
2626
else
27+
message="finding current owner of DB ${DB_NAME}"
28+
echo "${MYNAME}: ${message}"
29+
db_owner=$(psql --host=${DB_HOST} --username=${DB_ROOTUSER} --command='\list' | grep ${DB_NAME} | cut -d '|' -f 2 | sed -e 's/ *//')
30+
message="Database owner is ${db_owner}"
31+
echo "${MYNAME}: INFO: ${message}"
32+
2733
echo "${MYNAME}: deleting database ${DB_NAME}"
28-
result=$(psql --host=${DB_HOST} --dbname=postgres --username=${DB_USER} --command="DROP DATABASE ${DB_NAME};")
34+
result=$(psql --host=${DB_HOST} --dbname=postgres --username=${db_owner} --command="DROP DATABASE ${DB_NAME};")
2935
if [ "${result}" != "DROP DATABASE" ]; then
3036
message="Drop database command failed: ${result}"
3137
echo "${MYNAME}: FATAL: ${message}"

0 commit comments

Comments
 (0)