summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2013-01-28 17:46:47 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2013-01-28 19:13:06 -0300
commit85abf1d2cf9a2e780b2187356571df4f1b86c527 (patch)
tree2f8456a6e98415a6a2374bc58cf38db1eb704d47
parentde5104234d3ab66738ba17b4a02b139bbd841062 (diff)
downloadpostgresql-85abf1d2cf9a2e780b2187356571df4f1b86c527.tar.gz
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.
-rw-r--r--doc/src/sgml/ref/drop_owned.sgml9
-rw-r--r--src/backend/catalog/pg_shdepend.c13
2 files changed, 15 insertions, 7 deletions
diff --git a/doc/src/sgml/ref/drop_owned.sgml b/doc/src/sgml/ref/drop_owned.sgml
index 6276f8e928..34c091c0c1 100644
--- a/doc/src/sgml/ref/drop_owned.sgml
+++ b/doc/src/sgml/ref/drop_owned.sgml
@@ -28,10 +28,11 @@ DROP OWNED BY <replaceable class="PARAMETER">name</replaceable> [, ...] [ CASCAD
<title>Description</title>
<para>
- <command>DROP OWNED</command> drops all the objects in the current
+ <command>DROP OWNED</command> 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.
</para>
</refsect1>
@@ -91,6 +92,10 @@ DROP OWNED BY <replaceable class="PARAMETER">name</replaceable> [, ...] [ CASCAD
reassigns the ownership of all the database objects owned by one or
more roles.
</para>
+
+ <para>
+ Databases and tablespaces owned by the role(s) will not be removed.
+ </para>
</refsect1>
<refsect1>
diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c
index 6f4d52c173..b44d2a2848 100644
--- a/src/backend/catalog/pg_shdepend.c
+++ b/src/backend/catalog/pg_shdepend.c
@@ -1221,11 +1221,14 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
ExecGrantStmt_oids(&istmt);
break;
case SHARED_DEPENDENCY_OWNER:
- /* Save it for deletion below */
- obj.classId = sdepForm->classid;
- obj.objectId = sdepForm->objid;
- obj.objectSubId = 0;
- 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 = 0;
+ add_exact_object_address(&obj, deleteobjs);
+ }
break;
}
}