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

pg_basebackup

pg_basebackup <refpurpose>take a base backup of a <productname>PostgreSQL</productname> cluster</refpurpose> PostgreSQLクラスタのベースバックアップを取得する

概要

pg_basebackup [option...]

説明

<title>Description</title>

<application>pg_basebackup</application> is used to take a base backup of a running <productname>PostgreSQL</productname> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <xref linkend="continuous-archiving"/>) and as the starting point for a log-shipping or streaming-replication standby server (see <xref linkend="warm-standby"/>). pg_basebackupは、稼働中のPostgreSQLのデータベースクラスタのベースバックアップを取るために使用されます。 データベースへの他のクライアントに影響することなく、バックアップが取られます。 また、このバックアップはポイントインタイムリカバリ(26.3参照)とログシッピングやストリーミングレプリケーションスタンバイサーバ用の開始点(27.2参照)としても使用できます。

<application>pg_basebackup</application> makes an exact copy of the database cluster's files, while making sure the server is put into and out of backup mode automatically. Backups are always taken of the entire database cluster; it is not possible to back up individual databases or database objects. For selective backups, another tool such as <xref linkend="app-pgdump"/> must be used. pg_basebackupは、サーバをバックアップモードに入れ、また戻すことを自動的に確実に行ない、データベースクラスタファイルの厳密なコピーを作成します。 バックアップは常にデータベースクラスタ全体のバックアップを取ります。 個々のデータベースや個々のデータベースオブジェクトをバックアップすることはできません。 特定のものを対象としたバックアップに関してはpg_dumpなどの他のツールを使用しなければなりません。

The backup is made over a regular <productname>PostgreSQL</productname> connection that uses the replication protocol. The connection must be made with a user ID that has <literal>REPLICATION</literal> permissions (see <xref linkend="role-attributes"/>) or is a superuser, and <link linkend="auth-pg-hba-conf"><filename>pg_hba.conf</filename></link> must permit the replication connection. The server must also be configured with <xref linkend="guc-max-wal-senders"/> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used). バックアップは、レプリケーションプロトコルを用いる通常のPostgreSQL接続を経由して作成されます。 この接続はREPLICATION権限(22.2参照)を持つ、または、スーパーユーザであるユーザIDが確立しなければなりません。 さらにpg_hba.confでレプリケーション用の接続が許可されていなければなりません。 またサーバでmax_wal_sendersを、バックアップ用に少なくとも1つのwalsenderとWALストリーミング用にもう1つ(使用する場合)を残すように十分大きく設定する必要があります。

There can be multiple <command>pg_basebackup</command>s running at the same time, but it is usually better from a performance point of view to take only one backup, and copy the result. 同時にpg_basebackupを複数実行できます。 しかし性能の観点からは、1つのバックアップのみを取り結果をコピーする方が通常は優れています。

<application>pg_basebackup</application> can make a base backup from not only a primary server but also a standby. To take a backup from a standby, set up the standby so that it can accept replication connections (that is, set <varname>max_wal_senders</varname> and <xref linkend="guc-hot-standby"/>, and configure its <filename>pg_hba.conf</filename> appropriately). You will also need to enable <xref linkend="guc-full-page-writes"/> on the primary. pg_basebackupは、プライマリサーバからだけではなくスタンバイからもベースバックアップを作成できます。 スタンバイからバックアップを取得するためには、レプリケーション接続を受け付けられるようにスタンバイを設定してください(つまりmax_wal_sendershot_standbyを設定し、pg_hba.confを適切に設定してください)。 またプライマリでfull_page_writesを有効にする必要があります。

Note that there are some limitations in taking a backup from a standby: スタンバイからバックアップを取る場合にはいくつかの制限があることに注意してください。

  • The backup history file is not created in the database cluster backed up. バックアップ履歴ファイルはバックアップされるデータベースクラスタ内に作成されません。

  • <application>pg_basebackup</application> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <literal>-X none</literal>, if write activity on the primary is low, <application>pg_basebackup</application> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <function>pg_switch_wal</function> on the primary in order to trigger an immediate WAL file switch. pg_basebackupはバックアップの終了時に スタンバイに新しいWALファイルへの切り替えを強制することはできません。 -X noneの使用時にプライマリでの書き込みアクティビティが低い場合、 pg_basebackupはバックアップに必要な最後のWALファイルが 切り替わってアーカイブされるまで長時間待つ必要があるかもしれません。 このような場合、即時のWALファイル切り替えをトリガーするためにプライマリで pg_switch_walを実行するのがおそらく有用です。

  • If the standby is promoted to be primary during backup, the backup fails. バックアップ中にスタンバイがプライマリに昇格した場合、バックアップは失敗します。

  • All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <varname>full_page_writes</varname> on the primary. バックアップに必要なすべてのWALレコードは、必要なだけの完全ページ書き出しを含んでいなければなりません。 つまりこれは、プライマリでfull_page_writesを有効にすることが要求されます。

Whenever <application>pg_basebackup</application> is taking a base backup, the server's <structname>pg_stat_progress_basebackup</structname> view will report the progress of the backup. See <xref linkend="basebackup-progress-reporting"/> for details. pg_basebackupがベースバックアップを取るときには必ず、サーバのpg_stat_progress_basebackupはバックアップの進行状況を報告します。 詳細は28.4.6を参照してください。

オプション

<title>Options</title>

The following command-line options control the location and format of the output: 以下のコマンドラインオプションは出力の場所と書式を制御します。

-D directory
--pgdata=directory

Sets the target directory to write the output to. <application>pg_basebackup</application> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty. 出力を書き出す対象のディレクトリを設定します。 pg_basebackupは、存在していなければこのディレクトリ(とその親ディレクトリのうち存在していないものすべて)を作成します。 ディレクトリはすでに存在してもかまいませんが、空でなければなりません。

When the backup is in tar format, the target directory may be specified as <literal>-</literal> (dash), causing the tar file to be written to <literal>stdout</literal>. バックアップがtar形式であり、かつ、対象のディレクトリが-(ダッシュ)の場合、tarファイルをstdoutに書き出します。

This option is required. このオプションは必須です。

-F format
--format=format

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

p
plain

Write the output as plain files, with the same layout as the source server's data directory and tablespaces. When the cluster has no additional tablespaces, the whole database will be placed in the target directory. If the cluster contains additional tablespaces, the main data directory will be placed in the target directory, but all other tablespaces will be placed in the same absolute path as they have on the source server. (See <option>&#45;-tablespace-mapping</option> to change that.) 普通のファイルとして、ソースサーバのデータディレクトリとテーブル空間と同じレイアウトで、出力を書き出します。 クラスタがテーブル空間を追加で持たない場合、データベース全体が指定したディレクトリに格納されます。 クラスタが追加のテーブル空間を持つ場合は、主データディレクトリは指定したディレクトリ内に格納されますが、他のテーブル空間はすべて、ソースサーバ上と同じ絶対パスに格納されます。 (これを変更するには--tablespace-mappingを参照してください。)

This is the default format. これがデフォルトの書式です。

t
tar

Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <filename>base.tar</filename>, and each other tablespace will be written to a separate tar file named after that tablespace's OID. 指定したディレクトリ内にtarファイルとして出力を書き出します。 主データディレクトリの内容はbase.tarという名前のファイルに書き出され、他のテーブル空間はすべてテーブル空間のOIDに因んだ名前の別のtarファイルに書き出されます。

If the target directory is specified as <literal>-</literal> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <productname>gzip</productname>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used. 対象ディレクトリとして-(ダッシュ)という値が指定された場合、tarの内容は標準出力に書き出されます。 これは(例えば)gzipへのパイプ処理に適しています。 これはクラスタが追加テーブル空間を持たず、WALストリーミングを使用していない場合のみ行うことができます。

-R
--write-recovery-conf

Creates a <link linkend="file-standby-signal"><filename>standby.signal</filename></link> <indexterm><primary><filename>standby.signal</filename></primary><secondary>pg_basebackup &#45;-write-recovery-conf</secondary></indexterm> file and appends connection settings to the <filename>postgresql.auto.conf</filename> file in the target directory (or within the base archive file when using tar format). This eases setting up a standby server using the results of the backup. standby.signal を作成し、対象のディレクトリ(tar形式の場合はベースアーカイブファイルの中)にあるpostgresql.auto.confに接続設定を追加します。 これにより、バックアップの結果を利用するスタンバイサーバの設定が容易になります。

The <filename>postgresql.auto.conf</filename> file will record the connection settings and, if specified, the replication slot that <application>pg_basebackup</application> is using, so that streaming replication will use the same settings later on. postgresql.auto.confファイルは接続設定の情報、また、指定があればpg_basebackupが使用しているレプリケーションスロットの情報を記録するので、ストリーミングレプリケーションは後で同じ設定を使用します。

-t target
--target=target

Instructs the server where to place the base backup. The default target is <literal>client</literal>, which specifies that the backup should be sent to the machine where <application>pg_basebackup</application> is running. If the target is instead set to <literal>server:/some/path</literal>, the backup will be stored on the machine where the server is running in the <literal>/some/path</literal> directory. Storing a backup on the server requires superuser privileges or having privileges of the <literal>pg_write_server_files</literal> role. If the target is set to <literal>blackhole</literal>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. ベースバックアップを格納する場所をサーバに指示します。 デフォルトターゲットはclientです。これはpg_basebackupが実行されているマシンにバックアップが送信されるように指定します。 ターゲットがserver:/some/pathに設定されている場合、バックアップはサーバが実行されているマシンの/some/pathディレクトリに格納されます。 サーバにバックアップを格納するには、スーパーユーザ権限またはpg_write_server_filesロールの権限が必要です。 ターゲットがblackholeに設定されている場合、内容は破棄され、どこにも格納されません。 実際のバックアップは作成されないので、これはテスト目的でのみ使用してください。

Since WAL streaming is implemented by <application>pg_basebackup</application> rather than by the server, this option cannot be used together with <literal>-Xstream</literal>. Since that is the default, when this option is specified, you must also specify either <literal>-Xfetch</literal> or <literal>-Xnone</literal>. WALストリーミングはサーバではなくpg_basebackupによって実装されているため、このオプションは-Xstreamと一緒に使用することはできません。 それがデフォルトであるため、このオプションを指定する場合は-Xfetch-Xnoneも指定する必要があります。

-T olddir=newdir
--tablespace-mapping=olddir=newdir

Relocates the tablespace in directory <replaceable>olddir</replaceable> to <replaceable>newdir</replaceable> during the backup. To be effective, <replaceable>olddir</replaceable> must exactly match the path specification of the tablespace as it is defined on the source server. (But it is not an error if there is no tablespace in <replaceable>olddir</replaceable> on the source server.) Meanwhile <replaceable>newdir</replaceable> is a directory in the receiving host's filesystem. As with the main target directory, <replaceable>newdir</replaceable> need not exist already, but if it does exist it must be empty. Both <replaceable>olddir</replaceable> and <replaceable>newdir</replaceable> must be absolute paths. If either path needs to contain an equal sign (<literal>=</literal>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces. ディレクトリolddirにあるテーブル空間を、バックアップ中にnewdirに再配置します。 これが有効であるためには、olddirが、ソースサーバでのテーブル空間のパス定義と完全に一致している必要があります。 (ただし、ソースサーバのolddir内にテーブル空間がなくてもエラーにはなりません。) 一方、newdirは受け取るホストのファイルシステム内のディレクトリです。 主対象ディレクトリと同様に、newdirは既に存在している必要はありませんが、存在している場合には空でなければなりません。 olddirnewdirはいずれも絶対パスでなければなりません。 パス名に等号(=)を含む必要がある場合には、バックスラッシュをその前に付けてください。 このオプションは、複数のテーブル空間に対して複数回指定することができます。

If a tablespace is relocated in this way, the symbolic links inside the main data directory are updated to point to the new location. So the new data directory is ready to be used for a new server instance with all tablespaces in the updated locations. この方法でテーブル空間を再配置すると、メインのデータディレクトリ内のシンボリックリンクは、新しい場所を指すように更新されます。 このため、新しいデータディレクトリは、すべてのテーブル空間が更新された場所にあり、新しいサーバインスタンスがすぐに使える状態になっています。

Currently, this option only works with plain output format; it is ignored if tar format is selected. 現在、このオプションはplain出力形式でのみ機能します。tar形式が選択されている場合は無視されます。

--waldir=waldir

Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <filename>pg_wal</filename> subdirectory of the target directory, but this option can be used to place them elsewhere. <replaceable>waldir</replaceable> must be an absolute path. As with the main target directory, <replaceable>waldir</replaceable> need not exist already, but if it does exist it must be empty. This option can only be specified when the backup is in plain format. WAL(先行書き込みログ)ファイルを書き込むディレクトリを設定します。 デフォルトでは、WALファイルは対象のpg_walサブディレクトリに置かれますが、どこか他の場所に置くためにこのオプションが使えます。 waldirは絶対パスでなければなりません。 主対象ディレクトリと同様に、waldirは既に存在している必要はありませんが、存在している場合には空でなければなりません。 このオプションは、バックアップがplain形式の場合にのみ指定できます。

-X method
--wal-method=method

Includes the required WAL (write-ahead log) files in the backup. This will include all write-ahead logs generated during the backup. Unless the method <literal>none</literal> is specified, it is possible to start a postmaster in the target directory without the need to consult the WAL archive, thus making the output a completely standalone backup. 必要なWAL(先行書き込みログ)ファイルをバックアップに含めます。 これはバックアップ中に生成された先行書き込みログをすべて含みます。 方法noneを指定しない場合、WALアーカイブを考慮することなく展開した対象ディレクトリ内でpostmasterを起動することができます。 つまり出力は完全なスタンドアローンバックアップを作成します。

The following <replaceable>method</replaceable>s for collecting the write-ahead logs are supported: 以下の先行書き込みログを収集するためのmethodがサポートされます。

n
none

Don't include write-ahead logs in the backup. 先行書き込みログをバックアップに含めません。

f
fetch

The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <xref linkend="guc-wal-keep-size"/> parameter to be set high enough that the required log data is not removed before the end of the backup. If the required log data has been recycled before it's time to transfer it, the backup will fail and be unusable. 先行書き込みログファイルはバックアップの最後に収集されます。 したがって、ソースサーバのwal_keep_sizeパラメータを、バックアップの最後までログが削除されない程度に十分大きくする必要があります。 要求されるログデータが転送時点で再利用されていた場合、バックアップは失敗し、使用することができません。

When tar format is used, the write-ahead log files will be included in the <filename>base.tar</filename> file. tar形式が使われれば、先行書き込みログファイルはbase.tarファイルに含まれます。

s
stream

Stream write-ahead log data while the backup is being taken. This method will open a second connection to the server and start streaming the write-ahead log in parallel while running the backup. Therefore, it will require two replication connections not just one. As long as the client can keep up with the write-ahead log data, using this method requires no extra write-ahead logs to be saved on the source server. バックアップを取る時に先行書き込みログデータをストリームします。 この方法は第2のサーバ接続を開き、バックアップを実行している間、並行して先行書き込みログのストリーミングを始めます。 したがって、レプリケーション接続を、1つではなく2つ使用します。 クライアントが先行書き込みログデータに追従している限り、このモードを使用すれば、ソースサーバ上に余分に保管される先行書き込みログは必要ありません。

When tar format is used, the write-ahead log files will be written to a separate file named <filename>pg_wal.tar</filename> (if the server is a version earlier than 10, the file will be named <filename>pg_xlog.tar</filename>). tar形式が使われれば、先行書き込みログファイルはpg_wal.tarという名の別のファイルに書き込まれます(サーバが10より前のバージョンの場合、pg_xlog.tarというファイル名になります)。

This value is the default. この値がデフォルトです。

-z
--gzip

Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <filename>.gz</filename> will automatically be added to all tar filenames. tarファイル出力のデフォルトの圧縮レベルによるgzip圧縮を有効にします。 tarファイルを生成する場合のみ圧縮を利用することができ、すべてのtarファイルの名前に拡張子.gzが自動的に付加されます。

-Z level
-Z [{client|server}-]method[:detail]
--compress=level
--compress=[{client|server}-]method[:detail]

Requests compression of the backup. If <literal>client</literal> or <literal>server</literal> is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is <literal>client</literal> except when <literal>&#45;-target</literal> is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When <literal>-Xstream</literal>, which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify <literal>-Xfetch</literal>. バックアップの圧縮を要求します。 clientまたはserverが含まれている場合、それは圧縮を実行する場所を指定します。 サーバで圧縮すると、転送帯域幅が減少しますが、サーバのCPU消費が増加します。 デフォルトはclientですが、--targetを使用している場合は例外です。 その場合、バックアップはクライアントに送信されないため、サーバ圧縮のみが有効です。 デフォルトの-Xstreamが使用されている場合、サーバ側の圧縮はWALに適用されません。 WALを圧縮するには、クライアント側の圧縮を使用するか、-Xfetchを指定します。

The compression method can be set to <literal>gzip</literal>, <literal>lz4</literal>, <literal>zstd</literal>, <literal>none</literal> for no compression or an integer (no compression if 0, <literal>gzip</literal> if greater than 0). 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>, <literal>long</literal>, and <literal>workers</literal>. The detail string cannot be used when the compression method is specified as a plain integer. 圧縮方法は、gziplz4zstdで、圧縮しない場合はnoneに設定できます。また整数で設定できます(0なら圧縮しない、0より大きければgzip)。 オプションで圧縮の詳細文字列を指定できます。 詳細文字列が整数の場合は、圧縮レベルを指定します。 それ以外の場合は、keywordまたはkeyword=value形式のカンマ区切りの項目のリストにする必要があります。 現在サポートされているキーワードは、levellongおよびworkersです。 圧縮方法が単純な整数として指定されている場合、詳細文字列は使用できません。

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 0, and no compression will be used if the level is 0. 圧縮レベルが指定されていない場合、デフォルトの圧縮レベルが使用されます。 アルゴリズムを指定せずにレベルのみが指定されている場合、レベルが0より大きい場合はgzip圧縮が使用され、レベルが0の場合は圧縮が使用されません。

When the tar format is used with <literal>gzip</literal>, <literal>lz4</literal>, or <literal>zstd</literal>, the suffix <filename>.gz</filename>, <filename>.lz4</filename>, or <filename>.zst</filename>, respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. tar形式をgziplz4zstdとともに使用すると、接尾辞.gz.lz4.zstがそれぞれすべてのtarファイルに自動的に追加されます。 plain形式を使用する場合、クライアント側の圧縮は指定されない可能性がありますが、サーバ側の圧縮を要求することは可能です。 この場合、サーバは転送用にバックアップを圧縮し、クライアントは展開して抽出します。

When this option is used in combination with <literal>-Xstream</literal>, <literal>pg_wal.tar</literal> will be compressed using <literal>gzip</literal> if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected. このオプションを-Xstreamと組み合わせて使用すると、クライアント側のgzip圧縮が選択されている場合、pg_wal.targzipを使って圧縮されますが、他の圧縮アルゴリズムが選択されている場合やサーバ側の圧縮が選択されている場合は圧縮されません。

The following command-line options control the generation of the backup and the invocation of the program: 以下のコマンドラインオプションはバックアップの生成とこのプログラムの起動を制御します。

-c {fast|spread}
--checkpoint={fast|spread}

Sets checkpoint mode to fast (immediate) or spread (the default) (see <xref linkend="backup-lowlevel-base-backup"/>). チェックポイントモードをfast(即座に発行)またはspread(デフォルト)に設定します(26.3.3を参照してください)。

-C
--create-slot

Specifies that the replication slot named by the <literal>&#45;-slot</literal> option should be created before starting the backup. An error is raised if the slot already exists. バックアップ開始前に--slotオプションで名づけられたレプリケーションスロットを作成することを指定します。 スロットが既に存在する場合、エラーが生じます。

-l label
--label=label

Sets the label for the backup. If none is specified, a default value of <quote><literal>pg_basebackup base backup</literal></quote> will be used. バックアップのラベルを設定します。 何も指定がない場合、pg_basebackup base backupというデフォルト値が使用されます。

-n
--no-clean

By default, when <command>pg_basebackup</command> aborts with an error, it removes any directories it might have created before discovering that it cannot finish the job (for example, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging. デフォルトでは、pg_basebackupがエラーでアボートするとき、ジョブを完了できないことがわかるより前に作成したすべてのディレクトリ(例えば、対象のディレクトリと先行書き込みログのディレクトリ)を削除します。 このオプションはきれいに片付けることを禁止するので、デバッグのために有用です。

Note that tablespace directories are not cleaned up either way. テーブル空間のディレクトリはいずれにせよ削除されないことに注意してください。

-N
--no-sync

By default, <command>pg_basebackup</command> will wait for all files to be written safely to disk. This option causes <command>pg_basebackup</command> to return without waiting, which is faster, but means that a subsequent operating system crash can leave the base backup corrupt. Generally, this option is useful for testing but should not be used when creating a production installation. デフォルトではpg_basebackupは全てのファイルがディスクに安全に書き出されるのを待ちます。 このオプションでpg_basebackupは待つことなく返ります。これは高速ですが、その後のオペレーションシステムのクラッシュでベースバックアップの破損が残るかもしれないことを意味します。 一般にこのオプションはテスト用に有用なのであって、本番導入の際に使うべきではありません。

-P
--progress

Enables progress reporting. Turning this on will deliver an approximate progress report during the backup. Since the database may change during the backup, this is only an approximation and may not end at exactly <literal>100%</literal>. In particular, when WAL log is included in the backup, the total amount of data cannot be estimated in advance, and in this case the estimated target size will increase once it passes the total estimate without WAL. 進行状況報告を有効にします。 これを有効にすると、バックアップ中におおよその進行状況が報告されます。 データベースはバックアップ中に変更があるかもしれませんので、これはおおよそでしかなくちょうど100%では終わらないかもしれません。 特に、WALログがバックアップに含まれる場合、データ総量は前もって予測することはできません。 このためこの場合、推定対象容量はWALなしの総推定量を過ぎた後増加します。

-r rate
--max-rate=rate

Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <application>pg_basebackup</application> on the server. Values are in kilobytes per second. Use a suffix of <literal>M</literal> to indicate megabytes per second. A suffix of <literal>k</literal> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second. ソースサーバから収集されるデータの最大転送速度です。 これは、サーバでのpg_basebackupの影響を制限するのに有用です。 値は秒あたりのキロバイト数です。 添字Mを使うと秒あたりのメガバイト数を指定できます。 添字kを使うこともできますが、効果はありません。 有効な値は秒あたり32キロバイトから秒あたり1024メガバイトまでです。

This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <literal>fetch</literal>. このオプションはデータディレクトリの転送に対しては、常に影響があります。 WALファイルの転送については、収集方法がfetchの場合にのみ影響があります。

-S slotname
--slot=slotname

This option can only be used together with <literal>-X stream</literal>. It causes WAL streaming to use the specified replication slot. If the base backup is intended to be used as a streaming-replication standby using a replication slot, the standby should then use the same replication slot name as <xref linkend="guc-primary-slot-name"/>. This ensures that the primary server does not remove any necessary WAL data in the time between the end of the base backup and the start of streaming replication on the new standby. このオプションは-X streamと一緒でのみ使用できます。 これはWALストリーミングに指定したレプリケーションスロットを使用させます。 レプリケーションスロットを使うストリーミングレプリケーションのスタンバイとしてベースバックアップを使用するつもりであるなら、スタンバイはprimary_slot_nameと同じレプリケーションスロット名を使うべきです。 これにより、ベースバックアップ終了と新しいスタンバイでのストリーミングレプリケーション開始の間の時間にプライマリサーバが必要なWALデータを削除しないことが確実になります。

The specified replication slot has to exist unless the option <option>-C</option> is also used. 指定されたレプリケーションスロットは、オプション-Cも使われている場合を除き、存在していなければなりません。

If this option is not specified and the server supports temporary replication slots (version 10 and later), then a temporary replication slot is automatically used for WAL streaming. このオプションが指定されておらず、サーバが一時レプリケーションスロットに対応している(バージョン10以降)場合、WALストリーミングに対して一時レプリケーションスロットが自動的に使われます。

-v
--verbose

Enables verbose mode. Will output some extra steps during startup and shutdown, as well as show the exact file name that is currently being processed if progress reporting is also enabled. 冗長モードを有効にします。 開始時および終了段階でいくつか追加の段階が出力されます。 また進行状況報告も有効な場合、現在処理中のファイル名も正しく出力されます。

--manifest-checksums=algorithm

Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <literal>NONE</literal>, <literal>CRC32C</literal>, <literal>SHA224</literal>, <literal>SHA256</literal>, <literal>SHA384</literal>, and <literal>SHA512</literal>. The default is <literal>CRC32C</literal>. バックアップマニフェストに含まれる各ファイル適用されるチェックサムアルゴリズムを指定します。 現在利用できるアルゴリズムはNONECRC32CSHA224SHA256SHA384SHA512です。 デフォルトはCRC32Cです。

If <literal>NONE</literal> is selected, the backup manifest will not contain any checksums. Otherwise, it will contain a checksum of each file in the backup using the specified algorithm. In addition, the manifest will always contain a <literal>SHA256</literal> checksum of its own contents. The <literal>SHA</literal> algorithms are significantly more CPU-intensive than <literal>CRC32C</literal>, so selecting one of them may increase the time required to complete the backup. NONEが選択されれば、バックアップマニフェストはチェックサムを含みません。 それ以外の場合、バックアップ内の各ファイルの指定したアルゴリズムを使ったチェックサムを含みます。 さらに、マニフェストは自身の内容のSHA256チェックサムを常に含みます。 SHAアルゴリズムはCRC32CよりもかなりCPU集約的なため、そのどれかを1つを選択するとバックアップの完了に掛かる時間が増えるでしょう。

Using a SHA hash function provides a cryptographically secure digest of each file for users who wish to verify that the backup has not been tampered with, while the CRC32C algorithm provides a checksum that is much faster to calculate; it is good at catching errors due to accidental changes but is not resistant to malicious modifications. Note that, to be useful against an adversary who has access to the backup, the backup manifest would need to be stored securely elsewhere or otherwise verified not to have been modified since the backup was taken. SHAハッシュ関数を使うと、バックアップが変更されていないことを検証したい利用者にとっては暗号学的に安全な各ファイルのダイジェストが提供されますが、一方、CRC32Cアルゴリズムでは計算がずっと速いチェックサムが提供されます。偶発的な変更によるエラーを補足するのには良いですが、悪意のある修正に抵抗力はありません。 バックアップにアクセスした敵に対抗するのに有用なように、バックアップマニフェストは、どこか他のところに安全に保管するか、バックアップが取られて以来変更されたことがないのを検証する必要があることに注意してください。

<xref linkend="app-pgverifybackup"/> can be used to check the integrity of a backup against the backup manifest. pg_verifybackupを使ってバックアップマニフェストに対するバックアップの完全性を検査できます。

--manifest-force-encode

Forces all filenames in the backup manifest to be hex-encoded. If this option is not specified, only non-UTF8 filenames are hex-encoded. This option is mostly intended to test that tools which read a backup manifest file properly handle this case. バックアップマニフェスト内のファイル名をすべて強制的に16進数でエンコードします。 このオプションが指定されなければ、UTF8でないファイル名だけが16進数でエンコードされます。 このオプションは主に、バックアップマニフェストファイルを読むツールが、この場合を正しく扱うか試験することを意図しています。

--no-estimate-size

Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <structfield>backup_total</structfield> column in the <structname>pg_stat_progress_basebackup</structname> view always being <literal>NULL</literal>. ストリームされるバックアップデータの総量をサーバが評価しないようにします。その結果、pg_stat_progress_basebackupビューのbackup_total列は常にNULLになります。

Without this option, the backup will start by enumerating the size of the entire database, and then go back and send the actual contents. This may make the backup take slightly longer, and in particular it will take longer before the first data is sent. This option is useful to avoid such estimation time if it's too long. このオプションがなければ、バックアップはまずデータベース全体容量を計算し、その後バックアップに戻り、実際の内容を送信します。 これにより、バックアップに要する時間は少し長くなるかもしれません。特に最初のデータが送られるようになるまでの時間がより長くなります。 このオプションは、評価時間が長過ぎる場合にそれを避けるのに有用です。

This option is not allowed when using <option>&#45;-progress</option>. --progressを使う場合には、このオプションは認められません。

--no-manifest

Disables generation of a backup manifest. If this option is not specified, the server will generate and send a backup manifest which can be verified using <xref linkend="app-pgverifybackup"/>. The manifest is a list of every file present in the backup with the exception of any WAL files that may be included. It also stores the size, last modification time, and an optional checksum for each file. バックアップマニフェストを生成しないようにします。 このオプションが指定されなければ、サーバはpg_verifybackupを使って検証できるバックアップマニフェストを生成し送信します。 マニフェストは、含まれるかもしれないWALファイルを除いて、バックアップの中にある各ファイルの一覧です。 各ファイルの大きさや最終修正時刻、省略可能なチェックサムも保存されます。

--no-slot

Prevents the creation of a temporary replication slot for the backup. バックアップ時に一時レプリケーションスロットを作成しないようにします。

By default, if log streaming is selected but no slot name is given with the <option>-S</option> option, then a temporary replication slot is created (if supported by the source server). デフォルトでは、ログストリーミングが選択されたものの-Sオプションでスロット名が与えられなかった場合、(ソースサーバがサポートしていれば)一時レプリケーションスロットが作成されます。

The main purpose of this option is to allow taking a base backup when the server has no free replication slots. Using a replication slot is almost always preferred, because it prevents needed WAL from being removed by the server during the backup. このオプションの主な目的は、サーバにレプリケーションスロットの空きが無いときにベースバックアップを取得できるようにすることです。 レプリケーションスロットを使うことは、必要とされるWALがバックアップ中のサーバにより削除されることを防止するため、ほとんどの場合に好ましいです。

--no-verify-checksums

Disables verification of checksums, if they are enabled on the server the base backup is taken from. ベースバックアップ取得元のサーバでチェックサムの検証が有効になっている場合に、チェックサムの検証を無効化します。

By default, checksums are verified and checksum failures will result in a non-zero exit status. However, the base backup will not be removed in such a case, as if the <option>&#45;-no-clean</option> option had been used. Checksum verification failures will also be reported in the <link linkend="monitoring-pg-stat-database-view"> <structname>pg_stat_database</structname></link> view. デフォルトでは、チェックサムは検証され、チェックサムエラーは非ゼロの終了ステータスをもたらします。 とはいえ、このような場合には、--no-cleanオプションが使われていたかのように、ベースバックアップは削除されません。 チェックサム検証の失敗はpg_stat_databaseビューでも報告されます。

The following command-line options control the connection to the source server: 以下のオプションはソースサーバへの接続パラメータを制御します。

-d connstr
--dbname=connstr

Specifies parameters used to connect to the server, as a <link linkend="libpq-connstring">connection string</link>; these will override any conflicting command line options. サーバとの接続のために使用するパラメータを、接続文字列として指定します。 衝突するコマンドラインオプションよりも優先します。

The option is called <literal>&#45;-dbname</literal> for consistency with other client applications, but because <application>pg_basebackup</application> doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored. このオプションは他のクライアントアプリケーションとの整合性のために--dbnameと呼ばれます。 しかし、pg_basebackupはクラスタ内の何らかの特定のデータベースに接続しませんので、接続文字列内のデータベース名は無視されます。

-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 a 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の値となります。設定されていなければ、コンパイル時のデフォルト値となります。

-s interval
--status-interval=interval

Specifies the number of seconds between status packets sent back to the source server. Smaller values allow more accurate monitoring of backup progress from the server. A value of zero disables periodic status updates completely, although an update will still be sent when requested by the server, to avoid timeout-based disconnects. The default value is 10 seconds. 状態パケットがソースサーバに返送される間隔を秒単位で指定します。 より小さな値を指定することで、より正確にサーバからバックアップの進行状況を監視できます。 ゼロという値は定期的な状態更新を完全に無効にします。 しかし、タイムアウトによる切断を防止するために、サーバにより要求された場合には更新が送信されます。 デフォルト値は10秒です。

-U username
--username=username

Specifies the user name to connect as. 接続ユーザ名を指定します。

-w
--no-password

Prevents issuing 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

Forces <application>pg_basebackup</application> to prompt for a password before connecting to the source server. ソースサーバに接続する前に、pg_basebackupは強制的にパスワード入力を促します。

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

Other options are also available: 以下のその他のオプションも使用することができます。

-V
--version

Prints the <application>pg_basebackup</application> version and exits. pg_basebackupのバージョンを表示し終了します。

-?
--help

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

環境

<title>Environment</title>

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

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

注釈

<title>Notes</title>

At the beginning of the backup, a checkpoint needs to be performed on the source server. This can take some time (especially if the option <literal>&#45;-checkpoint=fast</literal> is not used), during which <application>pg_basebackup</application> will appear to be idle. バックアップの開始時に、ソースサーバ上でチェックポイントを実行する必要があります。 (特にオプション --checkpoint=fast を使用していない場合)これには少し時間を要する場合があり、その間 pg_basebackup はアイドル状態であるように見えます。

The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <xref linkend="protocol-replication"/> for the precise details. このバックアップには、設定ファイルやサードパーティによりディレクトリに格納された追加ファイルを含め、データディレクトリとテーブル空間内のすべてのファイルが含まれますが、PostgreSQLによって管理される一部の一時ファイルは含まれません。 ただし、テーブル空間に使われるシンボリックリンクが保存されることを除くと、通常のファイルとディレクトリのみがコピーされます。 PostgreSQLが認識している一部のディレクトリを指すシンボリックリンクは空のディレクトリとしてコピーされます。 その他のシンボリックリンクおよび特殊デバイスファイルはスキップされます。 (正確な詳細については55.4を参照してください。)

In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <literal>&#45;-tablespace-mapping</literal> is used. Without this option, running a plain format base backup on the same host as the server will not work if tablespaces are in use, because the backup would have to be written to the same directory locations as the original tablespaces. plain形式では、オプション--tablespace-mappingが使われなければ、テーブル空間はソースサーバ上のと同じパスでバックアップされます。 このオプションがないと、サーバと同じホスト上でのplain形式のベースバックアップの実行は動作しません、というのは、バックアップを元のテーブル空間と同じディレクトリに書き込まなければならないからです。

When tar format is used, it is the user's responsibility to unpack each tar file before starting a PostgreSQL server that uses the data. If there are additional tablespaces, the tar files for them need to be unpacked in the correct locations. In this case the symbolic links for those tablespaces will be created by the server according to the contents of the <filename>tablespace_map</filename> file that is included in the <filename>base.tar</filename> file. tar形式を使う場合、そのデータを使うPostgreSQLサーバを起動する前に各tarファイルを解凍するのはユーザの責任です。 追加のテーブル空間がある場合、それについてのtarファイルは、正しい場所に解凍される必要があります。 この場合、テーブル空間へのシンボリックリンクは、base.tarファイルに含まれるtablespace_mapファイルの内容に基づいて、サーバが作成します。

<application>pg_basebackup</application> works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (<literal>-X stream</literal>) only works with server version 9.3 and later, and tar format (<literal>&#45;-format=tar</literal>) only works with server version 9.5 and later. pg_basebackupは同じまたは9.1以降のより古いメジャーバージョンのサーバで動作します。 しかしWALストリーミングモード(-X stream)はバージョン9.3およびそれ以降のサーバでのみ動作します。 また、現在のバージョンのtar形式(--format=tar)はバージョン9.5およびそれ以降のサーバでのみ動作します。

<application>pg_basebackup</application> will preserve group permissions for data files if group permissions are enabled on the source cluster. pg_basebackupは、ソースのクラスタでグループパーミッションが有効になっている場合、データファイルに対するグループパーミッションを維持します。

<title>Examples</title>

To create a base backup of the server at <literal>mydbserver</literal> and store it in the local directory <filename>/usr/local/pgsql/data</filename>: mydbserverで稼働するサーバのベースバックアップを作成し、ローカルディレクトリ/usr/local/pgsql/dataに保管します。

$ pg_basebackup -h mydbserver -D /usr/local/pgsql/data

To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <filename>backup</filename>, showing a progress report while running: 各テーブル空間につき圧縮したtarファイルを1つ作成するようにローカルサーバをバックアップし、backupディレクトリに保管します。 同時に実行時に進行状況を表示します。

$ pg_basebackup -D backup -Ft -z -P

To create a backup of a single-tablespace local database and compress this with <productname>bzip2</productname>: 単一のテーブル空間を持つローカルデータベースのバックアップを作成し、それをbzip2で圧縮します。

$ pg_basebackup -D - -Ft -X fetch | bzip2 > backup.tar.bz2

(This command will fail if there are multiple tablespaces in the database.) (データベース内に複数のテーブル空間が存在する場合このコマンドは失敗します。)

To create a backup of a local database where the tablespace in <filename>/opt/ts</filename> is relocated to <filename>./backup/ts</filename>: /opt/tsにあるテーブル空間を./backup/tsに再配置してローカルデータベースのバックアップを作成します。

$ pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts

To create a backup of a local server with one tar file for each tablespace compressed with <application>gzip</application> at level 9, stored in the directory <filename>backup</filename>: レベル9でgzipで圧縮された、テーブル空間ごとに1つのtarファイルでローカルサーバのバックアップを作成し、ディレクトリbackupに保存します。

$ pg_basebackup -D backup -Ft --compress=gzip:9

関連項目

<title>See Also</title> pg_dump, 28.4.6