Logical replication behaves similarly to normal DML operations in that
the data will be updated even if it was changed locally on the subscriber
node. If incoming data violates any constraints the replication will
stop. This is referred to as a <firstterm>conflict</firstterm>. When
replicating <command>UPDATE</command> or <command>DELETE</command>
operations, missing data is also considered as a
<firstterm>conflict</firstterm>, but does not result in an error and such
operations will simply be skipped.
《マッチ度[81.065089]》サブスクライバーノードでローカルにデータが変更された場合でも、データが更新されるという点では、論理レプリケーションは通常のDML操作と同じように振る舞います。
到着したデータが制約に違反すると、レプリケーションは停止します。
これは、コンフリクトと呼ばれます。
UPDATE
あるいはDELETE
操作をレプリケーションする場合は、存在しないデータによってコンフリクトは起こらず、そのような操作は単にスキップされます。
《機械翻訳》論理レプリケーションは、サブスクライバーノードでローカルに変更された場合でもデータが更新されるという点で、通常のDML操作と同様に動作します。
着信データが制約に違反する場合、レプリケーションは停止します。
これはコンフリクトと呼ばれます。
レプリケーションUPDATE
またはDELETE
操作の場合、データがないこともコンフリクトとみなされますが、エラーにはならず、このような操作は単純にスキップされたになります。
Additional logging is triggered, and the conflict statistics are collected (displayed in the
<link linkend="monitoring-pg-stat-subscription-stats"><structname>pg_stat_subscription_stats</structname></link> view)
in the following <firstterm>conflict</firstterm> cases:
《機械翻訳》次のロギングの場合は、追加のコンフリクトがトリガされ、統計処理のビューが徴収されますpg_stat_subscription_stats
コンフリクトに表示されます。
insert_exists
#
Inserting a row that violates a <literal>NOT DEFERRABLE</literal>
unique constraint. Note that to log the origin and commit
timestamp details of the conflicting key,
<link linkend="guc-track-commit-timestamp"><varname>track_commit_timestamp</varname></link>
should be enabled on the subscriber. In this case, an error will be
raised until the conflict is resolved manually.
《機械翻訳》挿入競合する行の一意性制約とコミットノートの詳細NOT DEFERRABLE
track_commit_timestamp
をログに伝えるオリジン.タイムスタンプに違反するキーは、サブスクライバーで使用可能にする必要があります。
このケースでは、コンフリクトが手動で解決されるまでエラーが発生します。
update_origin_differs
#
Updating a row that was previously modified by another origin.
Note that this conflict can only be detected when
<link linkend="guc-track-commit-timestamp"><varname>track_commit_timestamp</varname></link>
is enabled on the subscriber. Currently, the update is always applied
regardless of the origin of the local row.
《機械翻訳》更新以前に別の行によって変更されたオリジン。
このノートは、サブスクライバーでtrack_commit_timestamp
が有効になっている場合にのみ検出できます。
現在、更新は、ローカル行のオリジンに関係なく常に適用されます。
コンフリクト
update_exists
#
The updated value of a row violates a <literal>NOT DEFERRABLE</literal>
unique constraint. Note that to log the origin and commit
timestamp details of the conflicting key,
<link linkend="guc-track-commit-timestamp"><varname>track_commit_timestamp</varname></link>
should be enabled on the subscriber. In this case, an error will be
raised until the conflict is resolved manually. Note that when updating a
partitioned table, if the updated row value satisfies another partition
constraint resulting in the row being inserted into a new partition, the
<literal>insert_exists</literal> conflict may arise if the new row
violates a <literal>NOT DEFERRABLE</literal> unique constraint.
《機械翻訳》行違反の更新された値は、一意性制約で有効にする必要がありますNOT DEFERRABLE
競合するノートのオリジンとコミットタイムスタンプの詳細をログに伝えるには、track_commit_timestamp
。
このケースでは、コンフリクトが手動で解決されるまでエラーが発生します。
ノートでは、更新がテーブルを分割した場合、更新された行値が別のパーティション制約を満たし、行が新しいパーティションに挿入されると、新しい行がNOT DEFERRABLE
一意性制約に違反するとinsert_exists
コンフリクトが発生する可能性があります。
キーサブスクライバー
update_missing
#The row to be updated was not found. The update will simply be skipped in this scenario. 《機械翻訳》更新される行が見つかりませんでした。 更新はこのシナリオのスキップされたになります。
delete_origin_differs
#
Deleting a row that was previously modified by another origin. Note that
this conflict can only be detected when
<link linkend="guc-track-commit-timestamp"><varname>track_commit_timestamp</varname></link>
is enabled on the subscriber. Currently, the delete is always applied
regardless of the origin of the local row.
《機械翻訳》削除以前に別の行によって変更されたオリジン。
このノートは、サブスクライバーでtrack_commit_timestamp
が有効になっている場合にのみ検出できます。
現在、削除は、ローカル行のオリジンに関係なく常に適用されます。
コンフリクト
delete_missing
#The row to be deleted was not found. The delete will simply be skipped in this scenario. 《機械翻訳》削除する行が見つかりませんでした。 削除は単にこのシナリオのスキップされたになります。
multiple_unique_conflicts
#
Inserting or updating a row violates multiple
<literal>NOT DEFERRABLE</literal> unique constraints. Note that to log
the origin and commit timestamp details of conflicting keys, ensure
that <link linkend="guc-track-commit-timestamp"><varname>track_commit_timestamp</varname></link>
is enabled on the subscriber. In this case, an error will be raised until
the conflict is resolved manually.
《機械翻訳》挿入または更新行がマルチプルに違反していますNOT DEFERRABLE
一意制約。
オリジンおよびコミットタイムスタンプに競合するキーの詳細をログに通知するノート、サブスクライバーでtrack_commit_timestamp
が有効になっている保証。
このケースでは、コンフリクトが手動で解決されるまでエラーが発生します。
Note that there are other conflict scenarios, such as exclusion constraint violations. Currently, we do not provide additional details for them in the log.
The log format for logical replication conflicts is as follows: 《機械翻訳》論理レプリケーション紛争のログフォーマットは以下の通りである。
LOG: conflict detected on relation "schemaname
.tablename
": conflict=conflict_type
DETAIL:detailed_explanation
. {detail_values
[; ... ]}. wheredetail_values
is one of:Key
(column_name
[, ...])=(column_value
[, ...])existing local row
[(column_name
[, ...])=](column_value
[, ...])remote row
[(column_name
[, ...])=](column_value
[, ...])replica identity
{(column_name
[, ...])=(column_value
[, ...]) | full [(column_name
[, ...])=](column_value
[, ...])}
The log provides the following information: 《機械翻訳》ログでは、次の情報が提供されます。
LOG
<replaceable>schemaname</replaceable>.<replaceable>tablename</replaceable>
identifies the local relation involved in the conflict.
《機械翻訳》schemaname
.tablename
は、コンフリクトに含まれるローカルリレーションを識別する。
<replaceable>conflict_type</replaceable> is the type of conflict that occurred
(e.g., <literal>insert_exists</literal>, <literal>update_exists</literal>).
《機械翻訳》conflict_type
は、発生したコンフリクトのタイプであるinsert_exists
例:,update_exists
。
DETAIL
<replaceable class="parameter">detailed_explanation</replaceable> includes
the origin, transaction ID, and commit timestamp of the transaction that
modified the existing local row, if available.
《機械翻訳》detailed_explanation
ローカルタイムスタンプを変更したトランザクションのオリジン、トランザクションID及びコミット行がある場合は、それを含む。
The <literal>Key</literal> section includes the key values of the local
row that violated a unique constraint for
<literal>insert_exists</literal>, <literal>update_exists</literal> or
<literal>multiple_unique_conflicts</literal> conflicts.
《機械翻訳》Key
セクションには、insert_exists
、update_exists
またはmultiple_unique_conflicts
紛争のキーに違反したローカル行の一意性制約値が含まれる。
The <literal>existing local row</literal> section includes the local
row if its origin differs from the remote row for
<literal>update_origin_differs</literal> or <literal>delete_origin_differs</literal>
conflicts, or if the key value conflicts with the remote row for
<literal>insert_exists</literal>, <literal>update_exists</literal> or
<literal>multiple_unique_conflicts</literal> conflicts.
《機械翻訳》existing local row
セクションにはローカル行が含まれます。
ただし、そのオリジンがupdate_origin_differs
またはdelete_origin_differs
競合する場合のリモート行と異なる場合、またはキーの値がinsert_exists
、update_exists
またはmultiple_unique_conflicts
競合する場合のリモート行と競合する場合です。
The <literal>remote row</literal> section includes the new row from
the remote insert or update operation that caused the conflict. Note that
for an update operation, the column value of the new row will be null
if the value is unchanged and toasted.
《機械翻訳》remote row
セクションには、行を発生させたリモート挿入または更新オペレーションからの新しいコンフリクトが含まれます。
ノート更新オペレーションの場合、値が変更されず、TOAST化されている場合、新しい行のカラム値はNULLになります。
The <literal>replica identity</literal> section includes the replica
identity key values that were used to search for the existing local
row to be updated or deleted. This may include the full row value
if the local relation is marked with
<link linkend="sql-altertable-replica-identity-full"><literal>REPLICA IDENTITY FULL</literal></link>.
《機械翻訳》replica identity
セクションには、更新または削除される既存のレプリカアイデンティティキーの検索に使用されたローカル行値が含まれます。
ローカルリレーションがREPLICA IDENTITY FULL
でマークされている場合は、行値全体がincludeされることがあります。
<replaceable class="parameter">column_name</replaceable> is the column name.
For <literal>existing local row</literal>, <literal>remote row</literal>,
and <literal>replica identity full</literal> cases, column names are
logged only if the user lacks the privilege to access all columns of
the table. If column names are present, they appear in the same order
as the corresponding column values.
《機械翻訳》column_name
はカラム名前です。
existing local row
、remote row
、およびreplica identity full
の場合、カラム名はユーザにテーブルの権限からアクセスまでのすべての列がない場合にのみログに記録されます。
カラム名が存在する場合は、対応するカラム値と同じオーダーに表示されます。
<replaceable class="parameter">column_value</replaceable> is the column value.
The large column values are truncated to 64 bytes.
《機械翻訳》column_value
はカラムの値です。
ラージのカラムの値は64バイトに切り捨てられます。
Note that in case of <literal>multiple_unique_conflicts</literal> conflict,
multiple <replaceable class="parameter">detailed_explanation</replaceable>
and <replaceable class="parameter">detail_values</replaceable> lines
will be generated, each detailing the conflict information associated
with distinct unique
constraints.
《機械翻訳》ケースのノートmultiple_unique_conflicts
コンフリクト、マルチプルdetailed_explanation
およびdetail_values
線が生成され、各線には個別の一意性制約に関連付けられたコンフリクト情報が詳述されます。
Logical replication operations are performed with the privileges of the role
which owns the subscription. Permissions failures on target tables will
cause replication conflicts, as will enabled
<link linkend="ddl-rowsecurity">row-level security</link> on target tables
that the subscription owner is subject to, without regard to whether any
policy would ordinarily reject the <command>INSERT</command>,
<command>UPDATE</command>, <command>DELETE</command> or
<command>TRUNCATE</command> which is being replicated. This restriction on
row-level security may be lifted in a future version of
<productname>PostgreSQL</productname>.
論理レプリケーション操作は、サブスクリプションを所有するロールの権限を使用して実行されます。
対象テーブルで権限違反が起こると、レプリケーション競合が発生します。
これは、サブスクリプション所有者が従う、対象テーブルで有効な行レベルセキュリティと同じですが、レプリケーションされているINSERT
、UPDATE
、DELETE
またはTRUNCATE
をポリシーが通常拒否するかどうかには関係ありません。
行レベルセキュリティに対するこの制限は、PostgreSQLの将来のバージョンで解除される可能性があります。
A conflict that produces an error will stop the replication; it must be resolved manually by the user. Details about the conflict can be found in the subscriber's server log. 《マッチ度[89.080460]》コンフリクトはエラーを生じさせ、レプリケーションを停止させます。 コンフリクトはユーザが手動で解消しなければなりません。 コンフリクトの詳細は、サブスクライバーのサーバログに出力されます。 《機械翻訳》コンフリクトがエラーを発生させると、レプリケーションが停止します。 これは、ユーザが手動で解決する必要があります。 コンフリクトの詳細は、サブスクライバーのサーバログを参照してください。
The resolution can be done either by changing data or permissions on the subscriber so that it does not conflict with the incoming change or by skipping the transaction that conflicts with the existing data. When a conflict produces an error, the replication won't proceed, and the logical replication worker will emit the following kind of message to the subscriber's server log: この問題を解決するには、データを変更するか、サブスクライバーに対する権限を変更して、既存の変更でコンフリクトしないようにするか、既存のトランザクションと競合するデータをスキップします。 コンフリクトよってエラーが発生した場合、レプリケーションは処理を続行せず、論理レプリケーションワーカーは次のようなメッセージをサブスクライバーのサーバログに送信します。
ERROR: conflict detected on relation "public.test": conflict=insert_exists DETAIL: Key already exists in unique index "t_pkey", which was modified locally in transaction 740 at 2024-06-26 10:47:04.727375+08. Key (c)=(1); existing local row (1, 'local'); remote row (1, 'remote'). CONTEXT: processing remote data for replication origin "pg_16395" during "INSERT" for replication target relation "public.test" in transaction 725 finished at 0/14C0378
The LSN of the transaction that contains the change violating the constraint and
the replication origin name can be found from the server log (LSN 0/14C0378 and
replication origin <literal>pg_16395</literal> in the above case). The
transaction that produced the conflict can be skipped by using
<link linkend="sql-altersubscription-params-skip"><command>ALTER SUBSCRIPTION ... SKIP</command></link>
with the finish LSN
(i.e., LSN 0/14C0378). The finish LSN could be an LSN at which the transaction
is committed or prepared on the publisher. Alternatively, the transaction can
also be skipped by calling the <link linkend="pg-replication-origin-advance">
<function>pg_replication_origin_advance()</function></link> function.
Before using this function, the subscription needs to be disabled temporarily
either by <link linkend="sql-altersubscription-params-disable">
<command>ALTER SUBSCRIPTION ... DISABLE</command></link> or, the
subscription can be used with the
<link linkend="sql-createsubscription-params-with-disable-on-error"><literal>disable_on_error</literal></link>
option. Then, you can use <function>pg_replication_origin_advance()</function>
function with the <parameter>node_name</parameter> (i.e., <literal>pg_16395</literal>)
and the next LSN of the finish LSN (i.e., 0/14C0379). The current position of
origins can be seen in the <link linkend="view-pg-replication-origin-status">
<structname>pg_replication_origin_status</structname></link> system view.
Please note that skipping the whole transaction includes skipping changes that
might not violate any constraint. This can easily make the subscriber
inconsistent.
The additional details regarding conflicting rows, such as their origin and
commit timestamp can be seen in the <literal>DETAIL</literal> line of the
log. But note that this information is only available when
<link linkend="guc-track-commit-timestamp"><varname>track_commit_timestamp</varname></link>
is enabled on the subscriber. Users can use this information to decide
whether to retain the local change or adopt the remote alteration. For
instance, the <literal>DETAIL</literal> line in the above log indicates that
the existing row was modified locally. Users can manually perform a
remote-change-win.
《マッチ度[69.924141]》制約とレプリケーションの起点名に違反する変更を含むトランザクションのLSNは、サーバログ(LSN 0/14C0378とレプリケーション起点pg_16395
)から見つけることができます。
競合を発生させたトランザクションは、終了LSN(LSN 0/14C0378)でALTER SUBSCRIPTION ... SKIP
を使用してスキップできます。
終了LSNは、パブリッシャーでトランザクションがコミットまたは準備されたLSNにすることができます。
あるいは、pg_replication_origin_advance()
関数を呼び出して、トランザクションをスキップすることもできます。
この関数を使用する前に、ALTER SUBSCRIPTION ... DISABLE
を使用してサブスクリプションを一時的に無効にする必要があります。
また、サブスクリプションはdisable_on_error
オプションを使用して使用できます。
次に、pg_replication_origin_advance()
関数をnode_name
(pg_16395
)と終了LSNの次のLSN(0/14C0379)と共に使用できます。
現在の起点の位置は、pg_replication_origin_status
システムビューで確認できます。
トランザクション全体をスキップすることは、いかなる制約にも違反しない可能性のある変更をスキップすることを含むことに注意してください。
これは容易にサブスクライバーを不整合にする可能性があります。
《機械翻訳》トランザクションと複製元包含に違反する変更がある制約のLSNは、名前から見つけることができます(前述のケースのLSN 0/14C0378および複製元pg_16395
)。
コンフリクトを作成したトランザクションは、終了LSN(つまり、LSN 0/14C0378)でALTER SUBSCRIPTION...SKIP
を使用してスキップされたにすることができます。
終了LSNは、トランザクションがコミットされているLSN、またはパブリッシャー上のプリペアドにすることができます。
また、この関数を使用してpg_replication_origin_advance()
関数.前を呼び出すことでトランザクションをスキップされたにすることもできます。
サブスクリプションニーズはALTER SUBSCRIPTION...DISABLE
によって一時的に無効にするか、サブスクリプションをdisable_on_error
オプションで使用できます。
次に、pg_replication_origin_advance()
関数をnode_name
(つまり、pg_16395
)および終了LSNの次のLSN(つまり、0/14C0379)と一緒に使用できます。
元の現在の位置はpg_replication_origin_status
に表示されます。
この情報は、サブスクライバーでtrack_commit_timestamp
が有効になっている場合にのみ利用可能であることに注意してください。
ユーザはこの情報を使用して、ローカルの変更を保持するか、リモートの変更を採用するかを決定できます。
たとえば、上記のログのDETAIL
行は、既存の行がローカルで変更されたことを示しています。
ユーザは手動でリモート変更を実行できます。
When the
<link linkend="sql-createsubscription-params-with-streaming"><literal>streaming</literal></link>
mode is <literal>parallel</literal>, the finish LSN of failed transactions
may not be logged. In that case, it may be necessary to change the streaming
mode to <literal>on</literal> or <literal>off</literal> and cause the same
conflicts again so the finish LSN of the failed transaction will be written
to the server log. For the usage of finish LSN, please refer to <link
linkend="sql-altersubscription"><command>ALTER SUBSCRIPTION ...
SKIP</command></link>.
streaming
モードがparallel
の場合、失敗したトランザクションの終了LSNはログに書き込まれないことがあります。
その場合、ストリーミングモードをon
またはoff
に変更し、再度同じコンフリクトを起こすことで、失敗したトランザクションの終了LSNをサーバのログに書き込むようにする必要があるかもしれません。
終了LSNの使用方法については、ALTER SUBSCRIPTION ... SKIP
を参照してください。