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

第31章 論理レプリケーション

目次

31.1. パブリケーション
31.2. サブスクリプション
31.2.1. レプリケーションスロットの管理
31.2.2. Examples: Set Up Logical Replication
31.2.3. Examples: Deferred Replication Slot Creation
31.3. 行フィルタ
31.3.1. 行フィルタルール
31.3.2. 式の制限
31.3.3. UPDATE変換
31.3.4. パーティション化テーブル
31.3.5. 初期データ同期
31.3.6. 複数行フィルタの統合
31.3.7. 例
31.4. 列リスト
31.4.1. 例
31.5. コンフリクト
31.6. 制限事項
31.7. アーキテクチャ
31.7.1. 初期スナップショット
31.8. 監視
31.9. セキュリティ
31.10. 構成設定
31.10.1. Publishers
31.10.2. Subscribers
31.11. 簡単な設定
<title>Logical Replication</title>

Logical replication is a method of replicating data objects and their changes, based upon their replication identity (usually a primary key). We use the term logical in contrast to physical replication, which uses exact block addresses and byte-by-byte replication. PostgreSQL supports both mechanisms concurrently, see <xref linkend="high-availability"/>. Logical replication allows fine-grained control over both data replication and security. 論理レプリケーションとは、レプリケーションアイデンティティ(replication identity)(通常は主キーです)に基づき、データオブジェクトと、それに対する変更を複製する手法です。 この論理という用語は、正確なブロックアドレスを使い、バイト同士の複製を行う物理レプリケーションと対比的に使用しています。 PostgreSQLは両方の仕組みを同時にサポートします。 第27章をご覧ください。 論理レプリケーションにより、データの複製とセキュリティに対するきめの細かい制御が可能になります。

Logical replication uses a <firstterm>publish</firstterm> and <firstterm>subscribe</firstterm> model with one or more <firstterm>subscribers</firstterm> subscribing to one or more <firstterm>publications</firstterm> on a <firstterm>publisher</firstterm> node. Subscribers pull data from the publications they subscribe to and may subsequently re-publish data to allow cascading replication or more complex configurations. 論理レプリケーションは、ひとつのパブリッシャー(publisher)ノード上の一つ以上のパブリケーション(publications)を購読する一つ以上のサブスクライバー(subscribers)を伴う、パブリッシュ(publish)サブスクライブ(subscribe)モデルを使用します。 サブスクライバーは、サブスクライブするパブリケーションからデータを取得し、再パブリッシュしてカスケードレプリケーションや、更に複雑な構成を構築することができます。

Logical replication of a table typically starts with taking a snapshot of the data on the publisher database and copying that to the subscriber. Once that is done, the changes on the publisher are sent to the subscriber as they occur in real-time. The subscriber applies the data in the same order as the publisher so that transactional consistency is guaranteed for publications within a single subscription. This method of data replication is sometimes referred to as transactional replication. テーブルの論理レプリケーションは、通常、パブリッシャーのデータベース上のデータのスナップショットを取り、サブスクライバーにコピーすることから始まります。 それが完了したあとは、パブリッシャーにおける変更は、発生した時にリアルタイムでサブスクライバーに送られます。 サブスクライバーはパブリッシャーと同じ順にデータを適用します。 そのため、一つのサブスクリプション内のパブリケーションに対するトランザクションの一貫性が保証されます。 この方式によるデータレプリケーションは、トランザクショナルレプリケーション(transactional replication)と呼ばれることがあります。

The typical use-cases for logical replication are: 典型的な論理レプリケーションの利用例には、以下のようなものがあります。

The subscriber database behaves in the same way as any other PostgreSQL instance and can be used as a publisher for other databases by defining its own publications. When the subscriber is treated as read-only by application, there will be no conflicts from a single subscription. On the other hand, if there are other writes done either by an application or by other subscribers to the same set of tables, conflicts can arise. サブスクライバーのデータベースは、他のPostgreSQLインスタンスと同様に振る舞い、自分用のパブリケーションを定義することにより、他のデータベースに対するパブリッシャーとして利用できます。 アプリケーションがそのサブスクライバーを読み取り専用として取り扱うときには、単独のサブスクリプションからはコンフリクトは発生しません。 一方、アプリケーションあるいは他のサブスクライバーから同じテーブルに書き込みが起こるとすると、コンフリクトが発生する可能性があります。