Skip to content

Commit ee22c55

Browse files
committed
REASSIGN OWNED: handle shared objects, too
Give away ownership of shared objects (databases, tablespaces) along with local objects, per original code intention. Try to make the documentation clearer, too. Per discussion about DROP OWNED's brokenness, in bug #7748. This is not backpatched because it'd require some refactoring of the ALTER/SET OWNER code for databases and tablespaces.
1 parent ec41b8e commit ee22c55

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

doc/src/sgml/ref/reassign_owned.sgml

+5-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ REASSIGN OWNED BY <replaceable class="PARAMETER">old_role</replaceable> [, ...]
3030

3131
<para>
3232
<command>REASSIGN OWNED</command> instructs the system to change
33-
the ownership of the database objects owned by one of the
33+
the ownership of database objects owned by one of the
3434
old_roles, to new_role.
3535
</para>
3636
</refsect1>
@@ -43,8 +43,9 @@ REASSIGN OWNED BY <replaceable class="PARAMETER">old_role</replaceable> [, ...]
4343
<term><replaceable class="PARAMETER">old_role</replaceable></term>
4444
<listitem>
4545
<para>
46-
The name of a role. The ownership of all the objects in the
47-
current database owned by this role will be reassigned to
46+
The name of a role. The ownership of all the objects within the
47+
current database, and of all shared objects (databases, tablespaces),
48+
owned by this role will be reassigned to
4849
<replaceable class="PARAMETER">new_role</replaceable>.
4950
</para>
5051
</listitem>
@@ -68,7 +69,7 @@ REASSIGN OWNED BY <replaceable class="PARAMETER">old_role</replaceable> [, ...]
6869
<para>
6970
<command>REASSIGN OWNED</command> is often used to prepare for the
7071
removal of one or more roles. Because <command>REASSIGN
71-
OWNED</command> only affects the objects in the current database,
72+
OWNED</command> does not affect objects within other databases,
7273
it is usually necessary to execute this command in each database
7374
that contains objects owned by a role that is to be removed.
7475
</para>
@@ -92,12 +93,6 @@ REASSIGN OWNED BY <replaceable class="PARAMETER">old_role</replaceable> [, ...]
9293
privileges.
9394
</para>
9495

95-
<para>
96-
The <command>REASSIGN OWNED</command> command does not affect the
97-
ownership of any databases owned by the role. Use
98-
<xref linkend="sql-alterdatabase"> to reassign that ownership.
99-
</para>
100-
10196
</refsect1>
10297

10398
<refsect1>

src/backend/catalog/pg_shdepend.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,12 @@ shdepReassignOwned(List *roleids, Oid newrole)
13251325
{
13261326
Form_pg_shdepend sdepForm = (Form_pg_shdepend) GETSTRUCT(tuple);
13271327

1328-
/* We only operate on objects in the current database */
1329-
if (sdepForm->dbid != MyDatabaseId)
1328+
/*
1329+
* We only operate on shared objects and objects in the current
1330+
* database
1331+
*/
1332+
if (sdepForm->dbid != MyDatabaseId &&
1333+
sdepForm->dbid != InvalidOid)
13301334
continue;
13311335

13321336
/* Unexpected because we checked for pins above */
@@ -1388,6 +1392,8 @@ shdepReassignOwned(List *roleids, Oid newrole)
13881392
case OperatorFamilyRelationId:
13891393
case OperatorClassRelationId:
13901394
case ExtensionRelationId:
1395+
case TableSpaceRelationId:
1396+
case DatabaseRelationId:
13911397
{
13921398
Oid classId = sdepForm->classid;
13931399
Relation catalog;

0 commit comments

Comments
 (0)