-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-pgrewind.html
More file actions
146 lines (145 loc) · 18.3 KB
/
Copy pathapp-pgrewind.html
File metadata and controls
146 lines (145 loc) · 18.3 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
<?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@postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="PostgreSQL 9.5.4文書" /><link rel="up" href="reference-server.html" title="PostgreSQLサーバアプリケーション" /><link rel="prev" href="app-pgresetxlog.html" title="pg_resetxlog" /><link rel="next" href="pgtestfsync.html" title="pg_test_fsync" /><link rel="copyright" href="legalnotice.html" title="法的告知" /><meta name="viewport" content="width=device-width,initial-scale=1.0" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><td width="20%" align="left" colspan="2"></td><th width="60%" align="center"><a accesskey="h" href="index.html">PostgreSQL 9.5.4文書</a></th><td width="20%" align="right"><div class="actions"><a class="issue" href="https://github.com/pgsql-jp/jpug-doc/issues/new?title=version 9.5.4 app-pgrewind.html">誤訳等の報告</a></div></td></tr><tr><td width="10%" align="left" valign="top"><a accesskey="p" href="app-pgresetxlog.html">前へ</a> </td><td width="10%" align="left" valign="top"><a accesskey="u" href="reference-server.html">上へ</a></td><td width="60%" align="center"><span class="application">pg_rewind</span></td><td width="20%" align="right" valign="top"> <a accesskey="n" href="pgtestfsync.html">次へ</a></td></tr></table><hr /></div><div class="refentry" id="app-pgrewind"><div class="titlepage"></div><a id="idp110473760" class="indexterm"></a><div class="refnamediv"><h2>名前</h2><p>pg_rewind<span class="original">
<refpurpose>synchronize a <productname>PostgreSQL</productname> data directory with another data directory that was forked from the first one</refpurpose>
</span> — <span class="productname">PostgreSQL</span>のデータディレクトリを、そこから派生した他のデータディレクトリと同期する</p></div><div class="refsynopsisdiv"><h2>概要</h2><div class="cmdsynopsis"><p id="idp110478192"><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="idp110486672"><h2>説明</h2><span class="original">
<title>Description</title>
</span><p><span class="original">
<application>pg_rewind</> 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. All files are copied, including configuration files. The
advantage of <application>pg_rewind</> over taking a new base backup, or
tools like <application>rsync</>, is that <application>pg_rewind</> does
not require reading through all unchanged files in the cluster. That makes
it a lot faster when the database is large and only a small portion of it
differs between the clusters.
</span>実行結果は、ターゲットデータディレクトリをソースディレクトリと置き換えたのと等しくなります。
設定ファイルを含め、すべてのファイルがコピーされます。
新しいベースバックアップを取ったり、<span class="application">rsync</span>のようなツールを使う場合と比較して、<span class="application">pg_rewind</span>はクラスタ内の変更されていないファイルを読出す必要がないという利点があります。
データベースが大きく、クラスタ間で変更されている部分がわずかの場合には、極めて高速になります。
</p><p><span class="original">
<application>pg_rewind</> 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_xlog</> directory
reaching all the way back to the point of divergence. In the typical
failover scenario where the target cluster was shut down soon after the
divergence, that is not a problem, but if the target cluster had run for a
long time after the divergence, the old WAL files might not be present
anymore. In that case, they can be manually copied from the WAL archive to
the <filename>pg_xlog</> directory. Fetching missing files from a WAL
archive automatically is currently not supported.
</span><span class="application">pg_rewind</span>はソースとターゲットクラスタ内のタイムラインヒストリーを調べ、それらがどの時点で異なるものになったのかを調べます。
そしてターゲットクラスタ内の<code class="filename">pg_xlog</code>ディレクトリ内の分岐点に到達するWALを見つけようとします。
分岐点のあと間をおかずシャットダウンされたような典型的なフェイルオーバのシナリオにおいては、これは特に問題になりません。
しかし、分岐点の後にターゲットクラスタが長時間運用されていた場合には、古いWALファイルはもう存在しないかもしれません。
この場合は、WALアーカイブから手動で<code class="filename">pg_xlog</code>ディレクトリにコピーすることができます。
不足しているWALファイルをアーカイブから自動的にコピーする機能は今のところサポートされていません。
</p><p><span class="original">
When the target server is started up for the first time after running
<application>pg_rewind</>, 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</> was run, and therefore could not be copied by
<application>pg_rewind</> session, it needs to be made available when the
target server is started up. That can be done by creating a
<filename>recovery.conf</> file in the target data directory with a
suitable <varname>restore_command</>.
</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</> requires that the target server either has
the <xref linkend="guc-wal-log-hints"> option is enabled
in <filename>postgresql.conf</> or that data checksums were enabled when
the cluster was initialized with <application>initdb</>. Neither of these
are currently on by default.
<xref linkend="guc-full-page-writes"> must also be enabled. That is the
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><div class="refsect1" id="idp110505904"><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 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 path to the data directory of the source server, to
synchronize the target with. When <option>#045;&#045;source-pgdata</> is
used, the source server must be cleanly shut down.
</span>同期するソースサーバのデータディレクトリへのパスを指定します。
<code class="option">--source-pgdata</code>を使用する場合は、ソースサーバは正常にシャットダウンされていなければなりません。
</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</> server to synchronize the target with.
The connection must be a normal (non-replication) connection
with superuser access. The server must be up and running,
and must not be in recovery mode.
</span>同期するソース<span class="productname">PostgreSQL</span>サーバへ接続するためのlibpq接続文字列を指定します。
接続は、スーパユーザアクセスである通常の接続(レプリケーション接続でない)でなければなりません。
サーバは稼働中でなければならず、またリカバリモードであってはいけません。
</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 over 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</>.
</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="idp110526608"><h2>環境</h2><span class="original">
<title>Environment</title>
</span><p><span class="original">
When <option>#045;&#045;source-server</> option is used,
<application>pg_rewind</application> also uses the environment variables
supported by <application>libpq</> (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="31.14. 環境変数">31.14. 環境変数</a>を参照)。
</p></div><div class="refsect1" id="idp110530240"><h2>注釈</h2><span class="original">
<title>Notes</title>
</span><div class="refsect2" id="idp110530880"><h3>どうやって動くのか</h3><span class="original">
<title>How it works</title>
</span><p><span class="original">
The basic idea is to copy everything from the new cluster to the old
cluster, except for the blocks that we know to be the same.
</span>基本的なアイデアは、同じであることがわかっているブロックを除き、すべてを新しいクラスタから古いクラスタにコピーする、というものです。
</p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p><span class="original">
Scan the WAL log of the old cluster, starting from the last checkpoint
before the point where the new cluster's timeline history forked off
from the old cluster. For each WAL record, make a note of the data
blocks that were touched. This yields a list of all the data blocks
that were changed in the old cluster, after the new cluster forked off.
</span>古いクラスタからタイムラインが新しいクラスタで分岐した時点より前の最後のチェックポイントから始めて、古いクラスタのWALログをスキャンしします。
各々のWALレコードについて、変更されたデータブロックを記録します。
これにより、新しいクラスタで分岐した以降に、古いクラスタで変更されたすべてのデータブロックのリストが作成できます。
</p></li><li class="step"><p><span class="original">
Copy all those changed blocks from the new cluster to the old cluster.
</span>変更されたすべてのブロックを新しいクラスタから古いクラスタにコピーします。
</p></li><li class="step"><p><span class="original">
Copy all other files such as <filename>clog</filename> and configuration files from the new cluster
to the old cluster, everything except the relation files.
</span><code class="filename">clog</code>や設定ファイルなど、リレーションファイル以外のすべてのファイルを新しいクラスタから古いクラスタにコピーします。
</p></li><li class="step"><p><span class="original">
Apply the WAL from the new cluster, starting from the checkpoint
created at failover. (Strictly speaking, <application>pg_rewind</>
doesn't apply the WAL, it just creates a backup label file indicating
that when <productname>PostgreSQL</> is started, it will start replay
from that checkpoint and apply all the required WAL.)
</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-pgresetxlog.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_resetxlog</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>