-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-pgrewind.html
More file actions
265 lines (264 loc) · 26.5 KB
/
app-pgrewind.html
File metadata and controls
265 lines (264 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>pg_rewind</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="app-pgresetwal.html" title="pg_resetwal" /><link rel="next" href="pgtestfsync.html" title="pg_test_fsync" /><meta name="viewport" content="width=device-width,initial-scale=1.0" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="4" align="center"><a accesskey="h" href="index.html">PostgreSQL 11.5文書</a></th></tr><tr><td width="10%" align="left"></td><td width="10%" align="left"></td><td width="60%" align="center"><a href="reference-server.html" title="PostgreSQLサーバアプリケーション">PostgreSQLサーバアプリケーション</a></td><td width="20%" align="right"><div class="actions"><a class="issue" title="github" href="https://github.com/pgsql-jp/jpug-doc/issues/new?title=version 11.5 app-pgrewind.html">誤訳等の報告
</a></div></td></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pgresetwal.html" title="pg_resetwal">前へ</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-server.html" title="PostgreSQLサーバアプリケーション">上へ</a></td><td width="60%" align="center"><span class="application">pg_rewind</span></td><td width="20%" align="right"> <a accesskey="n" href="pgtestfsync.html" title="pg_test_fsync">次へ</a></td></tr></table><hr /></div><div class="refentry" id="APP-PGREWIND"><div class="titlepage"></div><a id="id-1.9.5.8.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">pg_rewind</span></span></h2><p>pg_rewind<span class="original">
<refpurpose>synchronize a <productname>PostgreSQL</productname> data directory with another data directory that was forked from it</refpurpose>
</span> — <span class="productname">PostgreSQL</span>のデータディレクトリを、そこから派生した他のデータディレクトリと同期する</p></div><div class="refsynopsisdiv"><h2>概要</h2><div class="cmdsynopsis"><p id="id-1.9.5.8.4.1"><code class="command">pg_rewind</code> [<em class="replaceable"><code>option</code></em>...] { <code class="option">-D </code> | <code class="option">--target-pgdata</code> }<em class="replaceable"><code> directory</code></em> { <code class="option">--source-pgdata=<em class="replaceable"><code>directory</code></em></code> | <code class="option">--source-server=<em class="replaceable"><code>connstr</code></em></code> } </p></div></div><div class="refsect1" id="id-1.9.5.8.5"><h2>説明</h2><span class="original">
<title>Description</title>
</span><p>
<span class="original">
<application>pg_rewind</application> is a tool for synchronizing a PostgreSQL cluster
with another copy of the same cluster, after the clusters' timelines have
diverged. A typical scenario is to bring an old master server back online
after failover as a standby that follows the new master.
</span>
<span class="application">pg_rewind</span>は、PostgreSQLのクラスタのタイムラインが分岐した後、クラスタをその複製のクラスタに同期するためのツールです。
典型的なシナリオとしては、フェイルオーバー後、新しいマスターに追従するスタンバイとして、古いマスターサーバをオンラインに戻す、というのがあります。
</p><p>
<span class="original">
The result is equivalent to replacing the target data directory with the
source one. Only changed blocks from relation files are copied;
all other files are copied in full, including configuration files. The
advantage of <application>pg_rewind</application> over taking a new base backup, or
tools like <application>rsync</application>, is that <application>pg_rewind</application> does
not require reading through unchanged blocks in the cluster. This makes
it a lot faster when the database is large and only a small
fraction of blocks differ between the clusters.
</span>
実行結果は、ターゲットデータディレクトリをソースディレクトリと置き換えたのと等しくなります。
リレーションファイルのうちの変化のあったブロックだけがコピーされます。
それ以外のすべてのファイルは、設定ファイルを含め、すべてのファイルがコピーされます。
新しいベースバックアップを取ったり、<span class="application">rsync</span>のようなツールを使う場合と比較して、<span class="application">pg_rewind</span>はクラスタ内の変更されていないブロックを読出す必要がないという利点があります。
データベースが大きく、クラスタ間で変更されているブロックの割合が小さい場合には、極めて高速になります。
</p><p>
<span class="original">
<application>pg_rewind</application> examines the timeline histories of the source
and target clusters to determine the point where they diverged, and
expects to find WAL in the target cluster's <filename>pg_wal</filename> directory
reaching all the way back to the point of divergence. The point of divergence
can be found either on the target timeline, the source timeline, or their common
ancestor. In the typical failover scenario where the target cluster was
shut down soon after the divergence, this is not a problem, but if the
target cluster ran for a long time after the divergence, the old WAL
files might no longer be present. In that case, they can be manually
copied from the WAL archive to the <filename>pg_wal</filename> directory, or
fetched on startup by configuring <filename>recovery.conf</filename>. The use of
<application>pg_rewind</application> is not limited to failover, e.g. a standby
server can be promoted, run some write transactions, and then rewinded
to become a standby again.
</span>
<span class="application">pg_rewind</span>はソースとターゲットクラスタ内のタイムラインヒストリーを調べ、それらがどの時点で異なるものになったのかを調べます。
差異が発生した分岐点までずっと遡ることにより、ターゲットクラスタ内の<code class="filename">pg_wal</code>ディレクトリ内の分岐点に到達するWALを見つけようとします。
変化の分岐点は、ターゲット側のタイムライン中、ソース側のタイムライン中、あるいはそれら共通の祖先の中に見つかる可能性が高いです。
分岐点のあと間をおかずシャットダウンされたような典型的なフェイルオーバーのシナリオにおいては、これは特に問題になりません。
しかし、分岐点の後にターゲットクラスタが長時間運用されていた場合には、古いWALファイルはもう存在しないかもしれません。
この場合は、WALアーカイブから手動で<code class="filename">pg_wal</code>ディレクトリにコピーすることができます。
あるいは、<code class="filename">recovery.conf</code>を設定することにより、起動時に取得できます。
<span class="application">pg_rewind</span>の利用は、フェイルオーバーに留まりません。
たとえば、スタンバイサーバは昇格してから書き込みトランザクションを実行し、再びスタンバイになるために巻き戻すこともできます。
</p><p>
<span class="original">
When the target server is started for the first time after running
<application>pg_rewind</application>, it will go into recovery mode and replay all
WAL generated in the source server after the point of divergence.
If some of the WAL was no longer available in the source server when
<application>pg_rewind</application> was run, and therefore could not be copied by the
<application>pg_rewind</application> session, it must be made available when the
target server is started. This can be done by creating a
<filename>recovery.conf</filename> file in the target data directory with a
suitable <varname>restore_command</varname>.
</span>
<span class="application">pg_rewind</span>を実行した後、最初にターゲットサーバを起動すると、そのサーバはリカバリモードに入り、分岐点以降ソースサーバで生成されたWALをすべてリプレイします。
<span class="application">pg_rewind</span>が実行された時にWALがソースサーバになくて<span class="application">pg_rewind</span>のセッションではコピーできなかった場合は、ターゲットサーバが起動した時にWALを読む込めるようになっていなければなりません。
適切な<code class="varname">restore_command</code>を設定した<code class="filename">recovery.conf</code>ファイルをターゲットデータディレクトリに置くことで、これを達成できます。
</p><p>
<span class="original">
<application>pg_rewind</application> requires that the target server either has
the <xref linkend="guc-wal-log-hints"/> option enabled
in <filename>postgresql.conf</filename> or data checksums enabled when
the cluster was initialized with <application>initdb</application>. Neither of these
are currently on by default. <xref linkend="guc-full-page-writes"/>
must also be set to <literal>on</literal>, but is enabled by default.
</span>
<span class="application">pg_rewind</span>を使用するには、ターゲットサーバ上で<code class="filename">postgresql.conf</code>の<a class="xref" href="runtime-config-wal.html#GUC-WAL-LOG-HINTS">wal_log_hints</a>オプションが有効になっているか、<span class="application">initdb</span>でクラスタを初期化した時にデータチェックサムが有効になっていなければなりません。
どちらもデフォルトでは無効です。
<a class="xref" href="runtime-config-wal.html#GUC-FULL-PAGE-WRITES">full_page_writes</a>も有効でなければなりませんが、これはデフォルトで有効です。
</p><div class="warning"><h3 class="title">警告</h3><p>
<span class="original">
If <application>pg_rewind</application> fails while processing, then
the data folder of the target is likely not in a state that can be
recovered. In such a case, taking a new fresh backup is recommended.
</span>
処理中に<span class="application">pg_rewind</span>が失敗した場合、ターゲットのデータフォルダーはリカバリ可能な状態でない可能性があります。
このような場合は、最新のバックアップを取ることをお勧めします。
</p><p>
<span class="original">
<application>pg_rewind</application> will fail immediately if it finds
files it cannot write directly to. This can happen for example when
the source and the target server use the same file mapping for read-only
SSL keys and certificates. If such files are present on the target server
it is recommended to remove them before running
<application>pg_rewind</application>. After doing the rewind, some of
those files may have been copied from the source, in which case it may
be necessary to remove the data copied and restore back the set of links
used before the rewind.
</span>
<span class="application">pg_rewind</span>は直接書き込めないファイルが見つかるとすぐに失敗します。
たとえば、ソースサーバとターゲットサーバが読み取り専用のSSLキーと証明書に同じファイルマッピングを使用する場合に発生します。
そのようなファイルがターゲットサーバ上に存在する場合、それらを削除してから<span class="application">pg_rewind</span>を実行することをお勧めします。
巻き戻しを行った後、それらのファイルの一部がソースからコピーされている可能性があります。
その場合は、コピーされたデータを削除して、巻き戻し前に使用していたリンクのセットを元に戻す必要があります。
</p></div></div><div class="refsect1" id="id-1.9.5.8.6"><h2>オプション</h2><span class="original">
<title>Options</title>
</span><p>
<span class="original">
<application>pg_rewind</application> accepts the following command-line
arguments:
</span>
<span class="application">pg_rewind</span>は以下のコマンドラインオプションを受け付けます。
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-D <em class="replaceable"><code>directory</code></em></code><br /></span><span class="term"><code class="option">--target-pgdata=<em class="replaceable"><code>directory</code></em></code></span></dt><dd><p>
<span class="original">
This option specifies the target data directory that is synchronized
with the source. The target server must be shut down cleanly before
running <application>pg_rewind</application>
</span>
このオプションは、同期するターゲットデータディレクトリを指定します。
ターゲットサーバは、<span class="application">pg_rewind</span>を実行する前に、正常にシャットダウンされていなければなりません。
</p></dd><dt><span class="term"><code class="option">--source-pgdata=<em class="replaceable"><code>directory</code></em></code></span></dt><dd><p>
<span class="original">
Specifies the file system path to the data directory of the source
server to synchronize the target with. This option requires the
source server to be cleanly shut down.
</span>
同期するソースサーバのデータディレクトリへのファイルシステム上のパスを指定します。
このオプションを使用する場合は、ソースサーバは正常にシャットダウンされていなければなりません。
</p></dd><dt><span class="term"><code class="option">--source-server=<em class="replaceable"><code>connstr</code></em></code></span></dt><dd><p>
<span class="original">
Specifies a libpq connection string to connect to the source
<productname>PostgreSQL</productname> server to synchronize the target
with. The connection must be a normal (non-replication) connection
with a role having sufficient permissions to execute the functions
used by <application>pg_rewind</application> on the source server
(see Notes section for details) or a superuser role. This option
requires the source server to be running and not in recovery mode.
</span>
ターゲットサーバに同期するソース<span class="productname">PostgreSQL</span>サーバに接続するlibpq接続文字列を指定します。
接続は、ソースサーバ(詳しくは注釈を参照)で<span class="application">pg_rewind</span>で使われる関数を実行する権限を持つロールまたはスーパーユーザロールでの通常の(レプリケーションでない)接続でなければなりません。
このオプションはソースサーバが実行中であることとリカバリモードではないことを必要とします。
</p></dd><dt><span class="term"><code class="option">-n</code><br /></span><span class="term"><code class="option">--dry-run</code></span></dt><dd><p>
<span class="original">
Do everything except actually modifying the target directory.
</span>
ターゲットディレクトリを実際に更新する以外はすべてのことを行います。
</p></dd><dt><span class="term"><code class="option">-P</code><br /></span><span class="term"><code class="option">--progress</code></span></dt><dd><p>
<span class="original">
Enables progress reporting. Turning this on will deliver an approximate
progress report while copying data from the source cluster.
</span>
進行状況のレポートを有効にします。このオプションを有効にすると、データをソースクラスタからコピーする際のおおよその進行状況をレポートします。
</p></dd><dt><span class="term"><code class="option">--debug</code></span></dt><dd><p>
<span class="original">
Print verbose debugging output that is mostly useful for developers
debugging <application>pg_rewind</application>.
</span>
主に開発者が<span class="application">pg_rewind</span>をデバッグするのに役立つ冗長なデバッグ出力を印字します。
</p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>バージョン情報を表示して終了します。</p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>ヘルプを表示して終了します。</p></dd></dl></div><p>
</p></div><div class="refsect1" id="id-1.9.5.8.7"><h2>環境</h2><span class="original">
<title>Environment</title>
</span><p>
<span class="original">
When <option>&#045;&#045;source-server</option> option is used,
<application>pg_rewind</application> also uses the environment variables
supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>).
</span>
<code class="option">--source-server</code>オプションを使用する場合、<span class="application">pg_rewind</span>は
<span class="application">libpq</span>で利用できる環境変数を使用します(<a class="xref" href="libpq-envars.html" title="34.14. 環境変数">34.14</a>を参照)。
</p></div><div class="refsect1" id="id-1.9.5.8.8"><h2>注釈</h2><span class="original">
<title>Notes</title>
</span><p>
<span class="original">
When executing <application>pg_rewind</application> using an online
cluster as source, a role having sufficient permissions to execute the
functions used by <application>pg_rewind</application> on the source
cluster can be used instead of a superuser. Here is how to create such
a role, named <literal>rewind_user</literal> here:
</span>
オンラインのクラスタをソースとして使用して<span class="application">pg_rewind</span>を実行するとき、スーパーユーザの代わりにソースのクラスタ上で<span class="application">pg_rewind</span>で使われる関数を実行できる権限を持ったロールを使うことができます。
<code class="literal">rewind_user</code>という名前のこのようなロールの作り方を以下に示します。
</p><pre class="programlisting">
CREATE USER rewind_user LOGIN;
GRANT EXECUTE ON function pg_catalog.pg_ls_dir(text, boolean, boolean) TO rewind_user;
GRANT EXECUTE ON function pg_catalog.pg_stat_file(text, boolean) TO rewind_user;
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text) TO rewind_user;
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, boolean) TO rewind_user;
</pre><p>
</p><p>
<span class="original">
When executing <application>pg_rewind</application> using an online
cluster as source which has been recently promoted, it is necessary
to execute a <command>CHECKPOINT</command> after promotion so as its
control file reflects up-to-date timeline information, which is used by
<application>pg_rewind</application> to check if the target cluster
can be rewound using the designated source cluster.
</span>
最近に昇格したオンラインのクラスタをソースとして使って<span class="application">pg_rewind</span>を実行するときには、コントロールファイルが最新のタイムライン情報を反映するように昇格後に<code class="command">CHECKPOINT</code>を実行する必要があります。
タイムライン情報は<span class="application">pg_rewind</span>が指定されたソースクラスタを使ってターゲットクラスタを巻き戻しできるかどうか検査するのに使われます。
</p><div class="refsect2" id="id-1.9.5.8.8.4"><h3>どうやって動くのか</h3><span class="original">
<title>How it works</title>
</span><p>
<span class="original">
The basic idea is to copy all file system-level changes from the source
cluster to the target cluster:
</span>
基本的なアイデアは、ファイルシステムレベルの変更を、すべてをソースクラスタからターゲットクラスタにコピーする、というものです。
</p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p>
<span class="original">
Scan the WAL log of the target cluster, starting from the last
checkpoint before the point where the source cluster's timeline
history forked off from the target cluster. For each WAL record,
record each data block that was touched. This yields a list of all
the data blocks that were changed in the target cluster, after the
source cluster forked off.
</span>
ソースクラスタのタイムライン履歴がターゲットクラスタから分岐した時点より前の最後のチェックポイントから始めて、ターゲットクラスタのWALログをスキャンします。
各々のWALレコードについて、変更されたデータブロックを記録します。
これにより、ソースクラスタが分岐した以降に、ターゲットクラスタで変更されたすべてのデータブロックのリストが作成されます。
</p></li><li class="step"><p>
<span class="original">
Copy all those changed blocks from the source cluster to
the target cluster, either using direct file system access
(<option>&#045;&#045;source-pgdata</option>) or SQL (<option>&#045;&#045;source-server</option>).
</span>
ファイルシステムへの直接アクセス(<code class="option">--source-pgdata</code>)かSQL (<code class="option">--source-server</code>)を使って、変更のあったすべてのブロックを、ソースクラスタからターゲットクラスタにコピーします。
</p></li><li class="step"><p>
<span class="original">
Copy all other files such as <filename>pg_xact</filename> and
configuration files from the source cluster to the target cluster
(everything except the relation files). Similarly to base backups,
the contents of the directories <filename>pg_dynshmem/</filename>,
<filename>pg_notify/</filename>, <filename>pg_replslot/</filename>,
<filename>pg_serial/</filename>, <filename>pg_snapshots/</filename>,
<filename>pg_stat_tmp/</filename>, and
<filename>pg_subtrans/</filename> are omitted from the data copied
from the source cluster. Any file or directory beginning with
<filename>pgsql_tmp</filename> is omitted, as well as are
<filename>backup_label</filename>,
<filename>tablespace_map</filename>,
<filename>pg_internal.init</filename>,
<filename>postmaster.opts</filename> and
<filename>postmaster.pid</filename>.
</span>
<code class="filename">pg_xact</code>や設定ファイルなど、それ以外のすべてのファイルをソースクラスタからターゲットクラスタにコピーします。(リレーションファイル以外のすべて)。
ベースバックアップと同様に、ディレクトリ<code class="filename">pg_dynshmem/</code>、<code class="filename">pg_notify/</code>、<code class="filename">pg_replslot/</code>、<code class="filename">pg_serial/</code>、<code class="filename">pg_snapshots/</code>、<code class="filename">pg_stat_tmp/</code>、および、<code class="filename">pg_subtrans/</code>の内容は省かれます。
<code class="filename">pgsql_tmp</code>で始まる全てのファイルやディレクトリは省かれます。
<code class="filename">backup_label</code>、<code class="filename">tablespace_map</code>、<code class="filename">pg_internal.init</code>、<code class="filename">postmaster.opts</code>、および、<code class="filename">postmaster.pid</code>も同様です。
</p></li><li class="step"><p>
<span class="original">
Apply the WAL from the source cluster, starting from the checkpoint
created at failover. (Strictly speaking, <application>pg_rewind</application>
doesn't apply the WAL, it just creates a backup label file that
makes <productname>PostgreSQL</productname> start by replaying all WAL from
that checkpoint forward.)
</span>
フェイルオーバーの際に作られたチェックポイントから始めて、ソースクラスタのWALを適用します。(厳密に言うと、<span class="application">pg_rewind</span>はWALの適用はせず、単にバックアップラベルファイルを作るだけです。
それにより、<span class="productname">PostgreSQL</span>が起動する時、チェックポイントより前方のすべてのWALが適用されます)
</p></li></ol></div></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-pgresetwal.html">前へ</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-server.html">上へ</a></td><td width="40%" align="right"> <a accesskey="n" href="pgtestfsync.html">次へ</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_resetwal</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">ホーム</a></td><td width="40%" align="right" valign="top"> <span class="application">pg_test_fsync</span></td></tr></table></div></body></html>