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

5.7. 権限 #

<title>Privileges</title>

When an object is created, it is assigned an owner. The owner is normally the role that executed the creation statement. For most kinds of objects, the initial state is that only the owner (or a superuser) can do anything with the object. To allow other roles to use it, <firstterm>privileges</firstterm> must be granted. オブジェクトが作成されると、所有者が割り当てられます。通常、所有者は作成する文を実行したロールです。ほとんどの種類のオブジェクトについて、初期状態では所有者(またはスーパーユーザ)だけがそのオブジェクトを使用できます。 他のユーザがこのオブジェクトを使用するには、権限が付与されていなければなりません。

There are different kinds of privileges: <literal>SELECT</literal>, <literal>INSERT</literal>, <literal>UPDATE</literal>, <literal>DELETE</literal>, <literal>TRUNCATE</literal>, <literal>REFERENCES</literal>, <literal>TRIGGER</literal>, <literal>CREATE</literal>, <literal>CONNECT</literal>, <literal>TEMPORARY</literal>, <literal>EXECUTE</literal>, <literal>USAGE</literal>, <literal>SET</literal> and <literal>ALTER SYSTEM</literal>. The privileges applicable to a particular object vary depending on the object's type (table, function, etc.). More detail about the meanings of these privileges appears below. The following sections and chapters will also show you how these privileges are used. 権限にはいくつかの種類があります。 すなわちSELECTINSERTUPDATEDELETETRUNCATEREFERENCESTRIGGERCREATECONNECTTEMPORARYEXECUTEUSAGESETALTER SYSTEMです。 特定のオブジェクトに適用可能な権限は、オブジェクトの型(テーブル、関数など)により変わります。 これらの権限の詳細な意味を以下に示します。 以降の節および章でもこれらの権限の使用方法について説明があります。

The right to modify or destroy an object is inherent in being the object's owner, and cannot be granted or revoked in itself. (However, like all privileges, that right can be inherited by members of the owning role; see <xref linkend="role-membership"/>.) オブジェクトの変更や削除の権限は所有者に固有のもので、それ自体を許可したり取り消したりはできません (しかし、すべての権限同様、その権限を所有者のロールのメンバーが継承することはできます。22.3をご覧ください)。

An object can be assigned to a new owner with an <command>ALTER</command> command of the appropriate kind for the object, for example たとえば次のように、オブジェクトに対する適切な種類のALTERコマンドにより、あるオブジェクトに新しい所有者を割り当てることができます。

ALTER TABLE table_name OWNER TO new_owner;

Superusers can always do this; ordinary roles can only do it if they are both the current owner of the object (or inherit the privileges of the owning role) and able to <literal>SET ROLE</literal> to the new owning role. スーパーユーザはいつでも所有者を変更できます。 通常のロールは、オブジェクトの現在の所有者である(または所有者の権限を継承している)と同時に、新しい所有者のロールにSET ROLEできる場合に限り、所有者を変更できます。

To assign privileges, the <xref linkend="sql-grant"/> command is used. For example, if <literal>joe</literal> is an existing role, and <literal>accounts</literal> is an existing table, the privilege to update the table can be granted with: 権限を割り当てるには、GRANTコマンドを使用します。 例えば、joeという既存のロールとaccountsという既存のテーブルがある場合、このテーブルを更新する権限を付与するには以下のようにします。

GRANT UPDATE ON accounts TO joe;

Writing <literal>ALL</literal> in place of a specific privilege grants all privileges that are relevant for the object type. 特定の権限名を指定する代わりにALLを指定すると、その種類のオブジェクトに関連する全ての権限が付与されます。

The special <quote>role</quote> name <literal>PUBLIC</literal> can be used to grant a privilege to every role on the system. Also, <quote>group</quote> roles can be set up to help manage privileges when there are many users of a database &mdash; for details see <xref linkend="user-manag"/>. システム内の全てのロールに権限を付与するには、特別なロール名であるPUBLICを使用できます。 また、グループロールを使用すれば、データベース内に多くのユーザが存在する場合に権限の管理が簡単になります。 詳細は第22章を参照してください。

To revoke a previously-granted privilege, use the fittingly named <xref linkend="sql-revoke"/> command: 以前与えられた権限を取り消す(revoke)には、それに相応しい名前のREVOKEコマンドを使用します。

REVOKE ALL ON accounts FROM PUBLIC;

Ordinarily, only the object's owner (or a superuser) can grant or revoke privileges on an object. However, it is possible to grant a privilege <quote>with grant option</quote>, which gives the recipient the right to grant it in turn to others. If the grant option is subsequently revoked then all who received the privilege from that recipient (directly or through a chain of grants) will lose the privilege. For details see the <xref linkend="sql-grant"/> and <xref linkend="sql-revoke"/> reference pages. 普通はオブジェクトの所有者(またはスーパーユーザ)だけが、オブジェクトにおける権限の付与や剥奪ができます。 しかしwith grant optionを付けることで、権限を与えられたユーザが、所有者と同様に他のユーザに権限を付与することが可能になります。 もし後になってグラントオプションが剥奪されると、剥奪されたユーザから(直接もしくは権限付与の連鎖により)権限を与えられていたユーザはすべて、その権限が剥奪されます。 詳細は、GRANTREVOKEを参照してください。

An object's owner can choose to revoke their own ordinary privileges, for example to make a table read-only for themselves as well as others. But owners are always treated as holding all grant options, so they can always re-grant their own privileges. オブジェクトの所有者は、所有する通常の権限を削除することを選択できます。たとえば、他のものと同様、自身のためにテーブルを読み取り専用にできます。 しかし、所有者は常にすべての付与オプションを持つものとして扱われます。ですから、いつでも自身の権限を再び付与できます。

The available privileges are: 可能な権限は以下です。

SELECT #

Allows <command>SELECT</command> from any column, or specific column(s), of a table, view, materialized view, or other table-like object. Also allows use of <command>COPY TO</command>. This privilege is also needed to reference existing column values in <command>UPDATE</command>, <command>DELETE</command>, or <command>MERGE</command>. For sequences, this privilege also allows use of the <function>currval</function> function. For large objects, this privilege allows the object to be read. テーブル、ビュー、マテリアライズドビュー、あるいはそれ以外のテーブルのように見えるオブジェクトに対してSELECTをある列、あるいは指定した列(複数可)に許可します。 また、COPY TOの利用を許可します。 この権限はUPDATEDELETEまたはMERGEにおいて既存の列を参照する場合にも必要になります。 シーケンスにおいてこの権限はcurrval関数の使用を許可します。 ラージオブジェクトにおいてこの権限はオブジェクトの読み出しを許可します。

INSERT #

Allows <command>INSERT</command> of a new row into a table, view, etc. Can be granted on specific column(s), in which case only those columns may be assigned to in the <command>INSERT</command> command (other columns will therefore receive default values). Also allows use of <command>COPY FROM</command>. テーブル、ビューなどに新しい行をINSERTすることを許可します。 特定の列だけをINSERTコマンドで指定したい場合に、それらの列に許可することができます。 (したがって他の列にはデフォルトが設定されます)。 COPY FROMを利用することもできます。

UPDATE #

Allows <command>UPDATE</command> of any column, or specific column(s), of a table, view, etc. (In practice, any nontrivial <command>UPDATE</command> command will require <literal>SELECT</literal> privilege as well, since it must reference table columns to determine which rows to update, and/or to compute new values for columns.) <literal>SELECT ... FOR UPDATE</literal> and <literal>SELECT ... FOR SHARE</literal> also require this privilege on at least one column, in addition to the <literal>SELECT</literal> privilege. For sequences, this privilege allows use of the <function>nextval</function> and <function>setval</function> functions. For large objects, this privilege allows writing or truncating the object. テーブル、ビューなどの列をUPDATEすることを許可します。 (実用的には、単純ではないUPDATEコマンドにはSELECT権限も必要になります。 どの行を更新するかを決定したり、列に対して新しい値を計算するためにテーブルの列を参照しなければならないからです。) SELECT ... FOR UPDATESELECT ... FOR SHARESELECT権限に加えてさらにこの権限が必要になります。 シーケンスでこの権限はnextvalsetval関数の利用を許可します。 ラージオブジェクトでこの権限はオブジェクトへの書き込みあるいは切り詰めを行うことを許可します。

DELETE #

Allows <command>DELETE</command> of a row from a table, view, etc. (In practice, any nontrivial <command>DELETE</command> command will require <literal>SELECT</literal> privilege as well, since it must reference table columns to determine which rows to delete.) テーブル、ビューなどの列をDELETEすることを許可します。 (実用的には、簡単ではないDELETEコマンドにはSELECT権限も必要になります。 どの行を削除するかを決定するためにテーブルの列を参照しなければならないからです。)

TRUNCATE #

Allows <command>TRUNCATE</command> on a table. テーブルにTRUNCATEを許可します。

REFERENCES #

Allows creation of a foreign key constraint referencing a table, or specific column(s) of a table. テーブルあるいはテーブルの特定の列を参照する外部キー制約を作ることを許可します。

TRIGGER #

Allows creation of a trigger on a table, view, etc. テーブルあるいはビューにトリガを作ることを許可します。

CREATE #

For databases, allows new schemas and publications to be created within the database, and allows trusted extensions to be installed within the database. データベースに対して、データベース内に新しいスキーマとパブリケーションを作ること、信頼できる拡張をデータベース内に作成することを許可します。

For schemas, allows new objects to be created within the schema. To rename an existing object, you must own the object <emphasis>and</emphasis> have this privilege for the containing schema. スキーマに対して、スキーマ内に新しいオブジェクトを作ることを許可します。 既存のオブジェクトの名前を変えるには、オブジェクトを所有するとともにそのオブジェクトを含むスキーマに対してこの権限を持っていなければなりません。

For tablespaces, allows tables, indexes, and temporary files to be created within the tablespace, and allows databases to be created that have the tablespace as their default tablespace. テーブル空間に対しては、そのテーブル空間内にテーブル、インデックス、一時ファイルを作ることを許可し、そのテーブル空間をデフォルトのテーブル空間として持つデータベースを作ることを許可します。

Note that revoking this privilege will not alter the existence or location of existing objects. この権限を剥奪しても既存のオブジェクトの存在、あるいはその配置を変更しないことに注意してください。

CONNECT #

Allows the grantee to connect to the database. This privilege is checked at connection startup (in addition to checking any restrictions imposed by <filename>pg_hba.conf</filename>). 権限を与えられた者がデータベースに接続することを許可します。 (pg_hba.confが課す制限の検査に加えて)この権限は接続の開始時に検査されます。

TEMPORARY #

Allows temporary tables to be created while using the database. データベース使用中に一時テーブルを作成することを許可します。

EXECUTE #

Allows calling a function or procedure, including use of any operators that are implemented on top of the function. This is the only type of privilege that is applicable to functions and procedures. 関数上に実装された演算子を含めて関数あるいはプロシージャの呼び出しを許可します。 これは関数とプロシージャに適用される唯一のタイプの権限です。

USAGE #

For procedural languages, allows use of the language for the creation of functions in that language. This is the only type of privilege that is applicable to procedural languages. 手続き言語に対して、言語内で関数を作るために言語を使用することを許可します。 これは手続き言語に適用される唯一のタイプの権限です。

For schemas, allows access to objects contained in the schema (assuming that the objects' own privilege requirements are also met). Essentially this allows the grantee to <quote>look up</quote> objects within the schema. Without this permission, it is still possible to see the object names, e.g., by querying system catalogs. Also, after revoking this permission, existing sessions might have statements that have previously performed this lookup, so this is not a completely secure way to prevent object access. スキーマに対しては、(オブジェクト自身の権限要件が満たされているものと仮定した上で)スキーマ内に含まれるオブジェクトへのアクセスを許可します。 本質的に、これは権限を授与されたものがスキーマ内のオブジェクトを検査することを許可します。 この許可がなくても依然としてオブジェクト名を見ることが可能です。たとえば、システムカタログを問い合わせることによってです。 また、この許可を剥奪した後でも、既存のセッションはすでにこの検査を実施していると主張するかも知れません。 ですからこれはオブジェクトへのアクセスを妨げる完全にセキュアな方法ではありません。

For sequences, allows use of the <function>currval</function> and <function>nextval</function> functions. シーケンスに対しては、currvalnextval関数の利用を許可します。

For types and domains, allows use of the type or domain in the creation of tables, functions, and other schema objects. (Note that this privilege does not control all <quote>usage</quote> of the type, such as values of the type appearing in queries. It only prevents objects from being created that depend on the type. The main purpose of this privilege is controlling which users can create dependencies on a type, which could prevent the owner from changing the type later.) 型とドメインに対しては、テーブル、関数、および他のスキーマオブジェクトを生成する際に型とドメインを使用することを許可します。 (たとえば問い合わせ中に表れる型の値のような、すべての型の利用をこの権限はコントロールするわけではないことに注意してください。 その型に依存するオブジェクトが作られるのを防ぐだけです。 この権限の主な目的は、どのユーザがある型への依存関係を作ることができるかを制御し、後で所有者がこの型を変更するのを防ぐためです。)

For foreign-data wrappers, allows creation of new servers using the foreign-data wrapper. 外部データラッパーに対しては、その外部データラッパーを使って新しいサーバを作ることを許可します。

For foreign servers, allows creation of foreign tables using the server. Grantees may also create, alter, or drop their own user mappings associated with that server. 外部サーバに対しては、そのサーバを使って外部テーブルを作ることを許可します。 権限を授与されたものは、そのサーバに結びついたユーザマッピングを作成、変更、削除できます。

SET #

Allows a server configuration parameter to be set to a new value within the current session. (While this privilege can be granted on any parameter, it is meaningless except for parameters that would normally require superuser privilege to set.) サーバ構成パラメータを現在のセッション内で新しい値に設定できるようにします(この特権はどのパラメータにも付与できますが、通常はスーパーユーザ特権を必要とするパラメーター以外は意味がありません)。

ALTER SYSTEM #

Allows a server configuration parameter to be configured to a new value using the <xref linkend="sql-altersystem"/> command. ALTER SYSTEMコマンドを使用して、サーバ設定パラメータを新しい値に設定できるようにします。

The privileges required by other commands are listed on the reference page of the respective command. 他のコマンドで必要となる権限はそれぞれのコマンドのリファレンスページに列挙されています。

PostgreSQL grants privileges on some types of objects to <literal>PUBLIC</literal> by default when the objects are created. No privileges are granted to <literal>PUBLIC</literal> by default on tables, table columns, sequences, foreign data wrappers, foreign servers, large objects, schemas, tablespaces, or configuration parameters. For other types of objects, the default privileges granted to <literal>PUBLIC</literal> are as follows: <literal>CONNECT</literal> and <literal>TEMPORARY</literal> (create temporary tables) privileges for databases; <literal>EXECUTE</literal> privilege for functions and procedures; and <literal>USAGE</literal> privilege for languages and data types (including domains). The object owner can, of course, <command>REVOKE</command> both default and expressly granted privileges. (For maximum security, issue the <command>REVOKE</command> in the same transaction that creates the object; then there is no window in which another user can use the object.) Also, these default privilege settings can be overridden using the <xref linkend="sql-alterdefaultprivileges"/> command. PostgreSQLはあるタイプのオブジェクトが作成された時に、そのオブジェクトに対する権限をデフォルトでPUBLICに付与します。 テーブル、テーブルの列、シーケンス、外部データラッパー、外部サーバ、ラージオブジェクト、スキーマ、テーブル空間、構成パラメータに対しては、デフォルトではPUBLICに権限を付与しません。 他のタイプのオブジェクトに対しては、PUBLICにデフォルトで付与される権限は次のものです。 CONNECTTEMPORARY (データベース内で一時テーブルを作成する権限)、関数とプロシージャに対するEXECUTE権限、言語とデータ型(ドメインを含む)に対するUSAGE権限。 もちろんオブジェクトの所有者は、デフォルト、あるいは明示的に与えられた権限をREVOKEできます。 (セキュリティを最大限に高めるためには、REVOKEをオブジェクトを作成したのと同じトランザクション内で発行してください。そうすれば他のユーザがそのオブジェクトを使う隙が存在しません。) また、デフォルトの権限設定はALTER DEFAULT PRIVILEGESを使って上書きできます。

<xref linkend="privilege-abbrevs-table"/> shows the one-letter abbreviations that are used for these privilege types in <firstterm>ACL</firstterm> (Access Control List) values. You will see these letters in the output of the <xref linkend="app-psql"/> commands listed below, or when looking at ACL columns of system catalogs. 表 5.1に、ACL(Access Control List)値において権限タイプに使われる1文字の短縮形を示します。 psqlの出力、あるいはシステムカタログのACL列を参照することでこれらの文字を見ることができます。

表5.1 ACL短縮形

<title>ACL Privilege Abbreviations</title>
権限短縮形適用可能なオブジェクトタイプ
SELECTr (read) LARGE OBJECT, SEQUENCE, <literal>TABLE</literal> (and table-like objects), table column TABLE(およびテーブルのようなオブジェクト)、テーブルの列
INSERTa (append)TABLE、テーブルの列
UPDATEw (write) LARGE OBJECT, SEQUENCE, TABLE, table column テーブルの列
DELETEdTABLE
TRUNCATEDTABLE
REFERENCESxTABLE、テーブルの列
TRIGGERtTABLE
CREATEC DATABASE, SCHEMA, TABLESPACE
CONNECTcDATABASE
TEMPORARYTDATABASE
EXECUTEXFUNCTION, PROCEDURE
USAGEU DOMAIN, FOREIGN DATA WRAPPER, FOREIGN SERVER, LANGUAGE, SCHEMA, SEQUENCE, TYPE
SETsPARAMETER
ALTER SYSTEMAPARAMETER

<xref linkend="privileges-summary-table"/> summarizes the privileges available for each type of SQL object, using the abbreviations shown above. It also shows the <application>psql</application> command that can be used to examine privilege settings for each object type. 表 5.2は、前述の短縮形を用いてそれぞれのタイプのSQLオブジェクトで利用可能な権限をまとめています。 また、それぞれのオブジェクトタイプの権限設定を調べる際に利用できるpsqlコマンドを示します。

表5.2 アクセス権限のまとめ

<title>Summary of Access Privileges</title>
オブジェクトタイプすべての権限デフォルトPUBLIC権限psqlコマンド
DATABASECTcTc\l
DOMAINUU\dD+
FUNCTION or PROCEDUREXX\df+
FOREIGN DATA WRAPPERUnone\dew+
FOREIGN SERVERUnone\des+
LANGUAGEUU\dL+
LARGE OBJECTrwnone\dl+
PARAMETERsAnone\dconfig+
SCHEMAUCnone\dn+
SEQUENCErwUnone\dp
TABLE(およびテーブルのようなオブジェクト)arwdDxtnone\dp
テーブルの列arwxnone\dp
TABLESPACECnone\db+
TYPEUU\dT+

The privileges that have been granted for a particular object are displayed as a list of <type>aclitem</type> entries, where each <type>aclitem</type> describes the permissions of one grantee that have been granted by a particular grantor. For example, <literal>calvin=r*w/hobbes</literal> specifies that the role <literal>calvin</literal> has the privilege <literal>SELECT</literal> (<literal>r</literal>) with grant option (<literal>*</literal>) as well as the non-grantable privilege <literal>UPDATE</literal> (<literal>w</literal>), both granted by the role <literal>hobbes</literal>. If <literal>calvin</literal> also has some privileges on the same object granted by a different grantor, those would appear as a separate <type>aclitem</type> entry. An empty grantee field in an <type>aclitem</type> stands for <literal>PUBLIC</literal>. あるオブジェクトに与えられている権限はaclitemエントリのリストとして表示されます。 そこでは、aclitemはある権限付与者によって与えられている権限授与者の許可を示しています。 たとえば、calvin=r*w/hobbesは、ロールcalvinが許可オプション(*)ありのSELECTr)と許可オプションなしのUPDATE (w)を持ち、それらがロールhobbesに与えられていることを示します。 別の権限付与者によって権限が与えられている同じオブジェクトに対してcalvinも権限を持っている場合は、別のaclitemエントリとして表示されます。 aclitemの権限授与者フィールドが空であれば、それはPUBLICを表します。

As an example, suppose that user <literal>miriam</literal> creates table <literal>mytable</literal> and does: ユーザmiriamがテーブルmytableを作成し、以下を行う例を考えます。

GRANT SELECT ON mytable TO PUBLIC;
GRANT SELECT, UPDATE, INSERT ON mytable TO admin;
GRANT SELECT (col1), UPDATE (col1) ON mytable TO miriam_rw;

Then <application>psql</application>'s <literal>\dp</literal> command would show: すると、psql\dpコマンドは次のように表示するはずです。

=> \dp mytable
                                  Access privileges
 Schema |  Name   | Type  |   Access privileges   |   Column privileges   | Policies
--------+---------+-------+-----------------------+-----------------------+----------
 public | mytable | table | miriam=arwdDxt/miriam+| col1:                +|
        |         |       | =r/miriam            +|   miriam_rw=rw/miriam |
        |         |       | admin=arw/miriam      |                       |
(1 row)

If the <quote>Access privileges</quote> column is empty for a given object, it means the object has default privileges (that is, its privileges entry in the relevant system catalog is null). Default privileges always include all privileges for the owner, and can include some privileges for <literal>PUBLIC</literal> depending on the object type, as explained above. The first <command>GRANT</command> or <command>REVOKE</command> on an object will instantiate the default privileges (producing, for example, <literal>miriam=arwdDxt/miriam</literal>) and then modify them per the specified request. Similarly, entries are shown in <quote>Column privileges</quote> only for columns with nondefault privileges. (Note: for this purpose, <quote>default privileges</quote> always means the built-in default privileges for the object's type. An object whose privileges have been affected by an <command>ALTER DEFAULT PRIVILEGES</command> command will always be shown with an explicit privilege entry that includes the effects of the <command>ALTER</command>.) あるオブジェクトに対してAccess privileges列が空なら、そのオブジェクトがデフォルトの権限を持つことを意味します。 (つまり、関連するシステムカタログの権限エントリがNULLだということです。) デフォルト権限は常に所有者の全権限を含み、さらに上で説明を示したようにオブジェクトタイプ依存のPUBLICに対する権限を持つことができます。 オブジェクトに対する初回のGRANTあるいはREVOKEにより、デフォルト権限(たとえばmiriam=arwdDxt/miriam)が設定され、次に特定の要求に従って変更されます。 同様に、Column privilegesに示されるエントリは非デフォルトの権限を持つ列のためだけのものです。 (注意:デフォルト権限は常にオブジェクトのタイプの組み込みのデフォルト権限を意味します。 ALTER DEFAULT PRIVILEGESコマンドによって権限が影響を受けるオブジェクトは常にALTERの影響を含む明示的な権限エントリを伴って示されます。)

Notice that the owner's implicit grant options are not marked in the access privileges display. A <literal>*</literal> will appear only when grant options have been explicitly granted to someone. 所有者の暗黙的な許可オプションはアクセス権限表示で印を付けられないことに注意してください。 *は許可オプションが明示的に誰かに許可されたときにのみ現れます。