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

initdb

initdb <refpurpose>create a new <productname>PostgreSQL</productname> database cluster</refpurpose> PostgreSQLのデータベースクラスタを新しく作成する

概要

initdb [option...] [ --pgdata | -D ] directory

説明

<title>Description</title>

<command>initdb</command> creates a new <productname>PostgreSQL</productname> <glossterm linkend="glossary-db-cluster">database cluster</glossterm>. initdbPostgreSQLデータベースクラスタを新しく作成します。

Creating a database cluster consists of creating the <glossterm linkend="glossary-data-directory">directories</glossterm> in which the cluster data will live, generating the shared catalog tables (tables that belong to the whole cluster rather than to any particular database), and creating the <literal>postgres</literal>, <literal>template1</literal>, and <literal>template0</literal> databases. The <literal>postgres</literal> database is a default database meant for use by users, utilities and third party applications. <literal>template1</literal> and <literal>template0</literal> are meant as source databases to be copied by later <command>CREATE DATABASE</command> commands. <literal>template0</literal> should never be modified, but you can add objects to <literal>template1</literal>, which by default will be copied into databases created later. See <xref linkend="manage-ag-templatedbs"/> for more details. データベースクラスタの作成には、クラスタのデータを保存するディレクトリの作成、共有カタログテーブル(特定のデータベースではなく、クラスタ全体に所属するテーブル)の生成、そしてpostgresデータベース、template1データベース、template0データベースの作成といった作業が含まれます。 postgresデータベースは、ユーザ、ユーティリティ、サードパーティ製アプリケーションのデフォルトデータベースとしての使用を意図したものです。 template1template0は、後のCREATE DATABASEコマンドでコピーされる元のデータベースを意図しています。 新しいデータベースを作成する際は、template1データベースの全ての内容がコピーされます。 template0を修正してはいけませんが、template1にはオブジェクトを追加でき、そのオブジェクトは後に生成した各データベースにデフォルトでコピーされます。 より詳細については23.3を参照してください。

Although <command>initdb</command> will attempt to create the specified data directory, it might not have permission if the parent directory of the desired data directory is root-owned. To initialize in such a setup, create an empty data directory as root, then use <command>chown</command> to assign ownership of that directory to the database user account, then <command>su</command> to become the database user to run <command>initdb</command>. initdbは指定されたデータディレクトリを作成しようと試みますが、そのデータディレクトリの親ディレクトリの所有者がrootであるなど、権限がないことがあります。 このような場合、まず、空のデータディレクトリをrootで作成し、chownを使ってそのディレクトリの所有権限をデータベースのユーザに変えてください。 次にsuを使ってデータベースユーザとなり、initdbを実行します。

<command>initdb</command> must be run as the user that will own the server process, because the server needs to have access to the files and directories that <command>initdb</command> creates. Since the server cannot be run as root, you must not run <command>initdb</command> as root either. (It will in fact refuse to do so.) initdbは、サーバプロセスの所有者となるユーザによって実行されなければなりません。 initdbによって作成されるファイルやディレクトリにサーバがアクセスできる必要があるからです。 サーバをrootとして実行することはできませんので、rootでinitdbを実行してはいけません (実際には、実行しようとしても拒否されます)。

For security reasons the new cluster created by <command>initdb</command> will only be accessible by the cluster owner by default. The <option>&#45;-allow-group-access</option> option allows any user in the same group as the cluster owner to read files in the cluster. This is useful for performing backups as a non-privileged user. セキュリティ上の理由から、デフォルトではinitdbにより作られた新しいクラスタはクラスタの所有者だけがアクセスできます。 --allow-group-accessにより、クラスタの所有者と同じグループのユーザがクラスタ内のファイルを読めるようになります。 これは非特権ユーザとしてバックアップを実行するのに有用です。

<command>initdb</command> initializes the database cluster's default locale and character set encoding. These can also be set separately for each database when it is created. <command>initdb</command> determines those settings for the template databases, which will serve as the default for all other databases. initdbは、データベースクラスタのデフォルトのロケールと文字セット符号化方式を初期化します。 これらは、データベースの作成時にデータベースごとに個別に設定することもできます 。 initdbはテンプレートデータベースのこれらの設定を決定します。この設定が他のすべてのデータベースのデフォルトとして提供されます。

By default, <command>initdb</command> uses the locale provider <literal>libc</literal> (see <xref linkend="locale-providers"/>). The <literal>libc</literal> locale provider takes the locale settings from the environment, and determines the encoding from the locale settings. デフォルトでは、initdbはロケールプロバイダlibcを使用します(24.1.4を参照してください)。 libcロケールプロバイダは環境からロケール設定を取得し、ロケール設定からエンコーディングを決定します。

To choose a different locale for the cluster, use the option <option>&#45;-locale</option>. There are also individual options <option>&#45;-lc-*</option> and <option>&#45;-icu-locale</option> (see below) to set values for the individual locale categories. Note that inconsistent settings for different locale categories can give nonsensical results, so this should be used with care. クラスタに別のロケールを選択するには、--localeオプションを使用します。 また、個々のロケールカテゴリに値を設定するための個々のオプション--lc-*--icu-localeもあります(下記参照)。 異なるロケールカテゴリの設定に一貫性がないと、無意味な結果になることがあるので、注意して使用してください。

Alternatively, <command>initdb</command> can use the ICU library to provide locale services by specifying <literal>&#45;-locale-provider=icu</literal>. The server must be built with ICU support. To choose the specific ICU locale ID to apply, use the option <option>&#45;-icu-locale</option>. Note that for implementation reasons and to support legacy code, <command>initdb</command> will still select and initialize libc locale settings when the ICU locale provider is used. また、--locale-provider=icuと指定することで、initdbはICUライブラリを使用してロケールサービスを提供することもできます。 サーバがICUをサポートするよう構築されていることが必要です。 適用する特定のICUロケールIDを選択するには、--icu-localeオプションを使用します。 実装上の理由とレガシーコードをサポートするために、initdbはICUロケールプロバイダが使用されている場合でもlibcロケール設定を選択し初期化することに注意してください。

When <command>initdb</command> runs, it will print out the locale settings it has chosen. If you have complex requirements or specified multiple options, it is advisable to check that the result matches what was intended. initdbを実行すると、選択したロケール設定を出力します。 複雑な要件がある場合や、複数のオプションを指定した場合は、結果が意図したものと一致するのを確認することをお勧めします。

More details about locale settings can be found in <xref linkend="locale"/>. ロケール設定の詳細については24.1を参照してください。

To alter the default encoding, use the <option>&#45;-encoding</option>. More details can be found in <xref linkend="multibyte"/>. デフォルトの符号化方式を変更するには、--encodingオプションを使用します。 詳細は24.3に記載しています。

オプション

<title>Options</title>

-A authmethod
--auth=authmethod #

This option specifies the default authentication method for local users used in <filename>pg_hba.conf</filename> (<literal>host</literal> and <literal>local</literal> lines). See <xref linkend="auth-pg-hba-conf"/> for an overview of valid values. このオプションは、pg_hba.confで使用されるローカルユーザーのデフォルトの認証方法(hostおよびlocal行)を指定します。 有効な値の概要については21.1を参照してください。

<command>initdb</command> will prepopulate <filename>pg_hba.conf</filename> entries using the specified authentication method for non-replication as well as replication connections. initdbは、非レプリケーションおよびレプリケーションの接続について、指定の認証方式を使うエントリをpg_hba.confに事前に作成します。

Do not use <literal>trust</literal> unless you trust all local users on your system. <literal>trust</literal> is the default for ease of installation. システムのすべてのローカルユーザが信頼できるわけではない場合は、trustを使用しないでください。 インストールを簡単にするためにtrustがデフォルトになっています。

--auth-host=authmethod #

This option specifies the authentication method for local users via TCP/IP connections used in <filename>pg_hba.conf</filename> (<literal>host</literal> lines). このオプションはpg_hba.confにてTCP/IP接続経由のローカルユーザ用に使用される認証方法(host行)を指定します。

--auth-local=authmethod #

This option specifies the authentication method for local users via Unix-domain socket connections used in <filename>pg_hba.conf</filename> (<literal>local</literal> lines). このオプションはpg_hba.confにてUnixドメインソケット接続経由のローカルユーザ用に使用される認証方法(local行)を指定します。

-D directory
--pgdata=directory #

This option specifies the directory where the database cluster should be stored. This is the only information required by <command>initdb</command>, but you can avoid writing it by setting the <envar>PGDATA</envar> environment variable, which can be convenient since the database server (<command>postgres</command>) can find the data directory later by the same variable. このオプションは、データベースクラスタを格納すべきディレクトリを指定します。 initdbが必要とする情報はこれだけですが、環境変数PGDATAを設定しておけば、このオプションの指定を省略できます。 この方法は、後に同じ変数を使用してデータベースサーバ(postgres)がデータディレクトリを参照できるので、便利です。

-E encoding
--encoding=encoding #

Selects the encoding of the template databases. This will also be the default encoding of any database you create later, unless you override it then. The character sets supported by the <productname>PostgreSQL</productname> server are described in <xref linkend="multibyte-charset-supported"/>. テンプレートデータベースの符号化方式を選択します。 これが今後作成されるすべてのデータベースについてのデフォルト符号化方式となりますが、作成時に上書きすることもできます。 PostgreSQLサーバでサポートされる文字セットについては、24.3.1を参照してください。

By default, the template database encoding is derived from the locale. If <xref linkend="app-initdb-option-no-locale"/> is specified (or equivalently, if the locale is <literal>C</literal> or <literal>POSIX</literal>), then the default is <literal>UTF8</literal> for the ICU provider and <literal>SQL_ASCII</literal> for the <literal>libc</literal> provider. デフォルトでは、テンプレートデータベースの符号化方式はロケールに由来します。 --no-localeが指定されている場合(または同等に、ロケールがCまたはPOSIXの場合)、デフォルトはICUプロバイダーではUTF8libcプロバイダーではSQL_ASCIIになります。

-g
--allow-group-access #

Allows users in the same group as the cluster owner to read all cluster files created by <command>initdb</command>. This option is ignored on <productname>Windows</productname> as it does not support <acronym>POSIX</acronym>-style group permissions. クラスタの所有者と同じグループのユーザが、initdbにより作られたクラスタファイルすべてを読むことを許可します。 WindowsではPOSIX形式のグループパーミッションをサポートしませんので、このオプションは無視されます。

--icu-locale=locale #

Specifies the ICU locale when the ICU provider is used. Locale support is described in <xref linkend="locale"/>. ICUロケールプロバイダを使用する場合に、ICUロケールを指定します。 ロケールサポートは24.1に記載されています。

--icu-rules=rules #

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

-k
--data-checksums #

Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent. Enabling checksums may incur a noticeable performance penalty. If set, checksums are calculated for all objects, in all databases. All checksum failures will be reported in the <link linkend="monitoring-pg-stat-database-view"> <structname>pg_stat_database</structname></link> view. See <xref linkend="checksums" /> for details. I/Oシステムによる破損検知を補助するために、データページにおいてチェックサムを使用します。 これがないと警告もされません。 チェックサムを有効にすると、認知できる程度の性能低下が発生する可能性があります。 設定した場合、すべてのデータベースにおいて、すべてのオブジェクトに対してチェックサムが計算されます。 チェックサムの失敗はすべてpg_stat_databaseビューで報告されます。 詳細については30.2を参照してください。

--locale=locale #

Sets the default locale for the database cluster. If this option is not specified, the locale is inherited from the environment that <command>initdb</command> runs in. Locale support is described in <xref linkend="locale"/>. データベースクラスタ用のデフォルトのロケールを設定します。 このオプションを指定しない場合は、initdbを実行している環境のロケールが継承されます。 ロケールサポートについては24.1で説明します。

--lc-collate=locale
--lc-ctype=locale
--lc-messages=locale
--lc-monetary=locale
--lc-numeric=locale
--lc-time=locale #

Like <option>&#45;-locale</option>, but only sets the locale in the specified category. --localeと似ていますが、指定したカテゴリのロケールのみを設定します。

--no-locale #

Equivalent to <option>&#45;-locale=C</option>. --locale=Cと同じです。

--locale-provider={libc|icu} #

This option sets the locale provider for databases created in the new cluster. It can be overridden in the <command>CREATE DATABASE</command> command when new databases are subsequently created. The default is <literal>libc</literal> (see <xref linkend="locale-providers"/>). このオプションは、新しいクラスタで作成されたデータベースのロケールプロバイダを設定します。 新しいデータベースが後で作成されるときに、CREATE DATABASEコマンドで上書きできます。 デフォルトはlibcです(24.1.4を参照してください)。

-N
--no-sync #

By default, <command>initdb</command> will wait for all files to be written safely to disk. This option causes <command>initdb</command> to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt. Generally, this option is useful for testing, but should not be used when creating a production installation. デフォルトではinitdbはすべてのファイルが安全にディスクに書き出されるまで待機します。 このオプションを使うとinitdbは待機せずに返るようになり、より高速になりますが、後でオペレーティングシステムがクラッシュした場合にデータディレクトリが破損状態になってしまう可能性があります。 通常、このオプションは試験用では有用ですが、実用のインストレーションを作成する際に使用すべきではありません。

--no-instructions #

By default, <command>initdb</command> will write instructions for how to start the cluster at the end of its output. This option causes those instructions to be left out. This is primarily intended for use by tools that wrap <command>initdb</command> in platform-specific behavior, where those instructions are likely to be incorrect. デフォルトではinitdbは出力の最後にクラスタを起動する手順を表示します。 このオプションを使うと、これらの手順が省略されます。 これは主にinitdbをプラットフォーム固有の動作でラップするツールで、これらの手順が間違っている可能性がある場合に使用することを目的としています。

--pwfile=filename #

Makes <command>initdb</command> read the bootstrap superuser's password from a file. The first line of the file is taken as the password. initdbはブートストラップスーパーユーザのパスワードをこのファイルから読み取ります。 このファイルの最初の行がパスワードとして解釈されます。

-S
--sync-only #

Safely write all database files to disk and exit. This does not perform any of the normal <application>initdb</application> operations. Generally, this option is useful for ensuring reliable recovery after changing <xref linkend="guc-fsync"/> from <literal>off</literal> to <literal>on</literal>. すべてのデータベースファイルを安全にディスクに書き出し、終了します。 これは通常のinitdbの操作をまったく行いません。 通常、このオプションは、fsyncoffからonに変更した後の信頼できるリカバリを確実にするのに有用です。

-T config
--text-search-config=config #

Sets the default text search configuration. See <xref linkend="guc-default-text-search-config"/> for further information. デフォルトの全文検索設定を設定します。 詳細についてはdefault_text_search_configを参照してください。

-U username
--username=username #

Selects the user name of the <glossterm linkend="glossary-bootstrap-superuser">bootstrap superuser</glossterm>. This defaults to the name of the <glossterm linkend="glossary-cluster-owner">cluster owner</glossterm>. ブートストラップスーパーユーザのユーザ名を選択します。 デフォルトはクラスタ所有者の名前です。

-W
--pwprompt #

Makes <command>initdb</command> prompt for a password to give the bootstrap superuser. If you don't plan on using password authentication, this is not important. Otherwise you won't be able to use password authentication until you have a password set up. initdbにブートストラップスーパーユーザ権限を与えるためのパスワード入力のプロンプトを表示させます。 パスワード認証を行うつもりがない場合は必要ありません。 このオプションを指定しても、パスワードの設定を行わない限りパスワード認証は行われません。

-X directory
--waldir=directory #

This option specifies the directory where the write-ahead log should be stored. このオプションは先行書き込みログの格納ディレクトリを指定します。

--wal-segsize=size #

Set the <firstterm>WAL segment size</firstterm>, in megabytes. This is the size of each individual file in the WAL log. The default size is 16 megabytes. The value must be a power of 2 between 1 and 1024 (megabytes). This option can only be set during initialization, and cannot be changed later. WALセグメントサイズをメガバイト単位で設定します。 これはWALログの個々のファイルの大きさです。 デフォルトの大きさは16メガバイトです。 値は1から1024の間の2の冪でなければなりません。 このオプションは初期化の際にのみ設定することができ、後で変更することはできません。

It may be useful to adjust this size to control the granularity of WAL log shipping or archiving. Also, in databases with a high volume of WAL, the sheer number of WAL files per directory can become a performance and management problem. Increasing the WAL file size will reduce the number of WAL files. WALログのシッピングやアーカイブの粒度を制御するために、この大きさを調整することは有用でしょう。 また、大量のWALのあるデータベースでは、ディレクトリ当たりのWALファイルの数だけでパフォーマンスや管理の問題となり得ます。 WALファイルの大きさを増やせば、WALファイルの数は減るでしょう。

Other, less commonly used, options are also available: この他にも、使用頻度は下がりますが、下記のオプションが使用可能です。

-c name=value
--set name=value #

Forcibly set the server parameter <replaceable>name</replaceable> to <replaceable>value</replaceable> during <command>initdb</command>, and also install that setting in the generated <filename>postgresql.conf</filename> file, so that it will apply during future server runs. This option can be given more than once to set several parameters. It is primarily useful when the environment is such that the server will not start at all using the default parameters. initdbの間、サーバのパラメータnameを強制的にvalueに設定し、将来のサーバ実行の間も適用されるよう、その設定を生成されたpostgresql.confファイルにも書き込みます。 このオプションは複数のパラメータを設定するために2回以上指定できます。 デフォルトのパラメータを利用するとサーバ全く起動しないような環境で、とりわけ有用でしょう。

-d
--debug #

Print debugging output from the bootstrap backend and a few other messages of lesser interest for the general public. The bootstrap backend is the program <command>initdb</command> uses to create the catalog tables. This option generates a tremendous amount of extremely boring output. ブートストラップバックエンドからのデバッグ情報と、一般の利用者にはおそらく不要なその他の情報を出力します。 ブートストラップバックエンドとはinitdbがカタログテーブルを作成する際に使用するプログラムです。 このオプションはうんざりするようなログを大量に出力します。

--discard-caches #

Run the bootstrap backend with the <literal>debug_discard_caches=1</literal> option. This takes a very long time and is only of use for deep debugging. debug_discard_caches=1オプションをつけてブートストラップバックエンドを実行します。 これは非常に長い時間がかかるため、難解なデバッグでのみ使用されます。

-L directory #

Specifies where <command>initdb</command> should find its input files to initialize the database cluster. This is normally not necessary. You will be told if you need to specify their location explicitly. データベースクラスタを初期化する際に、initdbが参照すべき入力ファイルを指定します。 これは通常必要ありません。 明示的に指定する必要がある場合は、その時に指定するよう要求されます。

-n
--no-clean #

By default, when <command>initdb</command> determines that an error prevented it from completely creating the database cluster, it removes any files it might have created before discovering that it cannot finish the job. This option inhibits tidying-up and is thus useful for debugging. デフォルトでは、initdbを実行中にエラーが発生し、データベースクラスタを完成できなかった場合に、そのエラーが発生する前に作成された全てのファイルを削除します。 このオプションを指定すると、これらのファイルが削除しないで残されるので、デバッグの際にはとても便利です。

Other options: その他のオプションを以下に示します。

-V
--version #

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

-?
--help #

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

環境

<title>Environment</title>
PGDATA #

Specifies the directory where the database cluster is to be stored; can be overridden using the <option>-D</option> option. データベースクラスタを保存するディレクトリを指定します。 -Dオプションを使用して上書きすることができます。

PG_COLOR #

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

TZ #

Specifies the default time zone of the created database cluster. The value should be a full time zone name (see <xref linkend="datatype-timezones"/>). 作成されるデータベースクラスタのデフォルトの時間帯を指定します。 値は完全な時間帯の名前で指定することが望ましいです(8.5.3参照)。

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>Notes</title>

<command>initdb</command> can also be invoked via <command>pg_ctl initdb</command>. initdbpg_ctl initdb経由でも呼び出すことができます。

関連項目

<title>See Also</title> pg_ctl, postgres, 21.1