From: Alvaro Herrera Date: Mon, 28 Jan 2013 20:46:47 +0000 (-0300) Subject: DROP OWNED: don't try to drop tablespaces/databases X-Git-Tag: REL9_1_8~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3eae7940aeae78432e55ce18efb8ef5ea93f9295;p=postgresql DROP OWNED: don't try to drop tablespaces/databases My "fix" for bugs #7578 and #6116 on DROP OWNED at fe3b5eb08a1 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. --- diff --git a/doc/src/sgml/ref/drop_owned.sgml b/doc/src/sgml/ref/drop_owned.sgml index a453af58d1..48cf0fa535 100644 --- a/doc/src/sgml/ref/drop_owned.sgml +++ b/doc/src/sgml/ref/drop_owned.sgml @@ -29,10 +29,11 @@ DROP OWNED BY name [, ...] [ CASCAD Description - DROP OWNED drops all the objects in the current + DROP OWNED drops all the objects within the current database that are owned by one of the specified roles. Any privileges granted to the given roles on objects in the current - database will also be revoked. + database and on shared objects (databases, tablespaces) will also be + revoked. @@ -93,7 +94,7 @@ DROP OWNED BY name [, ...] [ CASCAD - Databases owned by the role(s) will not be removed. + Databases and tablespaces owned by the role(s) will not be removed. diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c index 8d2d37c730..91e26f4e15 100644 --- a/src/backend/catalog/pg_shdepend.c +++ b/src/backend/catalog/pg_shdepend.c @@ -1235,11 +1235,14 @@ shdepDropOwned(List *roleids, DropBehavior behavior) sdepForm->objid); break; case SHARED_DEPENDENCY_OWNER: - /* Save it for deletion below */ - obj.classId = sdepForm->classid; - obj.objectId = sdepForm->objid; - obj.objectSubId = sdepForm->objsubid; - add_exact_object_address(&obj, deleteobjs); + /* If a local object, save it for deletion below */ + if (sdepForm->dbid == MyDatabaseId) + { + obj.classId = sdepForm->classid; + obj.objectId = sdepForm->objid; + obj.objectSubId = sdepForm->objsubid; + add_exact_object_address(&obj, deleteobjs); + } break; } }