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

31.7. アーキテクチャ #

<title>Architecture</title>

Logical replication starts by copying a snapshot of the data on the publisher database. Once that is done, changes on the publisher are sent to the subscriber as they occur in real time. The subscriber applies data in the order in which commits were made on the publisher so that transactional consistency is guaranteed for the publications within any single subscription. 論理レプリケーションは、パブリッシャー側のデータベース上のデータのスナップショットをコピーすることから始まります。 それが完了したあとは、パブリッシャーにおける変更は、発生した時にリアルタイムでサブスクライバーに送られます。 サブスクライバーはパブリッシャーでコミットが発生した順にデータを適用します。 そのため、どの単一のサブスクリプションにおいても、パブリケーションに対するトランザクションの一貫性が保証されます。

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 plugin (pgoutput). 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. 《マッチ度[92.475728]》論理レプリケーションは物理ストリーミングレプリケーション(27.2.5参照)と似たアーキテクチャで構成されています。 WAL送信プロセスと適用プロセスで実装されています。 WAL送信プロセスはWALのロジカルデコーディング(第49章に記載)を開始し、標準のロジカルデコーディングプラグイン(pgoutput)をロードします。 このプラグインは、WALから読み込んだ更新を論理レプリケーションプロトコル(55.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の行と文トリガーの両方を起動します。

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

<title>Initial Snapshot</title>

The initial data in existing subscribed tables are snapshotted and copied in a parallel instance of a special kind of apply process. This 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. 既存のサブスクライブされたテーブル中の初期データのスナップショットが取得され、特殊な適用プロセスの並列インスタンスにコピーされます。 このプロセスは自身のレプリケーションスロットを作成し、既存のデータをコピーします。 コピーが終わるとすぐにテーブル内容が他のバックエンドから見えるようになります。 既存のデータのコピーが終わると、ワーカーは同期モードに入ります。 このモードでは、初期データのコピー中に起こった更新を標準の論理レプリケーションを使ってストリーミングすることにより、テーブルが主適用プロセスと同期状態になることを保証します。 この同期フェーズの間、パブリッシャーで発生したのと同じ順序で変更が適用され、コミットされます。 ひとたび同期が完了すれば、テーブルのレプリケーションの制御は主適用プロセスに戻され、レプリケーションは通常通り継続されます。

注記

The publication <link linkend="sql-createpublication-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. 《マッチ度[74.275362]》パブリケーションのパブリッシュパラメータは、レプリケーションされるDML操作にのみ影響します。 初期データ同期では、既存のテーブルデータをコピーするときにこのパラメータは考慮されません。 《機械翻訳》publishパラメータは、DML操作が複製されるかどうかにのみ影響します。 既存のテーブルデータをコピーする場合、初期データ同期ではこのパラメータは考慮されません。