8000 DROP OWNED: don't try to drop tablespaces/databases · home201448/postgres@85abf1d · GitHub
[go: up one dir, main page]

Skip to content

Commit 85abf1d

Browse files
committed
DROP OWNED: don't try to drop tablespaces/databases
My "fix" for bugs #7578 and #6116 on DROP OWNED at fe3b5eb not only misstated that it applied to REASSIGN OWNED (which it did not affect), but it also failed to fix the problems fully, because I didn't test the case of owned shared objects. Thus I created a new bug, reported by Thomas Kellerer as #7748, which would cause DROP OWNED to fail with a not-for-user-consumption error message. The code would attempt to drop the database, which not only fails to work because the underlying code does not support that, but is a pretty dangerous and undesirable thing to be doing as well. This patch fixes that bug by having DROP OWNED only attempt to process shared objects when grants on them are found, ignoring ownership. Backpatch to 8.3, which is as far as the previous bug was backpatched.
1 parent de51042 commit 85abf1d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

doc/src/sgml/ref/drop_owned.sgml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ DROP OWNED BY <replaceable class="PARAMETER">name</replaceable> [, ...] [ CASCAD
2828
<title>Description</title>
2929

3030
<para>
31-
<command>DROP OWNED</command> drops all the objects in the current
31+
<command>DROP OWNED</command> drops all the objects within the current
3232
database that are owned by one of the specified roles. Any
3333
privileges granted to the given roles on objects in the current
34-
database will also be revoked.
34+
database and on shared objects (databases, tablespaces) will also be
35+
revoked.
3536
</para>
3637
</refsect1>
3738

@@ -91,6 +92,10 @@ DROP OWNED BY <replaceable class="PARAMETER">name</replaceable> [, ...] [ CASCAD
9192
reassigns the ownership of all the database objects owned by one or
9293
more roles.
9394
</para>
95+
96+
<para>
97+
Databases and tablespaces owned by the role(s) will not be removed.
98+
</para>
9499
</refsect1>
95100

96101
<refsect1>

src/backend/catalog/pg_shdepend.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,11 +1221,14 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
12211221
ExecGrantStmt_oids(&istmt);
12221222
break;
12231223
case SHARED_DEPENDENCY_OWNER:
1224-
/* Save it for deletion below */
1225-
obj.classId = sdepForm->classid;
1226-
obj.objectId = sdepForm->objid;
1227-
obj.objectSubId = 0;
1228-
add_exact_object_address(&obj, deleteobjs);
1224+
/* If a lo 710C cal object, save it for deletion below */
1225+
if (sdepForm->dbid == MyDatabaseId)
1226+
{
1227+
obj.classId = sdepForm->classid;
1228+
obj.objectId = sdepForm->objid;
1229+
obj.objectSubId = 0;
1230+
add_exact_object_address(&obj, deleteobjs);
1231+
}
12291232
break;
12301233
}
12311234
}

0 commit comments

Comments
 (0)
0