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

pg_restore

pg_restore — restore a <productname>PostgreSQL</productname> database from an archive file created by <application>pg_dump</application> pg_dumpによって作成されたアーカイブファイルからPostgreSQLデータベースをリストアする

概要

pg_restore [connection-option...] [option...] [filename]

説明

<title>Description</title>

<application>pg_restore</application> is a utility for restoring a <productname>PostgreSQL</productname> database from an archive created by <xref linkend="app-pgdump"/> in one of the non-plain-text formats. It will issue the commands necessary to reconstruct the database to the state it was in at the time it was saved. The archive files also allow <application>pg_restore</application> to be selective about what is restored, or even to reorder the items prior to being restored. The archive files are designed to be portable across architectures. pg_restoreは、pg_dumpによって作成された平文形式以外のアーカイブファイルを使って、PostgreSQLデータベースをリストアするためのユーティリティです。 このコマンドは、データベースを再構成して保存された時点の状態にするために必要なコマンドを発行します。 また、pg_restoreは、アーカイブファイルから、リストアする内容を選択したり、リストアする前にアイテムの並べ替えを行うこともできます。 アーカイブファイルはアーキテクチャに依存しない移植性を持つように設計されています。

<application>pg_restore</application> can operate in two modes. If a database name is specified, <application>pg_restore</application> connects to that database and restores archive contents directly into the database. Otherwise, a script containing the SQL commands necessary to rebuild the database is created and written to a file or standard output. This script output is equivalent to the plain text output format of <application>pg_dump</application>. Some of the options controlling the output are therefore analogous to <application>pg_dump</application> options. pg_restoreの操作には2つのモードがあります。 データベース名が指定された場合、pg_restoreはそのデータベースに接続し、アーカイブを直接そのデータベースにリストアします。 データベース名が指定されなかった場合は、データベースを再構築するために必要となるSQLコマンドが含まれたスクリプトが作成されます(ファイルもしくは標準出力に書き出されます)。 このスクリプトの出力はpg_dumpの平文形式の出力と同じです。 従って、出力を制御するオプションの中には、pg_dumpのオプションに類似したものがあります。

Obviously, <application>pg_restore</application> cannot restore information that is not present in the archive file. For instance, if the archive was made using the <quote>dump data as <command>INSERT</command> commands</quote> option, <application>pg_restore</application> will not be able to load the data using <command>COPY</command> statements. 当然ながら、pg_restoreによって、アーカイブファイルに存在しない情報をリストアすることはできません。 例えば、アーカイブがINSERTコマンドの形式でデータダンプを行うオプションを使用して作成されたものであった場合、pg_restoreCOPY文を使用してデータを読み込むことはできません。

オプション

<title>Options</title>

<application>pg_restore</application> accepts the following command line arguments. pg_restoreは以下のコマンドライン引数を受け付けます。

filename

Specifies the location of the archive file (or directory, for a directory-format archive) to be restored. If not specified, the standard input is used. リストアするアーカイブファイル(ディレクトリ書式アーカイブの場合はディレクトリ)の場所を指定します。 指定がない場合は、標準入力が使用されます。

-a
--data-only

Restore only the data, not the schema (data definitions). Table data, large objects, and sequence values are restored, if present in the archive. データのみをリストアし、スキーマ(データ定義)はリストアしません。 アーカイブ内にある、テーブルデータ、ラージオブジェクト、シーケンス値がリストアされます。

This option is similar to, but for historical reasons not identical to, specifying <option>&#45;-section=data</option>. このオプションは--section=dataを指定することと似ていますが、歴史的な理由により同一ではありません。

-c
--clean

Clean (drop) database objects before recreating them. (Unless <option>&#45;-if-exists</option> is used, this might generate some harmless error messages, if any objects were not present in the destination database.) 再作成前にデータベースオブジェクトを整理(削除)します。 (--if-existsが使われなければ、対象のデータベースの中にオブジェクトがない場合に、害のないメッセージをいくつか出力するかもしれません。)

-C
--create

Create the database before restoring into it. If <option>&#45;-clean</option> is also specified, drop and recreate the target database before connecting to it. リストア前にデータベースを作成します。 --cleanも同時に指定されている場合、接続する前に対象データベースを削除し再作成します。

With <option>&#45;-create</option>, <application>pg_restore</application> also restores the database's comment if any, and any configuration variable settings that are specific to this database, that is, any <command>ALTER DATABASE ... SET ...</command> and <command>ALTER ROLE ... IN DATABASE ... SET ...</command> commands that mention this database. Access privileges for the database itself are also restored, unless <option>&#45;-no-acl</option> is specified. --createでは、pg_restoreは、もしあるならデータベースのコメントもリストアします。また、あらゆる設定変数の当データベースに対する設定、すなわち、このデータベースを対象にしたALTER DATABASE ... SET ...ALTER ROLE ... IN DATABASE ... SET ...コマンドもリストアします。 --no-aclが指定されていない限り、データベース自体に対するアクセス権限もリストアされます。

When this option is used, the database named with <option>-d</option> is used only to issue the initial <command>DROP DATABASE</command> and <command>CREATE DATABASE</command> commands. All data is restored into the database name that appears in the archive. このオプションがある場合、-dで指定したデータベースは最初のDROP DATABASECREATE DATABASEコマンドの発行時にのみ使用されます。 そして、すべてのデータはアーカイブ内に記述された名前のデータベースにリストアされます。

-d dbname
--dbname=dbname

Connect to database <replaceable class="parameter">dbname</replaceable> and restore directly into the database. The <replaceable>dbname</replaceable> can be a <link linkend="libpq-connstring">connection string</link>. If so, connection string parameters will override any conflicting command line options. dbnameデータベースに接続し、このデータベースに直接リストアします。 dbname接続文字列でも構いません。 その場合、接続文字列パラメータは衝突するコマンドラインオプションよりも優先します。

-e
--exit-on-error

Exit if an error is encountered while sending SQL commands to the database. The default is to continue and to display a count of errors at the end of the restoration. データベースにSQLコマンドを送信中にエラーが発生した場合、処理を終了します。 デフォルトでは、処理を続行し、リストア処理の最後に発生したエラーの数を表示します。

-f filename
--file=filename

Specify output file for generated script, or for the listing when used with <option>-l</option>. Use <literal>-</literal> for <systemitem>stdout</systemitem>. 作成するスクリプト(-lを使用した場合はアーカイブの一覧)の出力ファイルを指定します。 stdout(標準出力)に出力するには-を使ってください。

-F format
--format=format

Specify format of the archive. It is not necessary to specify the format, since <application>pg_restore</application> will determine the format automatically. If specified, it can be one of the following: アーカイブの形式を指定します。 pg_restoreは形式を自動認識するので、このオプションは必須ではありません。 指定する値は以下のいずれかになります。

c
custom

The archive is in the custom format of <application>pg_dump</application>. アーカイブがpg_dumpのカスタム形式であることを表します。

d
directory

The archive is a directory archive. アーカイブがディレクトリアーカイブであることを表します。

t
tar

The archive is a <command>tar</command> archive. アーカイブがtarアーカイブであることを表します。

-I index
--index=index

Restore definition of named index only. Multiple indexes may be specified with multiple <option>-I</option> switches. 指定したインデックスの定義のみをリストアします。 複数の-Iスイッチをつけることで複数のインデックスを指定できます。

-j number-of-jobs
--jobs=number-of-jobs

Run the most time-consuming steps of <application>pg_restore</application> &mdash; those that load data, create indexes, or create constraints &mdash; concurrently, using up to <replaceable class="parameter">number-of-jobs</replaceable> concurrent sessions. This option can dramatically reduce the time to restore a large database to a server running on a multiprocessor machine. This option is ignored when emitting a script rather than connecting directly to a database server. pg_restoreのもっとも時間がかかる部分、つまり、データのロード、インデックスの作成、制約の作成部分を最大number-of-jobsの並行セッションを使用して実行します。 このオプションは、複数プロセッサマシンで稼働するサーバに大規模なデータベースをリストアする時間を劇的に減らすことができます。 データベースサーバに直接接続するのではなくスクリプトを生成する場合には、このオプションは無視されます。

Each job is one process or one thread, depending on the operating system, and uses a separate connection to the server. 各ジョブは1プロセスまたは1スレッド(オペレーティングシステムに依存)です。 各ジョブはサーバへの別々の接続を使用します。

The optimal value for this option depends on the hardware setup of the server, of the client, and of the network. Factors include the number of CPU cores and the disk setup. A good place to start is the number of CPU cores on the server, but values larger than that can also lead to faster restore times in many cases. Of course, values that are too high will lead to decreased performance because of thrashing. このオプションの最適値はサーバ、クライアント、ネットワークのハードウェア構成に依存します。 要素にはCPUコア数やディスク構成も含まれます。 試行する最初の値としてサーバのCPUコア数を勧めます。 しかし、多くの場合これより大きな値でもリストア時間を高速化することができます。 当然ながらあまりに大きな値を使用すると、スラッシングのために性能が劣化することになります。

Only the custom and directory archive formats are supported with this option. The input must be a regular file or directory (not, for example, a pipe or standard input). Also, multiple jobs cannot be used together with the option <option>&#45;-single-transaction</option>. カスタムアーカイブ書式およびディレクトリアーカイブ書式のみがこのオプションをサポートします。 入力ファイルは通常のファイルまたはディレクトリでなければなりません(例えばパイプや標準入力はいけません)。 また、複数ジョブは--single-transactionオプションといっしょに使用することはできません。

-l
--list

List the table of contents of the archive. The output of this operation can be used as input to the <option>-L</option> option. Note that if filtering switches such as <option>-n</option> or <option>-t</option> are used with <option>-l</option>, they will restrict the items listed. アーカイブの内容を一覧表として出力します。 このコマンドが出力する一覧は、-Lオプションに対する入力として使用することができます。 -n-tなどのフィルタオプションを-lといっしょに使用すると、一覧出力する項目が制限されます。

-L list-file
--use-list=list-file

Restore only those archive elements that are listed in <replaceable class="parameter">list-file</replaceable>, and restore them in the order they appear in the file. Note that if filtering switches such as <option>-n</option> or <option>-t</option> are used with <option>-L</option>, they will further restrict the items restored. list-file内で指定したアーカイブ要素のみをリストアします。 また、それらはそのファイルの出現順にリストアされます。 -n-tなどのフィルタオプションを-Lといっしょに使用すると、リストアする項目がさらに制限されます。

<para><replaceable class="parameter">list-file</replaceable> is normally created by editing the output of a previous <option>-l</option> operation. Lines can be moved or removed, and can also be commented out by placing a semicolon (<literal>;</literal>) at the start of the line. See below for examples.

list-fileは通常、事前に行った-l操作の出力を編集して作成されます。 行の移動や削除、または、行の先頭にセミコロン(;)を付けてコメントアウトすることが可能です。 後述の例を参照してください。

-n schema
--schema=schema

Restore only objects that are in the named schema. Multiple schemas may be specified with multiple <option>-n</option> switches. This can be combined with the <option>-t</option> option to restore just a specific table. 指定されたスキーマ内のオブジェクトのみをリストアします。 複数の-nスイッチをつけることで複数のスキーマを指定できます。 これは特定のテーブルのみをリストアするために-tオプションと組み合わせることができます。

-N schema
--exclude-schema=schema

Do not restore objects that are in the named schema. Multiple schemas to be excluded may be specified with multiple <option>-N</option> switches. 指定したスキーマ内にあるオブジェクトをリストアしません。 -Nオプションを複数回指定することで、複数のスキーマを除外することができます。

When both <option>-n</option> and <option>-N</option> are given for the same schema name, the <option>-N</option> switch wins and the schema is excluded. 同じスキーマ名が-n-Nの両方で指定された場合は、-Nオプションが優先し、そのスキーマは除外されます。

-O
--no-owner

Do not output commands to set ownership of objects to match the original database. By default, <application>pg_restore</application> issues <command>ALTER OWNER</command> or <command>SET SESSION AUTHORIZATION</command> statements to set ownership of created schema elements. These statements will fail unless the initial connection to the database is made by a superuser (or the same user that owns all of the objects in the script). With <option>-O</option>, any user name can be used for the initial connection, and this user will own all the created objects. オブジェクトの所有者を元のデータベースに合わせるためのコマンドを出力しません。 デフォルトでは、pg_restoreは、ALTER OWNERまたはSET SESSION AUTHORIZATIONを発行して、作成したスキーマ要素の所有者を設定します。 データベースに最初に接続したのがスーパーユーザ(もしくは、そのスクリプト内の全てのオブジェクトを所有するユーザ)でない場合、これらの文は失敗します。 -Oを付与すると、初期接続に任意のユーザ名を使用できるようになります。ただし、この場合は、全てのオブジェクトの所有者がリストアしたユーザになります。

-P function-name(argtype [, ...])
--function=function-name(argtype [, ...])

Restore the named function only. Be careful to spell the function name and arguments exactly as they appear in the dump file's table of contents. Multiple functions may be specified with multiple <option>-P</option> switches. 指定した関数のみをリストアします。 関数や引数の名前は、ダンプファイルの一覧で出力される通りのスペルで正確に入力するよう注意してください。 複数の-Pスイッチをつけることで複数の関数を指定できます。

-R
--no-reconnect

This option is obsolete but still accepted for backwards compatibility. このオプションは廃止されました。後方互換性を保持するために受け入れられています。

-s
--schema-only

Restore only the schema (data definitions), not data, to the extent that schema entries are present in the archive. アーカイブ内にあるスキーマ項目の範囲でスキーマ(データ定義)のみをリストアし、データ(テーブルの内容)をリストアしません。

This option is the inverse of <option>&#45;-data-only</option>. It is similar to, but for historical reasons not identical to, specifying <option>&#45;-section=pre-data &#45;-section=post-data</option>. このオプションは--data-onlyの逆です。 このオプションは--section=pre-data --section=post-dataを指定することと似ていますが、歴史的な理由により同一ではありません。

(Do not confuse this with the <option>&#45;-schema</option> option, which uses the word <quote>schema</quote> in a different meaning.) (これと--schemaオプションと混同しないでください。schemaという単語を異なる意味で使用しています。)

-S username
--superuser=username

Specify the superuser user name to use when disabling triggers. This is relevant only if <option>&#45;-disable-triggers</option> is used. トリガを無効にする場合に使用する、スーパーユーザのユーザ名を指定します。 これは--disable-triggersを使う場合にのみ使用されます。

-t table
--table=table

Restore definition and/or data of only the named table. For this purpose, <quote>table</quote> includes views, materialized views, sequences, and foreign tables. Multiple tables can be selected by writing multiple <option>-t</option> switches. This option can be combined with the <option>-n</option> option to specify table(s) in a particular schema. 指定されたテーブルのみについて、定義、データまたはその両方をリストアします。 この目的において、テーブルにはビュー、マテリアライズドビュー、シーケンス、外部テーブルが含まれます。 複数の-tスイッチを指定することで複数のテーブルを指定することができます。 -nオプションと組み合わせることでスキーマを指定することができます。

注記

When <option>-t</option> is specified, <application>pg_restore</application> makes no attempt to restore any other database objects that the selected table(s) might depend upon. Therefore, there is no guarantee that a specific-table restore into a clean database will succeed. -tが指定された場合、pg_restoreは選択されたテーブルが依存するその他のデータベースオブジェクトについてリストアしようとはしません。 そのため、初期化されたデータベースに特定のテーブルをリストアすることが成功する保証はありません。

注記

This flag does not behave identically to the <option>-t</option> flag of <application>pg_dump</application>. There is not currently any provision for wild-card matching in <application>pg_restore</application>, nor can you include a schema name within its <option>-t</option>. And, while <application>pg_dump</application>'s <option>-t</option> flag will also dump subsidiary objects (such as indexes) of the selected table(s), <application>pg_restore</application>'s <option>-t</option> flag does not include such subsidiary objects. このフラグはpg_dump-tフラグと同じ動作をするわけではありません。 現在のところ、pg_restoreでワイルドカードマッチを提供する予定はありませんし、-tでスキーマ名を含めることもできません。 加えて、pg_dump-tフラグは選択されたテーブルの(インデックスなどの)従属オブジェクトもダンプしますが、pg_restore-tフラグではそのような従属オブジェクトを含めません。

注記

In versions prior to <productname>PostgreSQL</productname> 9.6, this flag matched only tables, not any other type of relation. PostgreSQLの9.6より前のバージョンでは、このフラグはテーブルにのみマッチし、その他の種類のリレーションとはマッチしませんでした。

-T trigger
--trigger=trigger

Restore named trigger only. Multiple triggers may be specified with multiple <option>-T</option> switches. 指定されたトリガだけをリストアします。 複数の-Tスイッチをつけることで、複数のトリガを指定できます。

-v
--verbose

Specifies verbose mode. This will cause <application>pg_restore</application> to output detailed object comments and start/stop times to the output file, and progress messages to standard error. Repeating the option causes additional debug-level messages to appear on standard error. 冗長モードを指定します。 これを指定すると、pg_restoreは詳細なオブジェクトコメント、開始時刻と終了時刻を出力ファイルに、進行メッセージを標準エラーに出力するようになります。 オプションを繰り返すと、追加のデバッグレベルメッセージが標準エラーに現れます。

-V
--version

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

-x
--no-privileges
--no-acl

Prevent restoration of access privileges (grant/revoke commands). アクセス権限(grant/revokeコマンド)のリストアを行いません。

-1
--single-transaction

Execute the restore as a single transaction (that is, wrap the emitted commands in <command>BEGIN</command>/<command>COMMIT</command>). This ensures that either all the commands complete successfully, or no changes are applied. This option implies <option>&#45;-exit-on-error</option>. リストアを単一トランザクションとして実行します(つまり発行するコマンドをBEGIN/COMMITで囲みます)。 これにより確実に、すべてのコマンドが完全に成功するか、まったく変更がなされないかのどちらかになります。 このオプションは--exit-on-errorを意味します。

--disable-triggers

This option is relevant only when performing a data-only restore. It instructs <application>pg_restore</application> to execute commands to temporarily disable triggers on the target tables while the data is restored. Use this if you have referential integrity checks or other triggers on the tables that you do not want to invoke during data restore. このオプションは、データのみのダンプからリストアする際にしか適用されません。 データのリストア中、pg_restoreに対し、対象テーブル上のトリガを一時的に無効にするコマンドを実行するよう指示します。 このオプションは、データのリストア中には呼び出したくない参照整合性検査やその他のトリガがある場合に使用します。

Presently, the commands emitted for <option>&#45;-disable-triggers</option> must be done as superuser. So you should also specify a superuser name with <option>-S</option> or, preferably, run <application>pg_restore</application> as a <productname>PostgreSQL</productname> superuser. 現在のところ、--disable-triggersが生成するコマンドを実行するのは、スーパーユーザでなければなりません。 そのため、-Sでスーパーユーザの名前を指定するか、あるいは、可能であれば、PostgreSQLのスーパーユーザ権限でpg_restoreを実行する必要があります。

--enable-row-security

This option is relevant only when restoring the contents of a table which has row security. By default, <application>pg_restore</application> will set <xref linkend="guc-row-security"/> to off, to ensure that all data is restored in to the table. If the user does not have sufficient privileges to bypass row security, then an error is thrown. This parameter instructs <application>pg_restore</application> to set <xref linkend="guc-row-security"/> to on instead, allowing the user to attempt to restore the contents of the table with row security enabled. This might still fail if the user does not have the right to insert the rows from the dump into the table. このオプションは、行セキュリティのあるテーブルの内容をリストアするときにのみ意味を持ちます。 デフォルトではpg_restorerow_securityをoffに設定し、すべてのデータが確実にテーブルにリストアされるようにします。 ユーザが行セキュリティを回避できるだけの十分な権限がないときはエラーが発生します。 このパラメータはpg_restorerow_securityをonに設定するようにし、ユーザが行セキュリティが有効なテーブルの内容をリストアできるようにします。 それでも、ユーザがダンプからテーブルに行を挿入する権限を持っていなければ、これは失敗します。

Note that this option currently also requires the dump be in <command>INSERT</command> format, as <command>COPY FROM</command> does not support row security. COPY FROMは行セキュリティをサポートしないので、このオプションは今のところ、ダンプがINSERT形式である必要があることに注意してください。

--if-exists

Use conditional commands (i.e., add an <literal>IF EXISTS</literal> clause) to drop database objects. This option is not valid unless <option>&#45;-clean</option> is also specified. データベースオブジェクトを削除するときに、条件コマンドを使います(つまりIF EXISTS句を追加します)。 このオプションは、--cleanも指定されているのでなければ有効にはなりません。

--no-comments

Do not output commands to restore comments, even if the archive contains them. たとえアーカイブにコメントが含まれていても、コメントをリストアするコマンドを出力しません。

--no-data-for-failed-tables

By default, table data is restored even if the creation command for the table failed (e.g., because it already exists). With this option, data for such a table is skipped. This behavior is useful if the target database already contains the desired table contents. For example, auxiliary tables for <productname>PostgreSQL</productname> extensions such as <productname>PostGIS</productname> might already be loaded in the target database; specifying this option prevents duplicate or obsolete data from being loaded into them. デフォルトでは、関連するテーブルの作成に失敗した(たとえば、既に存在するなどの理由により)としてもテーブルデータオブジェクトはリストアされます。 このオプションにより、こうしたテーブルデータは単に無視されるようになります。 これは対象のデータベースに目的のテーブルの中身が含まれている時に便利です。 たとえばPostGISなどのPostgreSQL拡張用の補助テーブルが既に対象のデータベース内に存在する可能性があります。 このオプションを指定すれば、二重ロードや古いデータのロードを防ぐことができます。

This option is effective only when restoring directly into a database, not when producing SQL script output. このオプションは直接データベースにリストアする時にのみ有効で、SQLスクリプト出力を生成する時は無効です。

--no-publications

Do not output commands to restore publications, even if the archive contains them. アーカイブにパブリケーションが含まれていたとしても、それをリストアするコマンドを出力しません。

--no-security-labels

Do not output commands to restore security labels, even if the archive contains them. アーカイブにセキュリティラベルが含まれている場合であっても、セキュリティラベルを戻すコマンドを出力しません。

--no-subscriptions

Do not output commands to restore subscriptions, even if the archive contains them. アーカイブにサブスクリプションが含まれていたとしても、それをリストアするコマンドを出力しません。

--no-table-access-method

Do not output commands to select table access methods. With this option, all objects will be created with whichever access method is the default during restore. テーブルアクセスメソッドを選択するコマンドを出力しません。 このオプションを付けると、すべてのオブジェクトはリストア時にデフォルトとなっているテーブルアクセスメソッドで作成されます。

--no-tablespaces

Do not output commands to select tablespaces. With this option, all objects will be created in whichever tablespace is the default during restore. テーブル空間を選択するコマンドを出力しません。 このオプションを付けると、すべてのオブジェクトはリストア時にデフォルトとなっているテーブル空間内に作成されます。

--section=sectionname

Only restore the named section. The section name can be <option>pre-data</option>, <option>data</option>, or <option>post-data</option>. This option can be specified more than once to select multiple sections. The default is to restore all sections. 指定された部分のみをリストアします。 部分名はpre-datadatapost-dataのいずれかを取ることができます。 複数の部分を選択するために、このオプションを複数指定することができます。 デフォルトではすべての部分をリストアします。

The data section contains actual table data as well as large-object definitions. Post-data items consist of definitions of indexes, triggers, rules and constraints other than validated check constraints. Pre-data items consist of all other data definition items. data部分には、実際のテーブルデータやラージオブジェクト定義が含まれます。 post-data項目は、インデックス定義、トリガ定義、ルール定義、有効化された検査制約以外の制約定義から構成されます。 pre-data項目は、他のすべてのデータ定義項目から構成されます。

--strict-names

Require that each schema (<option>-n</option>/<option>&#45;-schema</option>) and table (<option>-t</option>/<option>&#45;-table</option>) qualifier match at least one schema/table in the backup file. スキーマ指定(-n/--schema)およびテーブル指定(-t/--table)がバックアップファイル内の少なくとも1つのスキーマあるいはテーブルにマッチすることを必要とします。

--use-set-session-authorization

Output SQL-standard <command>SET SESSION AUTHORIZATION</command> commands instead of <command>ALTER OWNER</command> commands to determine object ownership. This makes the dump more standards-compatible, but depending on the history of the objects in the dump, might not restore properly. ALTER OWNERコマンドの代わりに、標準SQLのSET SESSION AUTHORIZATIONコマンドを出力して、オブジェクトの所有権を決定します。 これにより、ダンプの標準への互換性が高まりますが、ダンプ内のオブジェクトの履歴によっては正しくリストアされない可能性が生じます。

-?
--help

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

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

-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. The default is taken from the <envar>PGHOST</envar> environment variable, if set, else a Unix domain socket connection is attempted. サーバが稼働しているマシンのホスト名を指定します。 この値がスラッシュから始まる場合、Unixドメインソケット用のディレクトリとして使用されます。 デフォルトは、設定されていれば環境変数PGHOSTから取得されます。 設定されていなければ、Unixドメインソケット接続とみなされます。

-p port
--port=port

Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <envar>PGPORT</envar> environment variable, if set, or a compiled-in default. サーバが接続を監視するTCPポートもしくはローカルUnixドメインソケットファイルの拡張子を指定します。 デフォルトは、設定されている場合、環境変数PGPORTの値となります。設定されていなければ、コンパイル時のデフォルト値となります。

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

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

--role=rolename

Specifies a role name to be used to perform the restore. This option causes <application>pg_restore</application> to issue a <command>SET ROLE</command> <replaceable class="parameter">rolename</replaceable> command after connecting to the database. It is useful when the authenticated user (specified by <option>-U</option>) lacks privileges needed by <application>pg_restore</application>, but can switch to a role with the required rights. Some installations have a policy against logging in directly as a superuser, and use of this option allows restores to be performed without violating the policy. リストアを実行する際に使用するロール名を指定します。 このオプションによりpg_restoreはデータベースに接続した後にSET ROLE rolenameコマンドを発行するようになります。 認証に使用したユーザ(-Uで指定されたユーザ)がpg_restoreで必要とされる権限を持たないが、必要な権限を持つロールに切り替えることができる場合に有用です。 一部のインストレーションではスーパーユーザとして直接ログインさせないポリシーを取ることがありますが、このオプションを使用することでポリシーに反することなくリストアを行うことができます。

環境

<title>Environment</title>
PGHOST
PGOPTIONS
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"/>). However, it does not read <envar>PGDATABASE</envar> when a database name is not supplied. また、このユーティリティは、他のほとんどのPostgreSQLユーティリティと同様、libpqでサポートされる環境変数を使用します(34.15を参照してください)。 しかしデータベース名が指定されていない場合はPGDATABASEは読み取られません。

診断

<title>Diagnostics</title>

When a direct database connection is specified using the <option>-d</option> option, <application>pg_restore</application> internally executes <acronym>SQL</acronym> statements. If you have problems running <application>pg_restore</application>, make sure you are able to select information from the database using, for example, <xref linkend="app-psql"/>. Also, any default connection settings and environment variables used by the <application>libpq</application> front-end library will apply. -dオプションによってデータベースに直接接続するよう指定されている場合、pg_restoreは内部でSQL文を実行します。 pg_restoreの実行時に問題が発生する場合は、psqlなどを使用して、そのデータベースから情報を選択できることを確認してください。 また、libpqフロントエンドライブラリで使用されるデフォルト接続設定や環境変数もすべて適用されます。

注釈

<title>Notes</title>

If your installation has any local additions to the <literal>template1</literal> database, be careful to load the output of <application>pg_restore</application> into a truly empty database; otherwise you are likely to get errors due to duplicate definitions of the added objects. To make an empty database without any local additions, copy from <literal>template0</literal> not <literal>template1</literal>, for example: template1データベースに対し独自の変更を行っている場合、pg_restoreの出力は、確実に空のデータベースにロードするよう注意してください。 そうしないと、おそらく追加されたオブジェクトの重複定義によってエラーが発生します。 独自の追加が反映されていない空のデータベースを作成するには、template1ではなくtemplate0をコピーしてください。 以下に例を示します。

CREATE DATABASE foo WITH TEMPLATE template0;

The limitations of <application>pg_restore</application> are detailed below. pg_restoreの制限を以下に示します。

  • When restoring data to a pre-existing table and the option <option>&#45;-disable-triggers</option> is used, <application>pg_restore</application> emits commands to disable triggers on user tables before inserting the data, then emits commands to re-enable them after the data has been inserted. If the restore is stopped in the middle, the system catalogs might be left in the wrong state. 既存のテーブルにデータをリストアする際に--disable-triggersオプションを使用すると、pg_restoreは、データを挿入する前に、ユーザテーブル上のトリガを無効にするコマンドを発行し、データの挿入が完了した後で、それらを再び有効にする問い合わせを発行します。 リストアが途中で停止した場合、システムカタログが不適切な状態のままになっている可能性があります。

  • <para><application>pg_restore</application> cannot restore large objects selectively; for instance, only those for a specific table. If an archive contains large objects, then all large objects will be restored, or none of them if they are excluded via <option>-L</option>, <option>-t</option>, or other options.

    pg_restoreは特定のテーブルのみのラージオブジェクトなどといった、ラージオブジェクトを選択してリストアすることはできません。 アーカイブにラージオブジェクトが含まれる場合、すべてのラージオブジェクトをリストアします。 もし-L-tなどのオプションで除外が指定されていた場合は、全くリストアしません。

See also the <xref linkend="app-pgdump"/> documentation for details on limitations of <application>pg_dump</application>. pg_dumpの制限についての詳細は、pg_dumpの文書も参照してください。

Once restored, it is wise to run <command>ANALYZE</command> on each restored table so the optimizer has useful statistics; see <xref linkend="vacuum-for-statistics"/> and <xref linkend="autovacuum"/> for more information. リストア後は、オプティマイザが有用な統計情報を持つように、リストアしたテーブルそれぞれに対してANALYZEを実行することをお勧めします。 詳しくは25.1.3および25.1.6を参照してください。

<title>Examples</title>

Assume we have dumped a database called <literal>mydb</literal> into a custom-format dump file: mydbという名前のデータベースをカスタム形式のダンプファイルにダンプしているものと仮定します。

$ pg_dump -Fc mydb > db.dump

To drop the database and recreate it from the dump: データベースを削除し、ダンプファイルから再作成します。

$ dropdb mydb
$ pg_restore -C -d postgres db.dump

The database named in the <option>-d</option> switch can be any database existing in the cluster; <application>pg_restore</application> only uses it to issue the <command>CREATE DATABASE</command> command for <literal>mydb</literal>. With <option>-C</option>, data is always restored into the database name that appears in the dump file. -dオプションのデータベース名は、クラスタに存在する任意のデータベースで良いです。 pg_restoreは、mydbに対するCREATE DATABASEコマンドを発行するためだけに、このデータベース名を使用します。 -Cを付けると、データは常にダンプファイル内に記載された名前のデータベースにリストアされます。

To restore the dump into a new database called <literal>newdb</literal>: newdbという新しいデータベースにダンプファイルをリストアします。

$ createdb -T template0 newdb
$ pg_restore -d newdb db.dump

Notice we don't use <option>-C</option>, and instead connect directly to the database to be restored into. Also note that we clone the new database from <literal>template0</literal> not <literal>template1</literal>, to ensure it is initially empty. -Cを使用していないことに注意してください。 代わりにリストアするデータベースに直接接続しています。 また、新しいデータベースをtemplate1ではなくtemplate0からコピーして作成している点にも注意してください。 確実に初期状態を空にするためです。

To reorder database items, it is first necessary to dump the table of contents of the archive: データベースのアイテムを並び換えるには、まずこのアーカイブの内容の一覧をダンプしなければなりません。

$ pg_restore -l db.dump > db.list

The listing file consists of a header and one line for each item, e.g.: 一覧ファイルは、ヘッダと各アイテムを1行で表したものから構成されます。

;
; Archive created at Mon Sep 14 13:55:39 2009
;     dbname: DBDEMOS
;     TOC Entries: 81
;     Compression: 9
;     Dump Version: 1.10-0
;     Format: CUSTOM
;     Integer: 4 bytes
;     Offset: 8 bytes
;     Dumped from database version: 8.3.5
;     Dumped by pg_dump version: 8.3.8
;
;
; Selected TOC Entries:
;
3; 2615 2200 SCHEMA - public pasha
1861; 0 0 COMMENT - SCHEMA public pasha
1862; 0 0 ACL - public pasha
317; 1247 17715 TYPE public composite pasha
319; 1247 25899 DOMAIN public domain0 pasha

Semicolons start a comment, and the numbers at the start of lines refer to the internal archive ID assigned to each item. セミコロンで始まる行はコメントです。 行の先頭の番号は、各アイテムに割り当てられた内部アーカイブIDを示します。

Lines in the file can be commented out, deleted, and reordered. For example: このファイルの各行に対して、コメントアウト、削除、並べ替えを行うことができます。 以下に例を示します。

10; 145433 TABLE map_resolutions postgres
;2; 145344 TABLE species postgres
;4; 145359 TABLE nt_header postgres
6; 145402 TABLE species_records postgres
;8; 145416 TABLE ss_old postgres

could be used as input to <application>pg_restore</application> and would only restore items 10 and 6, in that order: このファイルをpg_restoreの入力として利用すれば、アイテム10と6だけを、この順番でリストアすることができます。

$ pg_restore -L db.list db.dump

関連項目

<title>See Also</title> pg_dump, pg_dumpall, psql