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

pg_dump

pg_dump — extract a <productname>PostgreSQL</productname> database into a script file or other archive file PostgreSQLデータベースをスクリプトファイルまたは他のアーカイブファイルへ抽出する

概要

pg_dump [connection-option...] [option...] [dbname]

説明

<title>Description</title>

<application>pg_dump</application> is a utility for backing up a <productname>PostgreSQL</productname> database. It makes consistent backups even if the database is being used concurrently. <application>pg_dump</application> does not block other users accessing the database (readers or writers). pg_dumpPostgreSQLデータベースをバックアップするユーティリティです。 データベースを使用中であっても一貫性のあるバックアップを作成することができます。 pg_dumpは他のユーザによるデータベースへのアクセス(読み書き)をブロックしません。

<application>pg_dump</application> only dumps a single database. To back up an entire cluster, or to back up global objects that are common to all databases in a cluster (such as roles and tablespaces), use <xref linkend="app-pg-dumpall"/>. pg_dumpは単一のデータベースしかダンプしません。 クラスタ全体、あるいは、クラスタ内の全データベースに共通のグローバルオブジェクト(ロールやテーブル空間など)をダンプするにはpg_dumpallを使用してください。

Dumps can be output in script or archive file formats. Script dumps are plain-text files containing the SQL commands required to reconstruct the database to the state it was in at the time it was saved. To restore from such a script, feed it to <xref linkend="app-psql"/>. Script files can be used to reconstruct the database even on other machines and other architectures; with some modifications, even on other SQL database products. ダンプはスクリプト形式、または、アーカイブファイル形式で出力することができます。 スクリプトダンプは、保存した時点の状態のデータベースを再構成するために必要なSQLコマンドが書き込まれた平文ファイルです。 このスクリプトを使ってリストアを行うには、それをpsqlに読み込ませます。 スクリプトファイルを使えば、ダンプを行ったのとは別のマシンや別のアーキテクチャ上でも、データベースを再構築することができます。 また、多少編集すれば他のSQLデータベース製品上でもデータベースの再構築が可能です。

The alternative archive file formats must be used with <xref linkend="app-pgrestore"/> to rebuild the database. They allow <application>pg_restore</application> to be selective about what is restored, or even to reorder the items prior to being restored. The archive file formats are designed to be portable across architectures. もう1つの形式であるアーカイブファイル形式を使ってデータベースを再構築するには、pg_restoreを使用しなければなりません。 このファイルを使用すると、pg_restoreがリストア対象を選択したり、リストアするアイテムを並べ替えたりできます。 アーカイブファイルもまた、アーキテクチャを越えて移植できるように設計されています。

When used with one of the archive file formats and combined with <application>pg_restore</application>, <application>pg_dump</application> provides a flexible archival and transfer mechanism. <application>pg_dump</application> can be used to backup an entire database, then <application>pg_restore</application> can be used to examine the archive and/or select which parts of the database are to be restored. The most flexible output file formats are the <quote>custom</quote> format (<option>-Fc</option>) and the <quote>directory</quote> format (<option>-Fd</option>). They allow for selection and reordering of all archived items, support parallel restoration, and are compressed by default. The <quote>directory</quote> format is the only format that supports parallel dumps. いずれかのアーカイブファイル形式をpg_restoreと組み合わせて使用する場合は、pg_dumpの柔軟なアーカイブ/転送機構が利用できます。 具体的には、pg_dumpを使用してデータベース全体をバックアップし、pg_restoreを使用して、アーカイブの内容を検査したり、データベースの一部を選択してリストアしたりすることができます。 最も柔軟な出力ファイル形式はカスタム形式(-Fc)とディレクトリ形式(-Fd)です。 これらはすべての保存された項目の選択や並べ替えを行うことができ、並行リストアをサポートし、デフォルトで圧縮されます。 ディレクトリ形式は、並行ダンプをサポートする唯一の形式です。

While running <application>pg_dump</application>, one should examine the output for any warnings (printed on standard error), especially in light of the limitations listed below. pg_dumpの実行中は、標準エラーに出力される警告(特に後述の制限に関する警告)が出力されていないか確認してください。

オプション

<title>Options</title>

The following command-line options control the content and format of the output. 以下のコマンドラインオプションは出力内容とその形式を制御します。

dbname

Specifies the name of the database to be dumped. If this is not specified, the environment variable <envar>PGDATABASE</envar> is used. If that is not set, the user name specified for the connection is used. ダンプするデータベースの名前を指定します。 指定されていない場合は環境変数PGDATABASEが使われます。 この変数も設定されていない場合は、接続のために指定されたユーザ名が使用されます。

-a
--data-only

Dump only the data, not the schema (data definitions). Table data, large objects, and sequence values are dumped. データのみをダンプし、スキーマ(データ定義)はダンプしません。 テーブルデータ、ラージオブジェクト、シーケンス値がダンプされます。

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

-b
--large-objects
--blobs (deprecated)

Include large objects in the dump. This is the default behavior except when <option>&#45;-schema</option>, <option>&#45;-table</option>, or <option>&#45;-schema-only</option> is specified. The <option>-b</option> switch is therefore only useful to add large objects to dumps where a specific schema or table has been requested. Note that large objects are considered data and therefore will be included when <option>&#45;-data-only</option> is used, but not when <option>&#45;-schema-only</option> is. ラージオブジェクトをダンプに含めます。 --schema--table--schema-onlyが指定された場合を除き、これがデフォルトの動作です。 したがって、-bオプションは特定のスキーマやテーブルのダンプにラージオブジェクトを追加する場合にのみ有用です。 ラージオブジェクトはデータとみなされるため、--data-onlyが使われたときは含まれますが、--schema-onlyが使われたときには含まれないことに注意してください。

-B
--no-large-objects
--no-blobs (deprecated)

Exclude large objects in the dump. ラージオブジェクトをダンプに含めません。

When both <option>-b</option> and <option>-B</option> are given, the behavior is to output large objects, when data is being dumped, see the <option>-b</option> documentation. -b-Bの両方が指定された場合は、データのダンプ時にラージオブジェクトを出力します。 -bの説明を参照してください。

-c
--clean

Output commands to clean (drop) database objects prior to outputting the commands for creating them. (Unless <option>&#45;-if-exists</option> is also specified, restore might generate some harmless error messages, if any objects were not present in the destination database.) データベースオブジェクトを作成するコマンドの前に、データベースオブジェクトを整理(削除)するコマンドを書き出します。 (--if-existsも指定されなければ、リストア先のデータベースの中に存在しないオブジェクトがある場合に、害がないエラーがいくつか発生するかもしれません。)

This option is ignored when emitting an archive (non-text) output file. For the archive formats, you can specify the option when you call <command>pg_restore</command>. このオプションはアーカイブ(テキストでない)出力ファイルを出力する場合には無視されます。 アーカイブ形式では、pg_restoreを呼び出す時にこのオプションを指定できます。

-C
--create

Begin the output with a command to create the database itself and reconnect to the created database. (With a script of this form, it doesn't matter which database in the destination installation you connect to before running the script.) If <option>&#45;-clean</option> is also specified, the script drops and recreates the target database before reconnecting to it. 初めにデータベース自体を作成するコマンドを出力し、その後、作成したデータベースに接続するコマンドを出力します (このようなスクリプトを使用すると、スクリプトを実行する前に対象のインストレーションの中のどのデータベースに接続すればよいかという問題を考える必要がなくなります)。 --cleanも同時に指定されている場合、このスクリプトは接続する前に対象データベースを削除し再作成します。

With <option>&#45;-create</option>, the output also includes 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 dumped, unless <option>&#45;-no-acl</option> is specified. --createでは出力に、もしあるならデータベースのコメントも含まれます。また、あらゆる設定変数の設定、すなわち、このデーベースを対象としているALTER DATABASE ... SET ...ALTER ROLE ... IN DATABASE ... SET ...コマンドも含まれます。 --no-aclが指定されていない限り、データベースに対するアクセス権限自体もダンプされます。

This option is ignored when emitting an archive (non-text) output file. For the archive formats, you can specify the option when you call <command>pg_restore</command>. このオプションはアーカイブ(テキストでない)出力ファイルを出力する場合には無視されます。 アーカイブ形式では、pg_restoreを呼び出す時にこのオプションを指定できます。

-e pattern
--extension=pattern

Dump only extensions matching <replaceable class="parameter">pattern</replaceable>. When this option is not specified, all non-system extensions in the target database will be dumped. Multiple extensions can be selected by writing multiple <option>-e</option> switches. The <replaceable class="parameter">pattern</replaceable> parameter is interpreted as a pattern according to the same rules used by <application>psql</application>'s <literal>\d</literal> commands (see <xref linkend="app-psql-patterns"/>), so multiple extensions can also be selected by writing wildcard characters in the pattern. When using wildcards, be careful to quote the pattern if needed to prevent the shell from expanding the wildcards. patternにマッチする拡張のみをダンプします。 このオプションが指定されなければ、対象データベース内にあるシステム以外の拡張すべてがダンプされます。 複数の-eオプションを記述することで、複数の拡張を選択できます。 patternパラメータはpsql\dコマンドと同じ規則に従うパターン(パターン参照)として解釈されます。ですので、ワイルドカード文字をパターン内に記述することで、複数の拡張を選択することもできます。 ワイルドカードを使用する時は、シェルがそのワイルドカードを展開しないように、必要であればパターンを引用符で括ってください。

Any configuration relation registered by <function>pg_extension_config_dump</function> is included in the dump if its extension is specified by <option>&#45;-extension</option>. pg_extension_config_dumpにより登録された設定リレーションは、その拡張が--extensionで指定されていればダンプに含まれます。

注記

When <option>-e</option> is specified, <application>pg_dump</application> makes no attempt to dump any other database objects that the selected extension(s) might depend upon. Therefore, there is no guarantee that the results of a specific-extension dump can be successfully restored by themselves into a clean database. -eが指定されると、pg_dumpは選択した拡張が依存する可能性のある、その他のデータベースオブジェクトのダンプを行ないません。 したがって、拡張指定のダンプ結果を初期状態のデータベースに正常にリストアできるという保証はありません。

-E encoding
--encoding=encoding

Create the dump in the specified character set encoding. By default, the dump is created in the database encoding. (Another way to get the same result is to set the <envar>PGCLIENTENCODING</envar> environment variable to the desired dump encoding.) The supported encodings are described in <xref linkend="multibyte-charset-supported"/>. 指定した文字セット符号化方式でダンプを作成します。 デフォルトではダンプはデータベースの符号化方式で作成されます。 (環境変数PGCLIENTENCODINGを好みのダンプ時の符号化方式に設定することで、同じ結果を得ることができます。) サポートする符号化方式は24.3.1に記載されています。

-f file
--file=file

Send output to the specified file. This parameter can be omitted for file based output formats, in which case the standard output is used. It must be given for the directory output format however, where it specifies the target directory instead of a file. In this case the directory is created by <command>pg_dump</command> and must not exist before. 出力を指定のファイルに送ります。 ファイルを基にする出力形式ではこのパラメータは省くことができます。 省略時は標準出力が使用されます。 しかしディレクトリ出力形式の場合は、省略することはできず、ファイルではなく対象ディレクトリを指定します。 この場合、ディレクトリはpg_dumpが生成しますので、事前に存在してはなりません。

-F format
--format=format

Selects the format of the output. <replaceable>format</replaceable> can be one of the following: 出力形式を選択します。 formatには以下のいずれかを取ることができます。

p
plain

Output a plain-text <acronym>SQL</acronym> script file (the default). 平文のSQLスクリプトファイルを出力します(デフォルト)。

c
custom

Output a custom-format archive suitable for input into <application>pg_restore</application>. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is also compressed by default. pg_restoreへの入力に適したカスタム形式アーカイブを出力します。 ディレクトリ出力形式と一緒に使用する場合、リストア時に手作業で保管された項目の選択、再順序付けできますので、これはもっとも柔軟な出力形式です。 また、この形式はデフォルトで圧縮されます。

d
directory

Output a directory-format archive suitable for input into <application>pg_restore</application>. This will create a directory with one file for each table and large object being dumped, plus a so-called Table of Contents file describing the dumped objects in a machine-readable format that <application>pg_restore</application> can read. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the <application>gzip</application>, <application>lz4</application>, or <application>zstd</application> tools. This format is compressed by default using <literal>gzip</literal> and also supports parallel dumps. pg_restoreへの入力に適したディレクトリ形式のアーカイブを出力します。 これは、ダンプされる各テーブルおよびラージオブジェクトごとに1つのファイル、さらに、pg_restoreから読み取り可能な、機械的に読み取り易い書式でダンプしたオブジェクトを記述する目次ファイルと呼ばれるファイルを持つディレクトリを作成します。 ディレクトリ形式アーカイブは標準Unixツールで操作することができます。 例えば、未圧縮アーカイブ内のファイルをツールgziplz4zstdを使用して圧縮することができます。 この形式はデフォルトではgzipを使って圧縮されます。 また並行ダンプをサポートします。

t
tar

Output a <command>tar</command>-format archive suitable for input into <application>pg_restore</application>. The tar format is compatible with the directory format: extracting a tar-format archive produces a valid directory-format archive. However, the tar format does not support compression. Also, when using tar format the relative order of table data items cannot be changed during restore. pg_restoreへの入力に適したtar形式のアーカイブを出力します。 このtar形式はディレクトリ形式と互換性があります。 tar形式アーカイブを展開すると、有効なディレクトリ形式のアーカイブを生成します。 しかしtar形式は圧縮をサポートしません。 またtar形式を使う場合、リストア時にテーブルデータ項目の相対的な順序を変更することはできません。

-j njobs
--jobs=njobs

Run the dump in parallel by dumping <replaceable class="parameter">njobs</replaceable> tables simultaneously. This option may reduce the time needed to perform the dump but it also increases the load on the database server. You can only use this option with the directory output format because this is the only output format where multiple processes can write their data at the same time. njobs個のテーブルを同時にダンプすることによって、並行してダンプを実行します。 このオプションはダンプを実行するのに必要な時間を減らすかもしれませんが、データベースサーバの負荷を増やします。 このオプションはディレクトリ出力形式でのみ使用することができます。 複数のプロセスが同時にそのデータを書き出すことができるのはディレクトリ形式だけだからです。

<para><application>pg_dump</application> will open <replaceable class="parameter">njobs</replaceable> + 1 connections to the database, so make sure your <xref linkend="guc-max-connections"/> setting is high enough to accommodate all connections.

pg_dumpnjobs+1個のデータベース接続を開きます。 このため、すべての接続を収容できる程度にmax_connectionsが高いことを確認してください。

Requesting exclusive locks on database objects while running a parallel dump could cause the dump to fail. The reason is that the <application>pg_dump</application> leader process requests shared locks (<link linkend="locking-tables">ACCESS SHARE</link>) on the objects that the worker processes are going to dump later in order to make sure that nobody deletes them and makes them go away while the dump is running. If another client then requests an exclusive lock on a table, that lock will not be granted but will be queued waiting for the shared lock of the leader process to be released. Consequently any other access to the table will not be granted either and will queue after the exclusive lock request. This includes the worker process trying to dump the table. Without any precautions this would be a classic deadlock situation. To detect this conflict, the <application>pg_dump</application> worker process requests another shared lock using the <literal>NOWAIT</literal> option. If the worker process is not granted this shared lock, somebody else must have requested an exclusive lock in the meantime and there is no way to continue with the dump, so <application>pg_dump</application> has no choice but to abort the dump. 並行ダンプを実行している時にデータベースオブジェクトに対して排他ロックを要求すると、ダンプが失敗する可能性があります。 ダンプ実行中に誰かがダンプ予定のオブジェクトを削除してそれがなくなってしまうことがないように、ワーカープロセスがダンプする予定のオブジェクトに対してpg_dumpのリーダープロセスが共有ロック(ACCESS SHARE)を要求するのがその理由です。 その後他のクライアントがテーブルに対する排他ロックを要求すると、 そのロックは許可されませんが、リーダープロセスが共有ロックを解放することを待機するキューに保管されます。 その結果、テーブルへのその他のアクセスは許可されず、排他ロック要求の後のキューに保管されます。 これには、そのテーブルをダンプしようとする作業用プロセスも含まれます。 何らかの注意をしないと、古典的なデッドロック状態になります。 この競合を検知するためにpg_dumpの作業用プロセスはNOWAITオプションを使用する別の共有ロックを要求します。 作業用プロセスによる共有ロックが許可されない場合、だれかがその時に排他ロックを要求していることになり、ダンプを継続することができません。 pg_dumpには、ダンプを中断するしか選択肢がありません。

To perform a parallel dump, the database server needs to support synchronized snapshots, a feature that was introduced in <productname>PostgreSQL</productname> 9.2 for primary servers and 10 for standbys. With this feature, database clients can ensure they see the same data set even though they use different connections. <command>pg_dump -j</command> uses multiple database connections; it connects to the database once with the leader process and once again for each worker job. Without the synchronized snapshot feature, the different worker jobs wouldn't be guaranteed to see the same data in each connection, which could lead to an inconsistent backup. 並行ダンプを実行するために、データベースサーバは同期スナップショットをサポートする必要があります。 これはプライマリサーバについてはPostgreSQL 9.2で、スタンバイについてはバージョン10で導入された機能です。 この機能を用いれば、データベースクライアントは異なる接続を使用していたとしても、確実に同じデータセットを参照することができます。 pg_dump -jは複数のデータベース接続を使用します。 リーダープロセスで一度、また、作業用ジョブそれぞれでも一度、データベースと接続します。 同期スナップショット機能がないと、異なる作業用ジョブがそれぞれの接続で同じデータを参照していることが保証されず、一貫性がないバックアップになってしまいます。

-n pattern
--schema=pattern

Dump only schemas matching <replaceable class="parameter">pattern</replaceable>; this selects both the schema itself, and all its contained objects. When this option is not specified, all non-system schemas in the target database will be dumped. Multiple schemas can be selected by writing multiple <option>-n</option> switches. The <replaceable class="parameter">pattern</replaceable> parameter is interpreted as a pattern according to the same rules used by <application>psql</application>'s <literal>\d</literal> commands (see <xref linkend="app-psql-patterns"/>), so multiple schemas can also be selected by writing wildcard characters in the pattern. When using wildcards, be careful to quote the pattern if needed to prevent the shell from expanding the wildcards; see <xref linkend="pg-dump-examples"/> below. patternにマッチするスキーマのみをダンプします。 これはスキーマ自体とそこに含まれるオブジェクトすべてを選択します。 このオプションが指定されなければ、対象データベース内にあるシステム以外のスキーマすべてがダンプされます。 複数の-nオプションを記述することで、複数のスキーマを選択することができます。 patternパラメータはpsql\dコマンドと同じ規則に従うパターン(パターン参照)として解釈されます。 ですので、ワイルドカード文字をパターン内に記述することで、複数のスキーマを選択することもできます。 ワイルドカードを使用する時は、シェルがそのワイルドカードを展開しないように、必要であればパターンを引用符で括ってください。 下記のを参照してください。

注記

When <option>-n</option> is specified, <application>pg_dump</application> makes no attempt to dump any other database objects that the selected schema(s) might depend upon. Therefore, there is no guarantee that the results of a specific-schema dump can be successfully restored by themselves into a clean database. -nが指定されると、pg_dumpは選択したスキーマ内のオブジェクトが依存する可能性がある、その他のデータベースオブジェクトのダンプを行いません。 したがって、スキーマ指定のダンプ結果を初期状態のデータベースに正常にリストアできるという保証はありません。

注記

Non-schema objects such as large objects are not dumped when <option>-n</option> is specified. You can add large objects back to the dump with the <option>&#45;-large-objects</option> switch. -nが指定されると、ラージオブジェクトなどの非スキーマオブジェクトはダンプされません。 --large-objectsオプションをつけてダンプを行うことでラージオブジェクトも追加されます。

-N pattern
--exclude-schema=pattern

Do not dump any schemas matching <replaceable class="parameter">pattern</replaceable>. The pattern is interpreted according to the same rules as for <option>-n</option>. <option>-N</option> can be given more than once to exclude schemas matching any of several patterns. patternにマッチするスキーマをダンプしません。 このパターンは-nと同様の規則に従って解釈されます。 -Nを複数指定して、複数のパターンのいずれかにマッチするスキーマを除外することができます。

When both <option>-n</option> and <option>-N</option> are given, the behavior is to dump just the schemas that match at least one <option>-n</option> switch but no <option>-N</option> switches. If <option>-N</option> appears without <option>-n</option>, then schemas matching <option>-N</option> are excluded from what is otherwise a normal dump. -n-Nの両方が指定された場合、少なくとも1つの-nにマッチし-Nオプションにマッチしないスキーマだけがダンプされます。 -nなしで-Nが指定された場合、-Nにマッチするスキーマが通常のダンプから除外されます。

-O
--no-owner

Do not output commands to set ownership of objects to match the original database. By default, <application>pg_dump</application> issues <command>ALTER OWNER</command> or <command>SET SESSION AUTHORIZATION</command> statements to set ownership of created database objects. These statements will fail when the script is run unless it is started by a superuser (or the same user that owns all of the objects in the script). To make a script that can be restored by any user, but will give that user ownership of all the objects, specify <option>-O</option>. オブジェクトの所有権を元のデータベースにマッチさせるためのコマンドを出力しません。 デフォルトでは、pg_dumpは、ALTER OWNER文またはSET SESSION AUTHORIZATION文を発行して、作成したデータベースオブジェクトの所有権を設定します。 スーパーユーザ(もしくは、そのスクリプト内の全てのオブジェクトを所有するユーザ)以外のユーザがスクリプトを実行した場合、これらの文は失敗します。 任意のユーザがリストアできるスクリプトを作成するには、-Oを指定してください。 ただし、この場合は、全てのオブジェクトの所有者がリストアしたユーザとなってしまいます。

This option is ignored when emitting an archive (non-text) output file. For the archive formats, you can specify the option when you call <command>pg_restore</command>. このオプションはアーカイブ(テキストでない)出力ファイルを出力する場合には無視されます。 アーカイブ形式では、pg_restoreを呼び出す時にこのオプションを指定できます。

-R
--no-reconnect

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

-s
--schema-only

Dump only the object definitions (schema), not data. データ定義(スキーマ)のみをダンプし、データはダンプしません。

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という単語を異なる意味で使用しています。)

To exclude table data for only a subset of tables in the database, see <option>&#45;-exclude-table-data</option>. データベース内の一部のみのテーブルのテーブルデータを除外するためには--exclude-table-dataを参照してください。

-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. (Usually, it's better to leave this out, and instead start the resulting script as superuser.) トリガを無効にする場合に使用する、スーパーユーザのユーザ名を指定します。 これは--disable-triggersを使う場合にのみ使用されます。 (通常は このオプションを使うよりも、出力されたスクリプトをスーパーユーザ権限で実行する方が良いでしょう。)

-t pattern
--table=pattern

Dump only tables with names matching <replaceable class="parameter">pattern</replaceable>. Multiple tables can be selected by writing multiple <option>-t</option> switches. The <replaceable class="parameter">pattern</replaceable> parameter is interpreted as a pattern according to the same rules used by <application>psql</application>'s <literal>\d</literal> commands (see <xref linkend="app-psql-patterns"/>), so multiple tables can also be selected by writing wildcard characters in the pattern. When using wildcards, be careful to quote the pattern if needed to prevent the shell from expanding the wildcards; see <xref linkend="pg-dump-examples"/> below. patternにマッチする名前のテーブルのみをダンプします。 複数の-tオプションを記述することで複数のテーブルを選択することができます。 patternパラメータはpsql\dコマンドで使用される規則(パターン参照)と同じ規則に従うパターンとして解釈されます。 ですので、ワイルドカード文字をパターン内に記述することで、複数のテーブルを選択することもできます。 ワイルドカードを使用する時は、シェルによりそのワイルドカードを展開させないように、パターンを引用符で括ってください。 下記のを参照してください。

As well as tables, this option can be used to dump the definition of matching views, materialized views, foreign tables, and sequences. It will not dump the contents of views or materialized views, and the contents of foreign tables will only be dumped if the corresponding foreign server is specified with <option>&#45;-include-foreign-data</option>. このオプションは、テーブルだけでなく、ビュー、マテリアライズドビュー、外部テーブル、シーケンスの定義をダンプするのにも使えます。 ビューやマテリアライズドビューの内容はダンプしませんし、対応する外部サーバに--include-foreign-dataが指定されている場合にのみ、外部テーブルの内容がダンプされます。

The <option>-n</option> and <option>-N</option> switches have no effect when <option>-t</option> is used, because tables selected by <option>-t</option> will be dumped regardless of those switches, and non-table objects will not be dumped. -tが使用されると、-nおよび-Nオプションの効果はなくなります。 -tで選択したテーブルが、これらのオプションとは関係なくダンプされ、また、非テーブルオブジェクトはダンプされないためです。

注記

When <option>-t</option> is specified, <application>pg_dump</application> makes no attempt to dump any other database objects that the selected table(s) might depend upon. Therefore, there is no guarantee that the results of a specific-table dump can be successfully restored by themselves into a clean database. -tが指定されると、pg_dumpは選択したテーブル内のオブジェクトが依存する可能性がある他のデータベースオブジェクトのダンプを行いません。 したがって、テーブル指定のダンプ結果を初期化されたデータベースに正常にリストアできるという保証はありません。

-T pattern
--exclude-table=pattern

Do not dump any tables matching <replaceable class="parameter">pattern</replaceable>. The pattern is interpreted according to the same rules as for <option>-t</option>. <option>-T</option> can be given more than once to exclude tables matching any of several patterns. patternにマッチするテーブルをダンプしません。 このパターンは-tと同じ規則に従って解釈されます。 -Tを複数指定することで、複数のパターンのいずれかにマッチするテーブルをすべて除外させることができます。

When both <option>-t</option> and <option>-T</option> are given, the behavior is to dump just the tables that match at least one <option>-t</option> switch but no <option>-T</option> switches. If <option>-T</option> appears without <option>-t</option>, then tables matching <option>-T</option> are excluded from what is otherwise a normal dump. -t-Tの両方が指定された場合、少なくとも1つの-tオプションにマッチし、-Tオプションにマッチしないテーブルのみがダンプされます。 -tなしで-Tが指定された場合、通常のダンプから-Tにマッチするテーブルが除外されます。

-v
--verbose

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

-V
--version

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

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

Prevent dumping of access privileges (grant/revoke commands). アクセス権限(grant/revokeコマンド)のダンプを抑制します。

-Z level
-Z method[:detail]
--compress=level
--compress=method[:detail]

Specify the compression method and/or the compression level to use. The compression method can be set to <literal>gzip</literal>, <literal>lz4</literal>, <literal>zstd</literal>, or <literal>none</literal> for no compression. A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <literal>keyword</literal> or <literal>keyword=value</literal>. Currently, the supported keywords are <literal>level</literal> and <literal>long</literal>. 使用する圧縮の手法または圧縮レベル、あるいはその両方を指定します。 圧縮の手法は、gziplz4zstdに設定できます。非圧縮の場合はnoneです。 圧縮の詳細文字列は、オプションで指定できます。 詳細文字列が整数の場合は、圧縮レベルを指定します。 それ以外の場合は、keywordまたはkeyword=valueの形式のカンマで区切られた項目リストにします。 現在サポートされているキーワードは、levellongです。

If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <literal>gzip</literal> compression will be used if the level is greater than <literal>0</literal>, and no compression will be used if the level is <literal>0</literal>. 圧縮レベルが指定されていない場合、デフォルトの圧縮レベルが使用されます。 アルゴリズムを指定せずにレベルのみを指定した場合、レベルが0より大きい場合はgzip圧縮が使用され、レベルが0の場合は圧縮が使用されません。

For the custom and directory archive formats, this specifies compression of individual table-data segments, and the default is to compress using <literal>gzip</literal> at a moderate level. For plain text output, setting a nonzero compression level causes the entire output file to be compressed, as though it had been fed through <application>gzip</application>, <application>lz4</application>, or <application>zstd</application>; but the default is not to compress. With zstd compression, <literal>long</literal> mode may improve the compression ratio, at the cost of increased memory use. カスタムおよびディレクトリアーカイブ形式では、これは個々のテーブルデータセグメントの圧縮を指定するもので、デフォルトではgzipを使って中間レベルで圧縮されます。 平文出力では、非ゼロの圧縮レベルの指定によりあたかもgziplz4zstdに渡されたかのように出力ファイル全体が圧縮されます。 しかしデフォルトは圧縮無しです。 zstd圧縮では、longモードは、メモリ使用の増加という犠牲を払いますが、圧縮率を改善するかもしれません。

The tar archive format currently does not support compression at all. tarアーカイブ形式では現在圧縮を全くサポートしていません。

--binary-upgrade

This option is for use by in-place upgrade utilities. Its use for other purposes is not recommended or supported. The behavior of the option may change in future releases without notice. このオプションは現位置でのアップグレード用のユーティリティにより使用されるものです。 他の目的での使用は推奨されませんし、サポートもされません。 このオプションの動作は、将来通知することなく変更される可能性があります。

--column-inserts
--attribute-inserts

Dump data as <command>INSERT</command> commands with explicit column names (<literal>INSERT INTO <replaceable>table</replaceable> (<replaceable>column</replaceable>, ...) VALUES ...</literal>). This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non-<productname>PostgreSQL</productname> databases. Any error during restoring will cause only rows that are part of the problematic <command>INSERT</command> to be lost, rather than the entire table contents. 明示的に列名を付けたINSERTコマンド(INSERT INTO table (column, ...)VALUES...)としてデータをダンプします。 これによりリストアは非常に遅くなります。 主にPostgreSQL以外のデータベースへロード可能なダンプを作成する時に有用です。 リストア中のエラーでは、テーブルの内容がまるごと失われることはなく、問題のあるINSERTの一部の行が失われるだけです。

--disable-dollar-quoting

This option disables the use of dollar quoting for function bodies, and forces them to be quoted using SQL standard string syntax. このオプションは、関数本体用のドル引用符の使用を無効にし、強制的に標準SQLの文字列構文を使用した引用符付けを行います。

--disable-triggers

This option is relevant only when creating a data-only dump. It instructs <application>pg_dump</application> to include 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_dumpに指示します。 このオプションは、データのリストア中には呼び出したくない参照整合性検査やその他のトリガがテーブル上にある場合に使用します。

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 be careful to start the resulting script as a superuser. 現在のところ、--disable-triggersに対応するコマンドを実行するのは、スーパーユーザでなければなりません。 そのため、-Sでスーパーユーザの名前を指定するか、あるいは、可能であれば、スーパーユーザ権限でスクリプトを開始するよう注意する必要があります。

This option is ignored when emitting an archive (non-text) output file. For the archive formats, you can specify the option when you call <command>pg_restore</command>. このオプションはアーカイブ(テキストでない)出力ファイルを出力する場合には無視されます。 アーカイブ形式では、pg_restoreを呼び出す時にこのオプションを指定できます。

--enable-row-security

This option is relevant only when dumping the contents of a table which has row security. By default, <application>pg_dump</application> will set <xref linkend="guc-row-security"/> to off, to ensure that all data is dumped from the table. If the user does not have sufficient privileges to bypass row security, then an error is thrown. This parameter instructs <application>pg_dump</application> to set <xref linkend="guc-row-security"/> to on instead, allowing the user to dump the parts of the contents of the table that they have access to. このオプションは、行セキュリティのあるテーブルの内容をダンプするときにのみ意味を持ちます。 デフォルトでは、pg_dumprow_securityをoffに設定し、テーブルからすべてのデータがダンプされるようにします。 ユーザが行セキュリティを無視できるだけの十分な権限を持っていない場合、エラーが発生します。 このパラメータはpg_dumprow_securityをonに設定するようにすることで、テーブルの内容のうち、ユーザがアクセスできる部分をダンプすることを可能にします。

Note that if you use this option currently, you probably also want the dump be in <command>INSERT</command> format, as the <command>COPY FROM</command> during restore does not support row security. リストア時のCOPY FROMが行セキュリティをサポートしていないので、今、このオプションを使う場合は、ダンプをINSERT形式にするのがおそらく望ましいでしょう。

--exclude-table-and-children=pattern

This is the same as the <option>-T</option>/<option>&#45;-exclude-table</option> option, except that it also excludes any partitions or inheritance child tables of the table(s) matching the <replaceable class="parameter">pattern</replaceable>. これは-T/--exclude-tableオプションと同じですが、patternにマッチするパーティションや継承の子テーブルもすべて除外する点が異なります。

--exclude-table-data=pattern

Do not dump data for any tables matching <replaceable class="parameter">pattern</replaceable>. The pattern is interpreted according to the same rules as for <option>-t</option>. <option>&#45;-exclude-table-data</option> can be given more than once to exclude tables matching any of several patterns. This option is useful when you need the definition of a particular table even though you do not need the data in it. patternにマッチするすべてのテーブルのデータをダンプしません。 パターンは-t用の規則と同じ規則にしたがって解釈されます。 複数のパターンのいずれかにマッチするテーブルを除外することができるように、--exclude-table-dataを複数回与えることができます。 このオプションは、特定のテーブルに関してデータを格納する必要はないがテーブル定義は必要である場合に有用です。

To exclude data for all tables in the database, see <option>&#45;-schema-only</option>. データベース内のすべてのテーブルに関してデータを除外するためには、--schema-onlyを参照してください。

--exclude-table-data-and-children=pattern

This is the same as the <option>&#45;-exclude-table-data</option> option, except that it also excludes data of any partitions or inheritance child tables of the table(s) matching the <replaceable class="parameter">pattern</replaceable>. これは--exclude-table-dataオプションと同じですが、patternにマッチするパーティションや継承の子テーブルのデータも除外する点が異なります。

--extra-float-digits=ndigits

Use the specified value of <option>extra_float_digits</option> when dumping floating-point data, instead of the maximum available precision. Routine dumps made for backup purposes should not use this option. 浮動小数点データをダンプする時に、利用できる最大の精度の代わりに、extra_float_digitsで指定された値を使います。 バックアップ目的で作られたダンプルーチンは、このオプションを使うべきではありません。

--if-exists

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

--include-foreign-data=foreignserver

Dump the data for any foreign table with a foreign server matching <replaceable class="parameter">foreignserver</replaceable> pattern. Multiple foreign servers can be selected by writing multiple <option>&#45;-include-foreign-data</option> switches. Also, the <replaceable class="parameter">foreignserver</replaceable> parameter is interpreted as a pattern according to the same rules used by <application>psql</application>'s <literal>\d</literal> commands (see <xref linkend="app-psql-patterns"/>), so multiple foreign servers can also be selected by writing wildcard characters in the pattern. When using wildcards, be careful to quote the pattern if needed to prevent the shell from expanding the wildcards; see <xref linkend="pg-dump-examples"/> below. The only exception is that an empty pattern is disallowed. foreignserverパターンとマッチする外部サーバの外部テーブルのデータをダンプします。 複数の--include-foreign-dataスイッチを書くことで、複数の外部サーバを選択できます。 また、foreignserverパラメータはpsql\dコマンドで使われているのと同じ規則に従うパターンとして解釈されます(パターンを参照してください)ので、パターンにワイルドカード文字を書くことで複数の外部サーバを選択することもできます。 ワイルドカードを使う時は、シェルがワイルドカードを展開しないよう必要ならパターンを引用符で囲むことに注意してください。下記のを参照してください。 唯一の例外は空のパターンが許されていないことです。

注記

When <option>&#45;-include-foreign-data</option> is specified, <application>pg_dump</application> does not check that the foreign table is writable. Therefore, there is no guarantee that the results of a foreign table dump can be successfully restored. --include-foreign-dataが指定された場合、pg_dumpは外部テーブルが書き込み可能かどうか確認しません。 そのため、外部テーブルのダンプの結果をリストアするのに成功する保証はありません。

--inserts

Dump data as <command>INSERT</command> commands (rather than <command>COPY</command>). This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non-<productname>PostgreSQL</productname> databases. Any error during restoring will cause only rows that are part of the problematic <command>INSERT</command> to be lost, rather than the entire table contents. Note that the restore might fail altogether if you have rearranged column order. The <option>&#45;-column-inserts</option> option is safe against column order changes, though even slower. データを(COPYではなく)INSERTコマンドの形式でダンプします。 これを行うとリストアに非常に時間がかかります。 主にPostgreSQL以外のデータベースへロード可能なダンプを作成する時に有用です。 リストア中のエラーでは、テーブルの内容がまるごと失われることはなく、問題のあるINSERTの一部の行が失われるだけです。 列の順序を変更した場合はリストアが失敗する可能性があることに注意してください。 --column-insertsはさらに処理が遅くなりますが、列の順序変更に対して安全です。

--load-via-partition-root

When dumping data for a table partition, make the <command>COPY</command> or <command>INSERT</command> statements target the root of the partitioning hierarchy that contains it, rather than the partition itself. This causes the appropriate partition to be re-determined for each row when the data is loaded. This may be useful when restoring data on a server where rows do not always fall into the same partitions as they did on the original server. That could happen, for example, if the partitioning column is of type text and the two systems have different definitions of the collation used to sort the partitioning column. テーブルパーティションのデータをダンプするときには、COPYあるいはINSERT文の対象を、そのパーティションではなく、それを含むパーティション階層のルートにします。 これにより、データが読み込まれるときに各行に対して適切なパーティションが再判断されます。 これは行が元のサーバ上と同じパーティションに必ずしも落ちないようなサーバ上にデータを再読み込みするときに有用でしょう。 例えば、パーティション列がtext型で二つのシステムがパーティション列のソートで使われる照合順序の異なる定義を持っている場合に、これはあり得ます。

--lock-wait-timeout=timeout

Do not wait forever to acquire shared table locks at the beginning of the dump. Instead fail if unable to lock a table within the specified <replaceable class="parameter">timeout</replaceable>. The timeout may be specified in any of the formats accepted by <command>SET statement_timeout</command>. (Allowed formats vary depending on the server version you are dumping from, but an integer number of milliseconds is accepted by all versions.) ダンプの開始時に共有テーブルのロックを永遠に待ちません。 代わりに指定したtimeout内にテーブルロックを獲得できなければ失敗します。 タイムアウトはSET statement_timeoutで受け付けられる任意の書式で指定できます。 (使用可能な形式はダンプの元となるサーバのバージョンに依存して異なりますが、すべてのバージョンにおいてミリ秒単位の整数値は受け付けられます。)

--no-comments

Do not dump comments. コメントをダンプしません。

--no-publications

Do not dump publications. パブリケーションをダンプしません。

--no-security-labels

Do not dump security labels. セキュリティラベルをダンプしません。

--no-subscriptions

Do not dump subscriptions. サブスクリプションをダンプしません。

--no-sync

By default, <command>pg_dump</command> will wait for all files to be written safely to disk. This option causes <command>pg_dump</command> to return without waiting, which is faster, but means that a subsequent operating system crash can leave the dump corrupt. Generally, this option is useful for testing but should not be used when dumping data from production installation. デフォルトでは、pg_dumpはすべてのファイルが確実にディスクに書き出されるまで待機します。 このオプションを使うとpg_dumpは待機せずに戻るため、より高速になりますが、これは、その後にオペレーティングシステムがクラッシュすると、ダンプが破損する可能性があることを意味します。 一般的に言って、このオプションはテスト用には有用ですが、実運用の環境からデータをダンプするときには使用しない方が良いでしょう。

--no-table-access-method

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

This option is ignored when emitting an archive (non-text) output file. For the archive formats, you can specify the option when you call <command>pg_restore</command>. このオプションはアーカイブ(テキストでない)出力ファイルを出力する場合には無視されます。 アーカイブ形式では、pg_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. テーブル空間を選択するコマンドを出力しません。 このオプションを使用すると、すべてのオブジェクトはリストア時のデフォルトのテーブル空間の中に作成されます。

This option is ignored when emitting an archive (non-text) output file. For the archive formats, you can specify the option when you call <command>pg_restore</command>. このオプションはアーカイブ(テキストでない)出力ファイルを出力する場合には無視されます。 アーカイブ形式では、pg_restoreを呼び出す時にこのオプションを指定できます。

--no-toast-compression

Do not output commands to set <acronym>TOAST</acronym> compression methods. With this option, all columns will be restored with the default compression setting. TOAST圧縮手法を設定するコマンドを出力しません。 このオプションにより、列はすべてデフォルトの圧縮の設定でリストアされます。

--no-unlogged-table-data

Do not dump the contents of unlogged tables and sequences. This option has no effect on whether or not the table and sequence definitions (schema) are dumped; it only suppresses dumping the table and sequence data. Data in unlogged tables and sequences is always excluded when dumping from a standby server. ログを取らないテーブルとシーケンスの内容をダンプしません。 このオプションはテーブルとシーケンスの定義(スキーマ)をダンプするかどうかには影響しません。 そのテーブルとシーケンスのデータのダンプを抑制するだけです。 スタンバイサーバからダンプを行う場合、ログを取らないテーブルとシーケンス内のデータは常に除外されます。

--on-conflict-do-nothing

Add <literal>ON CONFLICT DO NOTHING</literal> to <command>INSERT</command> commands. This option is not valid unless <option>&#45;-inserts</option>, <option>&#45;-column-inserts</option> or <option>&#45;-rows-per-insert</option> is also specified. INSERTコマンドにON CONFLICT DO NOTHINGを追加します。 このオプションは、--inserts--column-insertsまたは--rows-per-insertが同時に指定されていなければ、有効ではありません。

--quote-all-identifiers

Force quoting of all identifiers. This option is recommended when dumping a database from a server whose <productname>PostgreSQL</productname> major version is different from <application>pg_dump</application>'s, or when the output is intended to be loaded into a server of a different major version. By default, <application>pg_dump</application> quotes only identifiers that are reserved words in its own major version. This sometimes results in compatibility issues when dealing with servers of other versions that may have slightly different sets of reserved words. Using <option>&#45;-quote-all-identifiers</option> prevents such issues, at the price of a harder-to-read dump script. 強制的にすべての識別子に引用符を付与します。 このオプションは、pg_dumpのメジャーバージョンとは異なるメジャーバージョンのPostgreSQLのサーバーからデータベースをダンプするとき、あるいは出力を異なるメジャーバージョンのサーバにロードする予定であるときに推奨されます。 デフォルトでは、pg_dumpは、それ自身のメジャーバージョンにおける予約語である識別子に対してのみ引用符を付与します。 これは、他のバージョンのサーバを処理するときに互換性の問題を引き起こす場合があります。 他のバージョンのサーバでは予約語の集合が多少、異なる場合があるからです。 --quote-all-identifiersを使用することで、ダンプのスクリプトが読みにくくなりますが、このような問題を防ぐことができます。

--rows-per-insert=nrows

Dump data as <command>INSERT</command> commands (rather than <command>COPY</command>). Controls the maximum number of rows per <command>INSERT</command> command. The value specified must be a number greater than zero. Any error during restoring will cause only rows that are part of the problematic <command>INSERT</command> to be lost, rather than the entire table contents. (COPYではなく)INSERTコマンドでデータをダンプします。 INSERTコマンド1つあたりの最大行数を制御します。 指定する値は0より大きくなければなりません。 リストア中のエラーでは、テーブルの内容がまるごと失われることはなく、問題のあるINSERTの一部の行が失われるだけです。

--section=sectionname

Only dump 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 dump all sections. 指定した部分のみをダンプします。 部分名はpre-datadatapost-dataのいずれかを取ることができます。 複数の部分を選択するために、このオプションは複数回指定することができます。 デフォルトではすべての部分をダンプします。

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

--serializable-deferrable

Use a <literal>serializable</literal> transaction for the dump, to ensure that the snapshot used is consistent with later database states; but do this by waiting for a point in the transaction stream at which no anomalies can be present, so that there isn't a risk of the dump failing or causing other transactions to roll back with a <literal>serialization_failure</literal>. See <xref linkend="mvcc"/> for more information about transaction isolation and concurrency control. 使用されるスナップショットがその後のデータベース状態と一貫性を持つことを保証するために、ダンプ時にserializableトランザクションを使用します。 ダンプが失敗したり、serialization_failureにより他のトランザクションがロールバックしたりする危険がないように、トランザクションストリーム内で異常が発生することがない時点まで待つことでこれを行います。 トランザクション分離および同時実行性の制御については第13章を参照してください。

This option is not beneficial for a dump which is intended only for disaster recovery. It could be useful for a dump used to load a copy of the database for reporting or other read-only load sharing while the original database continues to be updated. Without it the dump may reflect a state which is not consistent with any serial execution of the transactions eventually committed. For example, if batch processing techniques are used, a batch may show as closed in the dump without all of the items which are in the batch appearing. このオプションは障害対策のリカバリのみを目的とするダンプでは利点はありません。 元のデータベースを継続して更新しながら、レポート処理や他の読み取りのみの負荷分散のためにデータベースのコピーをロードするために使用されるダンプとして有用になります。 こうしないと、ダンプには 何らかのトランザクションの直列実行が最終的にコミットされた状態と一貫性がない状態が反映される可能性があります。 例えば、バッチ処理技術が使用される場合、 バッチは、バッチ内で存在するすべての項目を持たないダンプ内でクローズしたものと表示される可能性があります。

This option will make no difference if there are no read-write transactions active when pg_dump is started. If read-write transactions are active, the start of the dump may be delayed for an indeterminate length of time. Once running, performance with or without the switch is the same. pg_dumpを始めた時に読み書きを行う実行中のトランザクションが存在しない場合、このオプションは何の差異ももたらしません。 読み書きを行うトランザクションが実行中の場合、確定できない期間、ダンプの起動が遅延される可能性があります。 動き出してからの性能は、このスイッチがある場合とない場合とで違いはありません。

--snapshot=snapshotname

Use the specified synchronized snapshot when making a dump of the database (see <xref linkend="functions-snapshot-synchronization-table"/> for more details). データベースのダンプを作成する時に、指定した同期スナップショットを使用します (詳しくは表 9.94を参照して下さい)。

This option is useful when needing to synchronize the dump with a logical replication slot (see <xref linkend="logicaldecoding"/>) or with a concurrent session. このオプションは、ダンプを論理レプリケーションスロット(第49章参照)あるいは同時実行セッションと同期させる必要がある時に役に立ちます。

In the case of a parallel dump, the snapshot name defined by this option is used rather than taking a new snapshot. 並行ダンプの場合、新しいスナップショットを作る代わりに、このオプションで指定されたスナップショット名が使われます。

--strict-names

Require that each extension (<option>-e</option>/<option>&#45;-extension</option>), schema (<option>-n</option>/<option>&#45;-schema</option>) and table (<option>-t</option>/<option>&#45;-table</option>) pattern match at least one extension/schema/table in the database to be dumped. Note that if none of the extension/schema/table patterns find matches, <application>pg_dump</application> will generate an error even without <option>&#45;-strict-names</option>. 各拡張(-e/--extension)、各スキーマ(-n/--schema)および各テーブル(-t/--table)が、パターンがダンプされるデータベース内の少なくとも1つの拡張、スキーマおよびテーブルにマッチすることを必要とします。 拡張、スキーマおよびテーブルのパターンのどれもがマッチするものを見つけられなかった場合は、--strict-namesがなくてもpg_dumpはエラーを発生させることに注意して下さい。

This option has no effect on <option>-N</option>/<option>&#45;-exclude-schema</option>, <option>-T</option>/<option>&#45;-exclude-table</option>, or <option>&#45;-exclude-table-data</option>. An exclude pattern failing to match any objects is not considered an error. このオプションは-N/--exclude-schema-T/--exclude-table--exclude-table-dataには影響を与えません。 除外のパターンがマッチするオブジェクトを見つけられないことは、エラーとはみなされません。

--table-and-children=pattern

This is the same as the <option>-t</option>/<option>&#45;-table</option> option, except that it also includes any partitions or inheritance child tables of the table(s) matching the <replaceable class="parameter">pattern</replaceable>. これは-t/--tableオプションと同じですが、patternにマッチするテーブルのパーティションや継承の子テーブルもすべて含まれる点が異なります。

--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. Also, a dump using <command>SET SESSION AUTHORIZATION</command> will certainly require superuser privileges to restore correctly, whereas <command>ALTER OWNER</command> requires lesser privileges. オブジェクトの所有権を決定するために、ALTER OWNERコマンドの代わりに標準SQLのSET SESSION AUTHORIZATIONコマンドを出力します。 これにより、ダンプの標準への互換性が高まりますが、ダンプ内のオブジェクトの履歴によっては正しくリストアされない可能性が生じます。 また、SET SESSION AUTHORIZATIONを使用したダンプを正しくリストアするためには、確実にスーパーユーザ権限が必要となります。 ALTER OWNERで必要な権限はこれよりも少なくなります。

-?
--help

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

The following command-line options control the database connection parameters. 以下のコマンドラインオプションは、データベース接続パラメータを制御します。

-d dbname
--dbname=dbname

Specifies the name of the database to connect to. This is equivalent to specifying <replaceable class="parameter">dbname</replaceable> as the first non-option argument on the command line. 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接続文字列でも構いません。 その場合、接続文字列パラメータは衝突するコマンドラインオプションに優先します。

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

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

--role=rolename

Specifies a role name to be used to create the dump. This option causes <application>pg_dump</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_dump</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 dumps to be made without violating the policy. ダンプを作成する際に使用するロール名を指定します。 このオプションによりpg_dumpはデータベースに接続した後にSET ROLE rolenameコマンドを発行するようになります。 認証に使用したユーザ(-Uで指定されたユーザ)がpg_dumpで必要とされる権限を持たないが、必要な権限を持つロールに切り替えることができる場合に有用です。 一部のインストレーションではスーパーユーザとして直接ログインさせないポリシーを取ることがありますが、このオプションを使用することでポリシーに反することなくダンプを作成することができます。

環境

<title>Environment</title>
PGDATABASE
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"/>). また、このユーティリティは、他のほとんどのPostgreSQLユーティリティと同様、libpqでサポートされる環境変数を使用します(34.15を参照してください)。

診断

<title>Diagnostics</title>

<application>pg_dump</application> internally executes <command>SELECT</command> statements. If you have problems running <application>pg_dump</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. pg_dumpは内部でSELECT文を実行します。 pg_dumpの実行時に問題が発生する場合は、psqlなどを使用して、そのデータベースから情報をselectできることを確認してください。 また、libpqフロントエンドライブラリで使用されるデフォルトの接続設定や環境変数も適用されます。

The database activity of <application>pg_dump</application> is normally collected by the cumulative statistics system. If this is undesirable, you can set parameter <varname>track_counts</varname> to false via <envar>PGOPTIONS</envar> or the <literal>ALTER USER</literal> command. 通常pg_dumpのデータベースに対する活動は累積された統計情報システムにより収集されます。 これを望まない場合、PGOPTIONSまたはALTER USERコマンドを使用してtrack_countsパラメータを偽に設定してください。

注釈

<title>Notes</title>

If your database cluster has any local additions to the <literal>template1</literal> database, be careful to restore the output of <application>pg_dump</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_dumpの出力は、確実に空のデータベースにリストアするように注意してください。 そうしないと、おそらく追加されたオブジェクトの重複定義によってエラーが発生します。 独自の追加が反映されていない空のデータベースを作成するには、template1ではなくtemplate0をコピーしてください。 以下に例を示します。

CREATE DATABASE foo WITH TEMPLATE template0;

When a data-only dump is chosen and the option <option>&#45;-disable-triggers</option> is used, <application>pg_dump</application> emits commands to disable triggers on user tables before inserting the data, and then 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_dumpはデータを挿入する前にユーザテーブルにトリガを無効にするコマンドを発行し、データの挿入が完了した後で、それらを再び有効にする問い合わせを発行します。 リストアが途中で停止した場合、システムカタログが不適切な状態のままになっている可能性があります。

The dump file produced by <application>pg_dump</application> does not contain the statistics used by the optimizer to make query planning decisions. Therefore, it is wise to run <command>ANALYZE</command> after restoring from a dump file to ensure optimal performance; see <xref linkend="vacuum-for-statistics"/> and <xref linkend="autovacuum"/> for more information. pg_dumpが生成するダンプファイルには、オプティマイザが問い合わせ計画を決定する際に使用される統計情報が含まれていません。 そのため、最適な性能を発揮するために、ダンプファイルからリストアした後でANALYZEを実行することをお勧めします。 詳しくは25.1.3および25.1.6を参照してください。

Because <application>pg_dump</application> is used to transfer data to newer versions of <productname>PostgreSQL</productname>, the output of <application>pg_dump</application> can be expected to load into <productname>PostgreSQL</productname> server versions newer than <application>pg_dump</application>'s version. <application>pg_dump</application> can also dump from <productname>PostgreSQL</productname> servers older than its own version. (Currently, servers back to version 9.2 are supported.) However, <application>pg_dump</application> cannot dump from <productname>PostgreSQL</productname> servers newer than its own major version; it will refuse to even try, rather than risk making an invalid dump. Also, it is not guaranteed that <application>pg_dump</application>'s output can be loaded into a server of an older major version &mdash; not even if the dump was taken from a server of that version. Loading a dump file into an older server may require manual editing of the dump file to remove syntax not understood by the older server. Use of the <option>&#45;-quote-all-identifiers</option> option is recommended in cross-version cases, as it can prevent problems arising from varying reserved-word lists in different <productname>PostgreSQL</productname> versions. pg_dumpは新しいバージョンのPostgreSQLへのデータ移行に使用されますので、pg_dumpの出力はpg_dumpのバージョンより新しいバージョンのPostgreSQLデータベースへロード可能と想定できるようになっています。 また、pg_dumpは自身より古いバージョンのPostgreSQLデータベースを読み取ることもできます。 (現在はバージョン9.2までのサーバをサポートします。) しかし、pg_dumpはそれ自身のメジャーバージョンより新しいPostgreSQLサーバのダンプを取ることはできません。 無効なダンプを作成するリスクは取らず、ダンプしようとさえしません。 また、pg_dumpの出力がメジャーバージョンが古いサーバにロードできるとは、たとえ同じバージョンのサーバから取得したダンプであっても、保証されていません。 より古いサーバへのダンプファイルのロードには、古いサーバでは理解できない構文を削除するために、ダンプファイルの手作業による修正が必要になることがあります。 バージョンをまたがる場合は--quote-all-identifiersオプションの使用が推奨されます。 これにより、PostgreSQLの異なるバージョンで、予約語のリストが変わることによって発生する問題を防ぐことができるからです。

When dumping logical replication subscriptions, <application>pg_dump</application> will generate <command>CREATE SUBSCRIPTION</command> commands that use the <literal>connect = false</literal> option, so that restoring the subscription does not make remote connections for creating a replication slot or for initial table copy. That way, the dump can be restored without requiring network access to the remote servers. It is then up to the user to reactivate the subscriptions in a suitable way. If the involved hosts have changed, the connection information might have to be changed. It might also be appropriate to truncate the target tables before initiating a new full table copy. If users intend to copy initial data during refresh they must create the slot with <literal>two_phase = false</literal>. After the initial sync, the <link linkend="sql-createsubscription-with-two-phase"><literal>two_phase</literal></link> option will be automatically enabled by the subscriber if the subscription had been originally created with <literal>two_phase = true</literal> option. 論理レプリケーションのサブスクリプションをダンプするとき、pg_dumpconnect = falseオプションを使用するCREATE SUBSCRIPTION生成するため、サブスクリプションのリストア時には、レプリケーションスロットの作成や初回のテーブルコピーのためのリモート接続が行われません。 このため、リモートサーバへのネットワーク接続を必要とせずにダンプをリストアできます。 その後でサブスクリプションを適切な方法で再有効化するのはユーザの責任です。 関連するホストが変更されたときは、接続情報も変更しなければならないかもしれません。 新しく完全なテーブルコピーを開始する前に、コピー先のテーブルを空にするのが適切なこともあります。 ユーザーがリフレッシュ中に最初のデータをコピーする場合は、two_phase = falseを使用してスロットを作成する必要があります。 最初の同期後、サブスクリプションがtwo_phase = trueオプションを使用して最初に作成された場合は、two_phaseオプションがサブスクライバーによって自動的に有効になります。

<refsect1 id="pg-dump-examples" xreflabel="Examples"> <title>Examples</title>

To dump a database called <literal>mydb</literal> into an SQL-script file: mydbという名前のデータベースをSQLスクリプトファイルにダンプします。

$ pg_dump mydb > db.sql

To reload such a script into a (freshly created) database named <literal>newdb</literal>: newdbという名前の(新規に作成した)データベースにスクリプトを再ロードします。

$ psql -d newdb -f db.sql

To dump a database into a custom-format archive file: カスタム形式のアーカイブファイルにデータベースをダンプします。

$ pg_dump -Fc mydb > db.dump

To dump a database into a directory-format archive: ディレクトリ形式アーカイブにデータベースをダンプします。

$ pg_dump -Fd mydb -f dumpdir

To dump a database into a directory-format archive in parallel with 5 worker jobs: 5個の作業用ジョブを使用してデータベースをdirectory形式のアーカイブにダンプします。

$ pg_dump -Fd mydb -j 5 -f dumpdir

To reload an archive file into a (freshly created) database named <literal>newdb</literal>: newdbという名前の(新規に作成した)データベースにアーカイブファイルを再ロードします。

$ pg_restore -d newdb db.dump

To reload an archive file into the same database it was dumped from, discarding the current contents of that database: アーカイブファイルをダンプ元と同じデータベースに再ロードし、そのデータベースの現在の内容を捨てます。

$ pg_restore -d postgres --clean --create db.dump

To dump a single table named <literal>mytab</literal>: mytabという名前の単一のテーブルをダンプします。

$ pg_dump -t mytab mydb > db.sql

To dump all tables whose names start with <literal>emp</literal> in the <literal>detroit</literal> schema, except for the table named <literal>employee_log</literal>: detroitスキーマ内の名前がempで始まるすべてのテーブルをダンプします。 ただし、employee_logという名前のテーブルは除きます。

$ pg_dump -t 'detroit.emp*' -T detroit.employee_log mydb > db.sql

To dump all schemas whose names start with <literal>east</literal> or <literal>west</literal> and end in <literal>gsm</literal>, excluding any schemas whose names contain the word <literal>test</literal>: eastまたはwestで始まりgsmで終わるスキーマをすべてダンプします。 ただし、testという単語を含む場合は除きます。

$ pg_dump -n 'east*gsm' -n 'west*gsm' -N '*test*' mydb > db.sql

The same, using regular expression notation to consolidate the switches: 正規表現記法を使用してオプションをまとめた形で同じことを行います。

$ pg_dump -n '(east|west)*gsm' -N '*test*' mydb > db.sql

To dump all database objects except for tables whose names begin with <literal>ts_</literal>: ts_から始まる名前のテーブルを除き、すべてのデータベースオブジェクトをダンプします。

$ pg_dump -T 'ts_*' mydb > db.sql

To specify an upper-case or mixed-case name in <option>-t</option> and related switches, you need to double-quote the name; else it will be folded to lower case (see <xref linkend="app-psql-patterns"/>). But double quotes are special to the shell, so in turn they must be quoted. Thus, to dump a single table with a mixed-case name, you need something like 大文字または大文字小文字混在の名前を-tなどのスイッチに指定するには、名前を二重引用符で括らなければなりません。 さもないと小文字に変換されます(パターンを参照してください)。 しかし、二重引用符はシェルでも特別に扱われますので、これも引用符で括らなければなりません。 したがって、大文字小文字混在の名前を持つテーブルを1つダンプするには、以下のようにしなければなりません。

$ pg_dump -t "\"MixedCaseName\"" mydb > mytab.sql

関連項目

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