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

22.1. データベースロール #

<title>Database Roles</title>

Database roles are conceptually completely separate from operating system users. In practice it might be convenient to maintain a correspondence, but this is not required. Database roles are global across a database cluster installation (and not per individual database). To create a role use the <link linkend="sql-createrole"><command>CREATE ROLE</command></link> SQL command: データベースロールは概念的に、オペレーティングシステムユーザとは完全に分離されています。 実行する上でユーザ名を一致させておくと便利ですが、必須ではありません。 データベースロール名はデータベースクラスタインストレーション全体で共通です (個別のデータベースごとではありません)。 ユーザを作成するためにはCREATE ROLE SQLコマンドを使います。

CREATE ROLE name;

<replaceable>name</replaceable> follows the rules for SQL identifiers: either unadorned without special characters, or double-quoted. (In practice, you will usually want to add additional options, such as <literal>LOGIN</literal>, to the command. More details appear below.) To remove an existing role, use the analogous <link linkend="sql-droprole"><command>DROP ROLE</command></link> command: nameはSQL識別子の規則に従います。 特殊な文字を持たない無装飾のものか、二重引用符に囲まれたもののどちらかです。 (現実的には、通常他のオプション、例えばLOGINなどをこのコマンドに付与することになるでしょう。 詳細は後で説明します。) 既存のユーザを削除するためには類似のコマンドDROP ROLEを使用してください。

DROP ROLE name;

For convenience, the programs <xref linkend="app-createuser"/> and <xref linkend="app-dropuser"/> are provided as wrappers around these SQL commands that can be called from the shell command line: 利便性のために、これらのSQLコマンドのラッパーである、シェルのコマンドラインから呼び出し可能なcreateuserプログラムとdropuserプログラムが提供されています。

createuser name
dropuser name

To determine the set of existing roles, examine the <structname>pg_roles</structname> system catalog, for example: 既存のロール群を求めるためには、以下のようにpg_rolesシステムカタログを確認してください。

SELECT rolname FROM pg_roles;

or to see just those capable of logging in: あるいはログインできるロールだけを確認するには以下のようにします。

SELECT rolname FROM pg_roles WHERE rolcanlogin;

The <xref linkend="app-psql"/> program's <literal>\du</literal> meta-command is also useful for listing the existing roles. また、psqlプログラムの\duメタコマンドも既存のロールを列挙する際に役に立ちます。

In order to bootstrap the database system, a freshly initialized system always contains one predefined login-capable role. This role is always a <quote>superuser</quote>, and by default it will have the same name as the operating system user that initialized the database cluster, unless another name is specified while running <command>initdb</command>. It is common, but not required, to arrange for this role to be named <literal>postgres</literal>. In order to create more roles you first have to connect as this initial role. データベースシステム自身を起動するために、初期化されたばかりのシステムは常に定義済みでログイン可能なロールを1つ持ちます。 このロールは必ずスーパーユーザであり、initdb実行時に他の名前を指定しない限り、デフォルトではそのデータベースクラスタを初期化したオペレーティングシステムユーザと同じ名前となります。 必須ではありませんが、習慣的にこのロールはpostgresと名付けられます。 ロールを追加する場合はまずこの初期ロールで接続しなければいけません。

Every connection to the database server is made using the name of some particular role, and this role determines the initial access privileges for commands issued in that connection. The role name to use for a particular database connection is indicated by the client that is initiating the connection request in an application-specific fashion. For example, the <command>psql</command> program uses the <option>-U</option> command line option to indicate the role to connect as. Many applications assume the name of the current operating system user by default (including <command>createuser</command> and <command>psql</command>). Therefore it is often convenient to maintain a naming correspondence between roles and operating system users. すべてのデータベースサーバへの接続は、特定のロールの名前を使用して確立し、そのロールによりその接続で発行されるコマンドの初期のアクセス権限が決まります。 特定のデータベース接続に使うロールは、アプリケーション固有の方式で接続要求を開始するクライアントによって指示されます。 例えば、psqlプログラムでは、-Uコマンドラインオプションを使って接続するロールを指示します。 多くのアプリケーション(createuserおよびpsqlを含む)では、オペレーティングシステムの現在のユーザ名をデフォルトと想定します。 したがって、ロールとオペレーティングシステムのユーザの組み合わせ間で名前を一致させておくと便利です。

The set of database roles a given client connection can connect as is determined by the client authentication setup, as explained in <xref linkend="client-authentication"/>. (Thus, a client is not limited to connect as the role matching its operating system user, just as a person's login name need not match his or her real name.) Since the role identity determines the set of privileges available to a connected client, it is important to carefully configure privileges when setting up a multiuser environment. 第21章で説明されているように、あるクライアント接続で与えられたデータベースロールの集合は、クライアント認証設定で決定された内容で接続できます。 (したがって、ユーザのログイン名が本名と一致していなくても構わないのと同様に、クライアントはオペレーティングシステムのユーザ名と同じロール名で接続しなくても構いません)。 接続したクライアントに付与される権限の内容はロールIDによって決定されるため、マルチユーザ環境を設定する際には権限を注意深く設定することが重要です。