バージョンごとのドキュメント一覧

22.4. ロールの削除 #

<title>Dropping Roles</title>

Because roles can own database objects and can hold privileges to access other objects, dropping a role is often not just a matter of a quick <link linkend="sql-droprole"><command>DROP ROLE</command></link>. Any objects owned by the role must first be dropped or reassigned to other owners; and any permissions granted to the role must be revoked. ロールはデータベースオブジェクトを所有したり、他のオブジェクトにアクセスする権限を保持したりできるので、ロールを削除するのは、単にDROP ROLEを実行すれば良いというだけのものでないことがよくあります。 そのロールが所有するすべてのオブジェクトについて、まずそれを削除するか、あるいは他の所有者に移すかしなければなりません。 また、そのロールに付与されたすべての権限を取り上げる必要があります。

Ownership of objects can be transferred one at a time using <command>ALTER</command> commands, for example: オブジェクトの所有権はALTERコマンドを使って、1度に1つずつ移管することができます。 以下に例を示します。

ALTER TABLE bobs_table OWNER TO alice;

Alternatively, the <link linkend="sql-reassign-owned"><command>REASSIGN OWNED</command></link> command can be used to reassign ownership of all objects owned by the role-to-be-dropped to a single other role. Because <command>REASSIGN OWNED</command> cannot access objects in other databases, it is necessary to run it in each database that contains objects owned by the role. (Note that the first such <command>REASSIGN OWNED</command> will change the ownership of any shared-across-databases objects, that is databases or tablespaces, that are owned by the role-to-be-dropped.) その代わりにREASSIGN OWNEDコマンドを使って、削除予定のロールが所有するすべてのオブジェクトの所有権を、単一の他のロールに移管することもできます。 REASSIGN OWNEDは他のデータベースのオブジェクトにはアクセスできないので、そのロールが所有するオブジェクトを含むそれぞれのデータベース内で実行する必要があります。 (最初にそのようなREASSIGN OWNEDを実行した時に、データベース間で共有されるオブジェクト、つまりデータベースとテーブル空間については、すべて削除予定のロールから所有権が変更されることに注意してください。)

Once any valuable objects have been transferred to new owners, any remaining objects owned by the role-to-be-dropped can be dropped with the <link linkend="sql-drop-owned"><command>DROP OWNED</command></link> command. Again, this command cannot access objects in other databases, so it is necessary to run it in each database that contains objects owned by the role. Also, <command>DROP OWNED</command> will not drop entire databases or tablespaces, so it is necessary to do that manually if the role owns any databases or tablespaces that have not been transferred to new owners. 重要なオブジェクトがすべて新しい所有者に移管された後は、削除予定のロールが所有する残りのオブジェクトはすべてDROP OWNED commandコマンドで削除することができます。 ここでも、このコマンドは他のデータベースのオブジェクトにはアクセスできないので、そのロールが所有するオブジェクトを含むそれぞれのデータベース内で実行する必要があります。 また、DROP OWNEDはデータベース全体、あるいはテーブル空間全体を削除することはありませんので、ロールが所有するデータベースあるいはテーブル空間で新しい所有者に移管されていないものがあれば、手作業でそれを削除する必要があります。

<command>DROP OWNED</command> also takes care of removing any privileges granted to the target role for objects that do not belong to it. Because <command>REASSIGN OWNED</command> does not touch such objects, it's typically necessary to run both <command>REASSIGN OWNED</command> and <command>DROP OWNED</command> (in that order!) to fully remove the dependencies of a role to be dropped. DROP OWNEDは対象のロールが所有しないオブジェクトについて、そのロールに付与されたすべての権限を削除することも行います。 REASSIGN OWNEDはそのようなオブジェクトに関与しないので、削除されるロールによる依存関係を完全に取り除くには、多くの場合、REASSIGN OWNEDDROP OWNEDの両方を(この順序で!)実行する必要があります。

In short then, the most general recipe for removing a role that has been used to own objects is: まとめると、オブジェクトを所有するために使用されたロールを削除する最も一般的な手順は以下のようになります。

REASSIGN OWNED BY doomed_role TO successor_role;
DROP OWNED BY doomed_role;

&#45;- repeat the above commands in each database of the cluster

-- 上記のコマンドをクラスタ内の各データベースについて繰り返す
DROP ROLE doomed_role;

When not all owned objects are to be transferred to the same successor owner, it's best to handle the exceptions manually and then perform the above steps to mop up. すべての所有オブジェクトを同一の後継所有者に移管するのでない場合は、例外部分を手作業で処理した後で、上記の手順を実行して残りを処理するのが最善でしょう。

If <command>DROP ROLE</command> is attempted while dependent objects still remain, it will issue messages identifying which objects need to be reassigned or dropped. 依存するオブジェクトがまだ残っている状態でDROP ROLEを実行すると、どのオブジェクトが所有者変更または削除の必要があるかを特定するメッセージが発行されます。