Implementation:2ndQuadrant Pglogical Report Conflict
| Knowledge Sources | |
|---|---|
| Domains | Database, Replication, Monitoring |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Function that logs conflict details at the configured log level, including conflict type, relation name, local and remote tuple contents, resolution applied, and origin information.
Description
The pglogical_report_conflict() function generates a detailed log message when a replication conflict is detected and resolved. The log level is controlled by the pglogical.conflict_log_level GUC (default: LOG). The log message includes:
- Conflict type (CONFLICT_INSERT_INSERT, UPDATE_UPDATE, UPDATE_DELETE, DELETE_DELETE)
- Relation name (schema-qualified)
- Local tuple contents (formatted via tuple deconstruction)
- Remote tuple contents
- Applied tuple (the winning tuple after resolution)
- Resolution decision (ApplyRemote, KeepLocal, Skip)
- Local tuple origin (RepOriginId) and commit timestamp (if available)
- Conflict index name (the index where the conflict was detected)
This function is called from the heap apply backend after try_resolve_conflict() completes.
Usage
This is an internal function called during conflict resolution. Users configure its behavior via GUCs:
- pglogical.conflict_log_level: Controls the log level (LOG, NOTICE, WARNING, etc.)
Code Reference
Source Location
- Repository: pglogical
- File: pglogical_conflict.c
- Lines: L649-860
Signature
void pglogical_report_conflict(PGLogicalConflictType conflict_type,
PGLogicalRelation *rel,
HeapTuple localtuple,
PGLogicalTupleData *oldkey,
HeapTuple remotetuple,
HeapTuple applytuple,
PGLogicalConflictResolution resolution,
TransactionId local_tuple_xid,
bool found_local_origin,
RepOriginId local_tuple_origin,
TimestampTz local_tuple_commit_ts,
Oid conflict_idx_oid,
bool has_before_triggers);
Import
#include "pglogical_conflict.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| conflict_type | PGLogicalConflictType | Yes INSERT_INSERT, UPDATE_UPDATE, UPDATE_DELETE, or DELETE_DELETE | |
| rel | PGLogicalRelation* | Yes Relation info with names | |
| localtuple | HeapTuple | No Existing local tuple (NULL if not found) | |
| oldkey | PGLogicalTupleData* | No Old key for UPDATE/DELETE | |
| remotetuple | HeapTuple | Yes Incoming remote tuple | |
| applytuple | HeapTuple | Yes Winning tuple after resolution | |
| resolution | PGLogicalConflictResolution | Yes Decision made (ApplyRemote/KeepLocal/Skip) | |
| local_tuple_xid | TransactionId | Yes XID of local tuple | |
| found_local_origin | bool | Yes Whether origin info was available | |
| local_tuple_origin | RepOriginId | Yes Origin of local tuple | |
| local_tuple_commit_ts | TimestampTz | Yes Commit time of local tuple | |
| conflict_idx_oid | Oid | Yes Index where conflict detected | |
| has_before_triggers | bool | Yes Whether BEFORE triggers fired |
Outputs
| Name | Type | Description |
|---|---|---|
| log message | ereport | Log entry at configured pglogical.conflict_log_level |
Usage Examples
Configuring Conflict Logging
-- In postgresql.conf:
pglogical.conflict_log_level = 'log' -- or 'notice', 'warning', etc.
pglogical.conflict_resolution = 'last_update_wins'
Sample Log Output
LOG: conflict detected on relation public.users with conflict type UPDATE_UPDATE
local tuple: (1, "alice", "alice@example.com", true)
remote tuple: (1, "alice", "alice@newdomain.com", true)
applied tuple: (1, "alice", "alice@newdomain.com", true)
resolution: apply_remote
local origin: 16384 (upstream_node)
local commit ts: 2026-01-15 10:30:00+00
conflict index: users_pkey