Skip to content

Commit 7188b9b

Browse files
committed
Fix bug in DROP OWNED BY.
Commit 6566133 broke the case where the role passed to DROP OWNED BY owns a database. Report by Rushabh Lathia, who also provided a patch, but this patch takes a slightly different approach to fixing the problem. Discussion: http://postgr.es/m/CAGPqQf2vO+nbo=3yAdZ8v26Rbug7bY4YjPaPLZx=L1NZ9-CC3w@mail.gmail.com
1 parent a448e49 commit 7188b9b

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/backend/catalog/pg_shdepend.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,19 +1412,28 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
14121412
break;
14131413
}
14141414
/* FALLTHROUGH */
1415+
14151416
case SHARED_DEPENDENCY_OWNER:
1416-
/* Save it for deletion below */
1417-
obj.classId = sdepForm->classid;
1418-
obj.objectId = sdepForm->objid;
1419-
obj.objectSubId = sdepForm->objsubid;
1420-
/* as above */
1421-
AcquireDeletionLock(&obj, 0);
1422-
if (!systable_recheck_tuple(scan, tuple))
1417+
/*
1418+
* Save it for deletion below, if it's a local object or a
1419+
* role grant. Other shared objects, such as databases,
1420+
* should not be removed here.
1421+
*/
1422+
if (sdepForm->dbid == MyDatabaseId ||
1423+
sdepForm->classid == AuthMemRelationId)
14231424
{
1424-
ReleaseDeletionLock(&obj);
1425-
break;
1425+
obj.classId = sdepForm->classid;
1426+
obj.objectId = sdepForm->objid;
1427+
obj.objectSubId = sdepForm->objsubid;
1428+
/* as above */
1429+
AcquireDeletionLock(&obj, 0);
1430+
if (!systable_recheck_tuple(scan, tuple))
1431+
{
1432+
ReleaseDeletionLock(&obj);
1433+
break;
1434+
}
1435+
add_exact_object_address(&obj, deleteobjs);
14261436
}
1427-
add_exact_object_address(&obj, deleteobjs);
14281437
break;
14291438
}
14301439
}

src/bin/scripts/t/020_createdb.pl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,22 @@
158158
qr/statement: CREATE DATABASE foobar7 STRATEGY file_copy TEMPLATE foobar2/,
159159
'create database with FILE_COPY strategy');
160160

161+
# Create database owned by role_foobar.
162+
$node->issues_sql_like(
163+
[ 'createdb', '-T', 'foobar2', '-O', 'role_foobar', 'foobar8' ],
164+
qr/statement: CREATE DATABASE foobar8 OWNER role_foobar TEMPLATE foobar2/,
165+
'create database with owner role_foobar');
166+
($ret, $stdout, $stderr) = $node->psql(
167+
'foobar2',
168+
'DROP OWNED BY role_foobar;',
169+
on_error_die => 1,
170+
);
171+
ok($ret == 0, "DROP OWNED BY role_foobar");
172+
($ret, $stdout, $stderr) = $node->psql(
173+
'foobar2',
174+
'DROP DATABASE foobar8;',
175+
on_error_die => 1,
176+
);
177+
ok($ret == 0, "DROP DATABASE foobar8");
178+
161179
done_testing();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy