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

createdb

createdb <refpurpose>create a new <productname>PostgreSQL</productname> database</refpurpose> — 新しいPostgreSQLデータベースを作成する

概要

createdb [connection-option...] [option...] [dbname [description]]

説明

<title>Description</title>

<application>createdb</application> creates a new <productname>PostgreSQL</productname> database. createdbは、新しいPostgreSQLデータベースを作成します。

Normally, the database user who executes this command becomes the owner of the new database. However, a different owner can be specified via the <option>-O</option> option, if the executing user has appropriate privileges. 通常、このコマンドを実行したデータベースユーザが、新しいデータベースの所有者になります。 ただし、コマンドを実行するユーザが適切な権限を持っている場合、-Oオプションを使用して別のユーザを所有者に指定できます。

<application>createdb</application> is a wrapper around the <acronym>SQL</acronym> command <link linkend="sql-createdatabase"><command>CREATE DATABASE</command></link>. There is no effective difference between creating databases via this utility and via other methods for accessing the server. createdbCREATE DATABASEというSQLコマンドのラッパーです。 したがって、このユーティリティでデータベースを作成しても、これ以外の方法でサーバにアクセスしてデータベースを作成しても何も違いはありません。

オプション

<title>Options</title>

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

dbname

Specifies the name of the database to be created. The name must be unique among all <productname>PostgreSQL</productname> databases in this cluster. The default is to create a database with the same name as the current system user. 作成するデータベースの名前を指定します。 この名前はクラスタ内の全てのPostgreSQLデータベースの中で一意でなければなりません。 デフォルトでは、現在のシステムユーザと同じ名前でデータベースを作成します。

description

Specifies a comment to be associated with the newly created database. 新しく作成されるデータベースに関連付けるコメントを指定します。

-D tablespace
--tablespace=tablespace

Specifies the default tablespace for the database. (This name is processed as a double-quoted identifier.) データベース用のデフォルトのテーブル空間を指定します。 (この名前は二重引用符で囲まれた識別子として処理されます。)

-e
--echo

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

-E encoding
--encoding=encoding

Specifies the character encoding scheme to be used in this database. The character sets supported by the <productname>PostgreSQL</productname> server are described in <xref linkend="multibyte-charset-supported"/>. このデータベース内で使用する文字符号化方式を指定します。 PostgreSQLサーバでサポートされる文字セットについては24.3.1で説明します。

-l locale
--locale=locale

Specifies the locale to be used in this database. This is equivalent to specifying <option>&#45;-lc-collate</option>, <option>&#45;-lc-ctype</option>, and <option>&#45;-icu-locale</option> to the same value. Some locales are only valid for ICU and must be set with <option>&#45;-icu-locale</option>. このデータベースで使用されるロケールを指定します。 これは、--lc-collate--lc-ctype、および--icu-localeを同じ値に指定することと等価です。 一部のロケールはICUに対してのみ有効であり、--icu-localeで設定することが必要です。

--lc-collate=locale

Specifies the LC_COLLATE setting to be used in this database. このデータベースで使用されるLC_COLLATE設定を指定します。

--lc-ctype=locale

Specifies the LC_CTYPE setting to be used in this database. このデータベースで使用されるLC_CTYPE設定を指定します。

--icu-locale=locale

Specifies the ICU locale ID to be used in this database, if the ICU locale provider is selected. ICUロケールプロバイダを選択した場合に、このデータベースで使用されるICUロケールIDを指定します。

--icu-rules=rules

Specifies additional collation rules to customize the behavior of the default collation of this database. This is supported for ICU only. このデータベースのデフォルトの照合の動作をカスタマイズするための追加の照合規則を指定します。 これはICUのみでサポートされています。

--locale-provider={libc|icu}

Specifies the locale provider for the database's default collation. データベースのデフォルトの照合順序のロケールプロバイダを指定します。

-O owner
--owner=owner

Specifies the database user who will own the new database. (This name is processed as a double-quoted identifier.) 新しいデータベースの所有者となるデータベースユーザを指定します。 (この名前は二重引用符で囲まれた識別子として処理されます。)

-S template
--strategy=strategy

Specifies the database creation strategy. See <xref linkend="create-database-strategy" /> for more details. データベース作成手法を指定します。 詳細はCREATE DATABASE STRATEGYを参照してください。

-T template
--template=template

Specifies the template database from which to build this database. (This name is processed as a double-quoted identifier.) このデータベースの構築に使用するテンプレートデータベースを指定します。 (この名前は二重引用符で囲まれた識別子として処理されます。)

-V
--version

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

-?
--help

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

The options <option>-D</option>, <option>-l</option>, <option>-E</option>, <option>-O</option>, and <option>-T</option> correspond to options of the underlying SQL command <link linkend="sql-createdatabase"><command>CREATE DATABASE</command></link>; see there for more information about them. オプション-D-l-E-O、および-Tは、基盤となるCREATE DATABASEというSQLコマンドのオプションにそれぞれ対応しています。 詳細はそちらを参照してください。

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

-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 the 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. 接続に使用するユーザ名を指定します。

-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>createdb</application> to prompt for a password before connecting to a database. データベースに接続する前に、createdbは強制的にパスワード入力を促します。

This option is never essential, since <application>createdb</application> will automatically prompt for a password if the server demands password authentication. However, <application>createdb</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. サーバがパスワード認証を要求する場合createdbは自動的にパスワード入力を促しますので、これが重要になることはありません。 しかし、createdbは、サーバにパスワードが必要かどうかを判断するための接続試行を無駄に行います。 こうした余計な接続試行を防ぐために-Wの入力が有意となる場合もあります。

--maintenance-db=dbname

Specifies the name of the database to connect to when creating the new database. If not specified, the <literal>postgres</literal> database will be used; if that does not exist (or if it is the name of the new database being created), <literal>template1</literal> will be used. This can be a <link linkend="libpq-connstring">connection string</link>. If so, connection string parameters will override any conflicting command line options. 新しいデータベースを作成する時の接続先となるデータベースの名前を指定します。 指定がなければ、postgresデータベースが使用されます。 もし存在しなければ(またはこれが作成しようとしているデータベースの名前であれば)template1が使用されます。 これは接続文字列でも構いません。 その場合、接続文字列パラメータは衝突するコマンドラインオプションよりも優先します。

環境

<title>Environment</title>
PGDATABASE

If set, the name of the database to create, unless overridden on the command line. この値が設定されている場合、コマンドラインで上書きされなければ、設定された値が作成するデータベースの名前になります。

PGHOST
PGPORT
PGUSER

Default connection parameters. <envar>PGUSER</envar> also determines the name of the database to create, if it is not specified on the command line or by <envar>PGDATABASE</envar>. デフォルトの接続パラメータです。 コマンドラインでもPGDATABASEでも名前が指定されていない場合は、PGUSERが作成するデータベースの名前にもなります。

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-createdatabase"/> 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 DATABASEpsqlを参照してください。 データベースサーバは対象ホストで稼働していなければなりません。 また、libpqフロントエンドライブラリで使用される、全てのデフォルトの接続設定と環境変数が適用されることも覚えておいてください。

<title>Examples</title>

To create the database <literal>demo</literal> using the default database server: デフォルトのデータベースサーバを使用してdemoデータベースを作成します。

$ createdb demo

To create the database <literal>demo</literal> using the server on host <literal>eden</literal>, port 5000, using the <literal>template0</literal> template database, here is the command-line command and the underlying SQL command: edenホスト上のポート番号5000のサーバを使用し、template0テンプレートデータベースを使用してdemoデータベースを作成する場合の、コマンド行から入力するコマンドと背後で実行されるSQLコマンドを示します。

$ createdb -p 5000 -h eden -T template0 -e demo
CREATE DATABASE demo TEMPLATE template0;

関連項目

<title>See Also</title> dropdb, CREATE DATABASE