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

createuser

createuser <refpurpose>define a new <productname>PostgreSQL</productname> user account</refpurpose> — 新しいPostgreSQLのユーザアカウントを定義する

概要

createuser [connection-option...] [option...] [username]

説明

<title>Description</title>

<application>createuser</application> creates a new <productname>PostgreSQL</productname> user (or more precisely, a role). Only superusers and users with <literal>CREATEROLE</literal> privilege can create new users, so <application>createuser</application> must be invoked by someone who can connect as a superuser or a user with <literal>CREATEROLE</literal> privilege. createuserは新しいPostgreSQLのユーザ(より正確にいえばロール)を作成します。 新しいユーザを作成できるのは、スーパーユーザとCREATEROLE権限を持つユーザのみです。 したがって、createuserは、スーパーユーザもしくはCREATEROLE権限を持つユーザとして接続可能なユーザによって実行されなければなりません。

If you wish to create a role with the <literal>SUPERUSER</literal>, <literal>REPLICATION</literal>, or <literal>BYPASSRLS</literal> privilege, you must connect as a superuser, not merely with <literal>CREATEROLE</literal> privilege. Being a superuser implies the ability to bypass all access permission checks within the database, so superuser access should not be granted lightly. <literal>CREATEROLE</literal> also conveys <link linkend="role-creation">very extensive privileges</link>. SUPERUSERREPLICATION、またはBYPASSRLS権限を持つロールを作成したいのであれば、スーパーユーザとして接続しなければなりません。CREATEROLE権限だけではいけません。 スーパーユーザであるということは、そのデータベースにおけるアクセス権限の検査を素通りできることを意味しています。したがって、スーパーユーザのアクセス権を簡単に与えてはなりません。 CREATEROLE非常に広範な権限を付与します。

<application>createuser</application> is a wrapper around the <acronym>SQL</acronym> command <link linkend="sql-createrole"><command>CREATE ROLE</command></link>. There is no effective difference between creating users via this utility and via other methods for accessing the server. createuserSQLコマンドCREATE ROLEのラッパーです。 このユーティリティによってユーザを作成しても、これ以外の方法でサーバにアクセスしてユーザを作成しても特に違いはありません。

オプション

<title>Options</title>

<application>createuser</application> accepts the following command-line arguments: createuserでは、下記のコマンドライン引数を指定できます。

username

Specifies the name of the <productname>PostgreSQL</productname> user to be created. This name must be different from all existing roles in this <productname>PostgreSQL</productname> installation. 作成するPostgreSQLユーザの名前を指定します。 この名前は、そのPostgreSQLインストレーションに存在するすべてのロールと異なるものでなければなりません。

-a role
--with-admin=role

Specifies an existing role that will be automatically added as a member of the new role with admin option, giving it the right to grant membership in the new role to others. Multiple existing roles can be specified by writing multiple <option>-a</option> switches. アドミンオプションを持つ新しいロールのメンバとして自動的に追加される既存のロールを指定します。 これにより、新しいロールのメンバ資格を他の人に付与する権利が与えられます。 -aスイッチを複数記述することで、複数の既存のロールを指定できます。

-c number
--connection-limit=number

Set a maximum number of connections for the new user. The default is to set no limit. 新しいユーザの最大接続数を設定します。 デフォルトでは無制限です。

-d
--createdb

The new user will be allowed to create databases. 新しいユーザに対してデータベースの作成を許可します。

-D
--no-createdb

The new user will not be allowed to create databases. This is the default. 新しいユーザに対してデータベースの作成を禁止します。 これはデフォルトです。

-e
--echo

Echo the commands that <application>createuser</application> generates and sends to the server. createuserが生成しサーバに送信するコマンドを出力します。

-E
--encrypted

This option is obsolete but still accepted for backward compatibility. このオプションは廃止されましたが、後方互換性のためにまだ受け付けられます。

-g role
--member-of=role
--role=role (deprecated)

Specifies the new role should be automatically added as a member of the specified existing role. Multiple existing roles can be specified by writing multiple <option>-g</option> switches. 新しいロールが、指定された既存のロールのメンバとして自動的に追加されるように指定します。 -gスイッチを複数記述することで、複数の既存のロールを指定できます。

-i
--inherit

The new role will automatically inherit privileges of roles it is a member of. This is the default. 新しいロールは自動的にメンバとして属するロールの権限を継承します。 これがデフォルトです。

-I
--no-inherit

The new role will not automatically inherit privileges of roles it is a member of. 新しいロールは自動的にメンバとして属するロールの権限を継承しません。

--interactive

Prompt for the user name if none is specified on the command line, and also prompt for whichever of the options <option>-d</option>/<option>-D</option>, <option>-r</option>/<option>-R</option>, <option>-s</option>/<option>-S</option> is not specified on the command line. (This was the default behavior up to PostgreSQL 9.1.) ユーザ名がコマンドラインで指定されない場合、ユーザ名の入力を促し、更に -d/-D-r/-R-s/-Sオプションがコマンドラインで指定されない場合にはどちらにするか入力を促します。 (これはPostgreSQL 9.1までのデフォルトの動作でした。)

-l
--login

The new user will be allowed to log in (that is, the user name can be used as the initial session user identifier). This is the default. 新しいユーザに対してログインを許可します。 (つまり、このユーザ名をセッション起動時のユーザ識別子として使用することができます。) これがデフォルトです。

-L
--no-login

The new user will not be allowed to log in. (A role without login privilege is still useful as a means of managing database permissions.) 新しいユーザに対してログインを禁止します。 (ログイン権限を持たないロールはデータベース権限管理という面で有意です。)

-m role
--with-member=role

Specifies an existing role that will be automatically added as a member of the new role. Multiple existing roles can be specified by writing multiple <option>-m</option> switches. 新しいロールのメンバとして自動的に追加される既存のロールを指定します。 -mスイッチを複数記述することで、複数の既存のロールを指定できます。

-P
--pwprompt

If given, <application>createuser</application> will issue a prompt for the password of the new user. This is not necessary if you do not plan on using password authentication. このオプションが指定されると、createuserは新しいユーザのパスワードのプロンプトを表示します。 もしパスワード認証を使う予定がなければ、これは必要ありません。

-r
--createrole

The new user will be allowed to create, alter, drop, comment on, change the security label for other roles; that is, this user will have <literal>CREATEROLE</literal> privilege. See <xref linkend="role-creation"/> for more details about what capabilities are conferred by this privilege. 他のロールの作成、変更、削除、コメント付与、およびセキュリティラベルの変更を新しいユーザに対して許可します。つまり、このユーザはCREATEROLE権限を持つことになります。 この権限によって付与される機能の詳細については、ロールの作成を参照してください。

-R
--no-createrole

The new user will not be allowed to create new roles. This is the default. 新しいユーザに対して新しいロールの作成を禁止します。 これはデフォルトです。

-s
--superuser

The new user will be a superuser. 新しいユーザはスーパーユーザになります。

-S
--no-superuser

The new user will not be a superuser. This is the default. 新しいユーザはスーパーユーザにはなりません。 これはデフォルトです。

-v timestamp
--valid-until=timestamp

Set a date and time after which the role's password is no longer valid. The default is to set no password expiry date. ロールのパスワードが有効でなくなる日時を設定します。 デフォルトはパスワードの有効期限を設定しません。

-V
--version

Print the <application>createuser</application> version and exit. createuserのバージョンを表示し、終了します。

--bypassrls

The new user will bypass every row-level security (RLS) policy. 新しいユーザは、すべての行レベルセキュリティ(RLS)ポリシーをバイパスします。

--no-bypassrls

The new user will not bypass row-level security (RLS) policies. This is the default. 新しいユーザは、行レベルセキュリティ(RLS)ポリシーをバイパスしません。 これがデフォルトです。

--replication

The new user will have the <literal>REPLICATION</literal> privilege, which is described more fully in the documentation for <xref linkend="sql-createrole"/>. 新しいユーザはREPLICATION権限を持ちます。 この権限についてはCREATE ROLEの文書で詳しく説明します。

--no-replication

The new user will not have the <literal>REPLICATION</literal> privilege, which is described more fully in the documentation for <xref linkend="sql-createrole"/>. This is the default. 新しいユーザはREPLICATION権限を持ちません。 この権限についてはCREATE ROLEの文書で詳しく説明します。 これがデフォルトです。

-?
--help

Show help about <application>createuser</application> command line arguments, and exit. createuserのコマンドライン引数の使用方法を表示し、終了します。

<application>createuser</application> also accepts the following command-line arguments for connection parameters: createuserは、以下のコマンドライン引数も接続パラメータとして受け付けます。

-h host
--host=host

Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket. サーバが稼働しているマシンのホスト名を指定します。 この値がスラッシュから始まる場合、Unixドメインソケット用のディレクトリとして使用されます。

-p port
--port=port

Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. サーバが接続を監視するTCPポートもしくはUnixドメインソケットファイルの拡張子を指定します。

-U username
--username=username

User name to connect as (not the user name to create). 接続に使用するユーザ名です(作成するユーザの名前ではありません)。

-w
--no-password

Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a <filename>.pgpass</filename> file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. パスワードの入力を促しません。 サーバがパスワード認証を必要とし、かつ、.pgpassファイルなどの他の方法が利用できない場合、接続試行は失敗します。 バッチジョブやスクリプトなどパスワードを入力するユーザが存在しない場合にこのオプションは有用かもしれません。

-W
--password

Force <application>createuser</application> to prompt for a password (for connecting to the server, not for the password of the new user). createuserは強制的にパスワード入力を促します。 (新しいユーザのパスワードではなく、サーバに接続するためのパスワードです)。

This option is never essential, since <application>createuser</application> will automatically prompt for a password if the server demands password authentication. However, <application>createuser</application> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <option>-W</option> to avoid the extra connection attempt. サーバがパスワード認証を要求する場合createuserは自動的にパスワード入力を促しますので、これが重要になることはありません。 しかし、createuserは、サーバにパスワードが必要かどうかを判断するための接続試行を無駄に行います。 こうした余計な接続試行を防ぐために-Wの入力が有意となる場合もあります。

環境

<title>Environment</title>
PGHOST
PGPORT
PGUSER

Default connection parameters デフォルトの接続パラメータです。

PG_COLOR

Specifies whether to use color in diagnostic messages. Possible values are <literal>always</literal>, <literal>auto</literal> and <literal>never</literal>. 診断メッセージで色を使うかどうかを指定します。 可能な値はalwaysautoneverです。

This utility, like most other <productname>PostgreSQL</productname> utilities, also uses the environment variables supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>). また、このユーティリティは、他のほとんどのPostgreSQLユーティリティと同様、libpqでサポートされる環境変数を使用します(34.15を参照してください)。

診断

<title>Diagnostics</title>

In case of difficulty, see <xref linkend="sql-createrole"/> and <xref linkend="app-psql"/> for discussions of potential problems and error messages. The database server must be running at the targeted host. Also, any default connection settings and environment variables used by the <application>libpq</application> front-end library will apply. 問題が発生した場合、考えられる原因とエラーメッセージの説明については、CREATE ROLEpsqlを参照してください。 データベースサーバは対象ホストで稼働していなければなりません。 また、libpqフロントエンドライブラリで使用される、全ての接続設定と環境変数が適用されることを覚えておいてください。

<title>Examples</title>

To create a user <literal>joe</literal> on the default database server: デフォルトデータベースサーバ上にjoeというユーザを作成します。

$ createuser joe

To create a user <literal>joe</literal> on the default database server with prompting for some additional attributes: デフォルトデータベースサーバ上にjoeというユーザを一部の属性入力が促されるように作成します。

$ createuser --interactive joe
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n

To create the same user <literal>joe</literal> using the server on host <literal>eden</literal>, port 5000, with attributes explicitly specified, taking a look at the underlying command: ホストedenのポート番号5000上のサーバを使って上記と同じjoeというユーザを属性を明示的に指定して作成し、背後で実行される問い合わせを表示します。

$ createuser -h eden -p 5000 -S -D -R -e joe
CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;

To create the user <literal>joe</literal> as a superuser, and assign a password immediately: joeというユーザをスーパーユーザとして作成します。作成時にパスワードを割り当てます。

$ createuser -P -s -e joe
Enter password for new role: xyzzy
Enter it again: xyzzy
CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;

In the above example, the new password isn't actually echoed when typed, but we show what was typed for clarity. As you see, the password is encrypted before it is sent to the client. 上の例で、実際には入力した新しいパスワードは画面上に表示されませんが、分かりやすくするために記載しています。 上記の通りこのパスワードはクライアントに送信される前に暗号化されます。

関連項目

<title>See Also</title> dropuser, CREATE ROLE, createrole_self_grant