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

29.9. アーキテクチャ #

<title>Architecture</title>

Logical replication is built with an architecture similar to physical streaming replication (see <xref linkend="streaming-replication"/>). It is implemented by <literal>walsender</literal> and <literal>apply</literal> processes. The walsender process starts logical decoding (described in <xref linkend="logicaldecoding"/>) of the WAL and loads the standard logical decoding output plugin (<literal>pgoutput</literal>). The plugin transforms the changes read from WAL to the logical replication protocol (see <xref linkend="protocol-logical-replication"/>) and filters the data according to the publication specification. The data is then continuously transferred using the streaming replication protocol to the apply worker, which maps the data to local tables and applies the individual changes as they are received, in correct transactional order. 論理レプリケーションは物理ストリーミングレプリケーション(26.2.5参照)と似たアーキテクチャで構成されています。 walsender(WAL送信)プロセスとapply(適用)プロセスで実装されています。 WAL送信プロセスはWALのロジカルデコーディング(第47章に記載)を開始し、標準のロジカルデコーディング出力プラグイン(pgoutput)をロードします。 このプラグインは、WALから読み込んだ更新を論理レプリケーションプロトコル(54.5参照)に変換します。 そして、パブリケーションの指定にしたがってフィルタします。 データは次に、ストリーミングレプリケーションプロトコルを使って継続的に適用ワーカーに転送されます。 適用ワーカーは、データをローカルテーブルにマップし、更新を受信すると正しいトランザクション順に個々の更新を適用します。

The apply process on the subscriber database always runs with <link linkend="guc-session-replication-role"><varname>session_replication_role</varname></link> set to <literal>replica</literal>. This means that, by default, triggers and rules will not fire on a subscriber. Users can optionally choose to enable triggers and rules on a table using the <link linkend="sql-altertable"><command>ALTER TABLE</command></link> command and the <literal>ENABLE TRIGGER</literal> and <literal>ENABLE RULE</literal> clauses. サブスクライバーデータベース上の適用プロセスは、常にsession_replication_rolereplicaに設定して実行されます。 これは、デフォルトでは、トリガとルールはサブスクライバー上では起動されないことを意味します。 ユーザは、必要に応じて、 ALTER TABLEコマンド、ENABLE TRIGGERおよびENABLE RULE句を使用して、テーブルのトリガおよびルールを有効にすることを選択できます。

The logical replication apply process currently only fires row triggers, not statement triggers. The initial table synchronization, however, is implemented like a <command>COPY</command> command and thus fires both row and statement triggers for <command>INSERT</command>. 今のところ、論理レプリケーション適用プロセスは行トリガだけを起動し、文トリガは起動しません。 ただし、初期テーブル同期はCOPYコマンドのように実装されているので、INSERTの行と文トリガの両方を起動します。

29.9.1. 初期スナップショット #

<title>Initial Snapshot</title>

The initial data in existing subscribed tables are snapshotted and copied in parallel instances of a special kind of apply process. These special apply processes are dedicated table synchronization workers, spawned for each table to be synchronized. Each table synchronization process will create its own replication slot and copy the existing data. As soon as the copy is finished the table contents will become visible to other backends. Once existing data is copied, the worker enters synchronization mode, which ensures that the table is brought up to a synchronized state with the main apply process by streaming any changes that happened during the initial data copy using standard logical replication. During this synchronization phase, the changes are applied and committed in the same order as they happened on the publisher. Once synchronization is done, control of the replication of the table is given back to the main apply process where replication continues as normal. 《マッチ度[79.247202]》既存のサブスクライブされたテーブル中の初期データのスナップショットが取得され、特殊な適用プロセスの並列インスタンスにコピーされます。 このプロセスは自身のレプリケーションスロットを作成し、既存のデータをコピーします。 コピーが終わるとすぐにテーブル内容が他のバックエンドから見えるようになります。 既存のデータのコピーが終わると、ワーカーは同期モードに入ります。 このモードでは、初期データのコピー中に起こった更新を標準の論理レプリケーションを使ってストリーミングすることにより、テーブルが主適用プロセスと同期状態になることを保証します。 この同期フェーズの間、パブリッシャーで発生したのと同じ順序で変更が適用され、コミットされます。 ひとたび同期が完了すれば、テーブルのレプリケーションの制御は主適用プロセスに戻され、レプリケーションは通常通り継続されます。 《機械翻訳》既存のサブスクライブされた表の初期データは、スナップショットが作成され、特殊な種類の適用パラレルのプロセスインスタンスにコピーされます。 これらの特殊な適用プロセスは、同期化される各テーブルに対して生成された専用のテーブル同期化ワーカーです。 各テーブル同期化プロセスは、独自のレプリケーションスロットを作成し、既存のデータをコピーします。 コピーが終了するとすぐに、テーブルの内容は他のバックエンドに対する可視になります。 既存のデータがコピーされると、ワーカーは同期化モードに入ります。 これにより、標準論理レプリケーションを使用した最初のデータコピーで発生したすべての変更が、ストリーミングによってメイン適用プロセスと同期化された状態になります。 この同期化フェーズでは、変更はパブリッシャーで発生したのと同じオーダーで適用およびコミットされます。 同期化が完了すると、ののが適用テーブルに戻され、は通常どおり続行されます。 テーブルプロセスコントロールレプリケーションメインレプリケーション

注記

The publication <link linkend="sql-createpublication-params-with-publish"><literal>publish</literal></link> parameter only affects what DML operations will be replicated. The initial data synchronization does not take this parameter into account when copying the existing table data. パブリケーションのpublishパラメータは、レプリケーションされるDML操作にのみ影響します。 初期データ同期では、既存のテーブルデータをコピーするときにこのパラメータは考慮されません。

注記

If a table synchronization worker fails during copy, the apply worker detects the failure and respawns the table synchronization worker to continue the synchronization process. This behaviour ensures that transient errors do not permanently disrupt the replication setup. See also <link linkend="guc-wal-retrieve-retry-interval"><varname>wal_retrieve_retry_interval</varname></link>. 《機械翻訳》ワーカー中に表の同期のコピーが失敗した場合、適用ワーカーは障害を検出し、テーブルの同期のワーカーを再開して同期のプロセスを続行します。 この動作により、一時的なエラーによってレプリケーションのセットアップが永続的に中断されることがなくなります。 wal_retrieve_retry_intervalも参照してください。