|
7 | 7 | <productname>PostgreSQL</productname> manages database access permissions
|
8 | 8 | using the concept of <firstterm>roles</>. A role can be thought of as
|
9 | 9 | either a database user, or a group of database users, depending on how
|
10 |
| - the role is set up. Roles can own database objects (for example, |
11 |
| - tables) and can assign privileges on those objects to other roles to |
| 10 | + the role is set up. Roles can own database objects (for example, tables |
| 11 | + and functions) and can assign privileges on those objects to other roles to |
12 | 12 | control who has access to which objects. Furthermore, it is possible
|
13 | 13 | to grant <firstterm>membership</> in a role to another role, thus
|
14 | 14 | allowing the member role to use privileges assigned to another role.
|
@@ -213,7 +213,7 @@ CREATE USER <replaceable>name</replaceable>;
|
213 | 213 | <para>
|
214 | 214 | A role must explicitly be given permission to initiate streaming
|
215 | 215 | replication (except for superusers, since those bypass all permission
|
216 |
| - checks). A role used for streaming replication must always |
| 216 | + checks). A role used for streaming replication must |
217 | 217 | have <literal>LOGIN</> permission as well. To create such a role, use
|
218 | 218 | <literal>CREATE ROLE <replaceable>name</replaceable> REPLICATION
|
219 | 219 | LOGIN</literal>.
|
@@ -408,9 +408,67 @@ RESET ROLE;
|
408 | 408 | DROP ROLE <replaceable>name</replaceable>;
|
409 | 409 | </synopsis>
|
410 | 410 | Any memberships in the group role are automatically revoked (but the
|
411 |
| - member roles are not otherwise affected). Note however that any objects |
412 |
| - owned by the group role must first be dropped or reassigned to other |
413 |
| - owners; and any permissions granted to the group role must be revoked. |
| 411 | + member roles are not otherwise affected). |
| 412 | + </para> |
| 413 | + </sect1> |
| 414 | + |
| 415 | + <sect1 id="role-removal"> |
| 416 | + <title>Dropping Roles</title> |
| 417 | + |
| 418 | + <para> |
| 419 | + Because roles can own database objects and can hold privileges |
| 420 | + to access other objects, dropping a role is often not just a matter of a |
| 421 | + quick <xref linkend="sql-droprole">. Any objects owned by the role must |
| 422 | + first be dropped or reassigned to other owners; and any permissions |
| 423 | + granted to the role must be revoked. |
| 424 | + </para> |
| 425 | + |
| 426 | + <para> |
| 427 | + Ownership of objects can be transferred one at a time |
| 428 | + using <command>ALTER</> commands, for example: |
| 429 | +<programlisting> |
| 430 | +ALTER TABLE bobs_table OWNER TO alice; |
| 431 | +</programlisting> |
| 432 | + Alternatively, the <xref linkend="sql-reassign-owned"> command can be |
| 433 | + used to reassign ownership of all objects owned by the role-to-be-dropped |
| 434 | + to a single other role. Because <command>REASSIGN OWNED</> can only |
| 435 | + access objects in the current database, it is necessary to run it in each |
| 436 | + database that contains objects owned by the role. |
| 437 | + </para> |
| 438 | + |
| 439 | + <para> |
| 440 | + Once any valuable objects have been transferred to new owners, any |
| 441 | + remaining objects owned by the role-to-be-dropped can be dropped with |
| 442 | + the <xref linkend="sql-drop-owned"> command. Again, this command can |
| 443 | + only access objects in the current database, so it is necessary to run it |
| 444 | + in each database that contains objects owned by the role. |
| 445 | + </para> |
| 446 | + |
| 447 | + <para> |
| 448 | + <command>DROP OWNED</> also takes care of removing any privileges granted |
| 449 | + to the target role for objects that do not belong to it. |
| 450 | + Because <command>REASSIGN OWNED</> does not touch such objects, it's |
| 451 | + typically necessary to run both <command>REASSIGN OWNED</> |
| 452 | + and <command>DROP OWNED</> (in that order!) to fully remove the |
| 453 | + dependencies of a role to be dropped. |
| 454 | + </para> |
| 455 | + |
| 456 | + <para> |
| 457 | + In short then, the most general recipe for removing a role that has been |
| 458 | + used to own objects is: |
| 459 | + |
| 460 | + </para> |
| 461 | +<programlisting> |
| 462 | +REASSIGN OWNED BY doomed_role TO successor_role; |
| 463 | +DROP OWNED BY doomed_role; |
| 464 | +-- repeat the above commands in each database of the cluster |
| 465 | +DROP ROLE doomed_role; |
| 466 | +</programlisting> |
| 467 | + |
| 468 | + <para> |
| 469 | + If <command>DROP ROLE</> is attempted while dependent objects still |
| 470 | + remain, it will issue messages identifying which objects need to be |
| 471 | + reassigned or dropped. |
414 | 472 | </para>
|
415 | 473 | </sect1>
|
416 | 474 |
|
|
0 commit comments