PostgreSQL Source Code git master
Loading...
Searching...
No Matches
conflict.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 * conflict.c
3 * Support routines for logging conflicts.
4 *
5 * Copyright (c) 2024-2026, PostgreSQL Global Development Group
6 *
7 * IDENTIFICATION
8 * src/backend/replication/logical/conflict.c
9 *
10 * This file contains the code for logging conflicts on the subscriber during
11 * logical replication.
12 *-------------------------------------------------------------------------
13 */
14
15#include "postgres.h"
16
17#include "access/commit_ts.h"
18#include "access/genam.h"
19#include "access/tableam.h"
20#include "catalog/heap.h"
21#include "catalog/pg_am.h"
23#include "catalog/toasting.h"
24#include "executor/executor.h"
25#include "pgstat.h"
28#include "storage/lmgr.h"
29#include "utils/lsyscache.h"
30
31/*
32 * String representations for the supported conflict logging destinations.
33 */
34const char *const ConflictLogDestNames[] = {
35 [CONFLICT_LOG_DEST_LOG] = "log",
36 [CONFLICT_LOG_DEST_TABLE] = "table",
37 [CONFLICT_LOG_DEST_ALL] = "all"
38};
39
41 "ConflictLogDestNames length mismatch");
42
43
44/* Structure to hold metadata for one column of the conflict log table */
46{
47 const char *attname; /* Column name */
48 Oid atttypid; /* Data type OID */
50
51/*
52 * Schema definition for conflict log tables.
53 *
54 * Defines the fixed schema of the per-subscription conflict log table created
55 * in the pg_conflict namespace. Each entry specifies the column name and its
56 * type OID; the table is created in this column order by
57 * create_conflict_log_table().
58 *
59 * The tuple/key columns (replica_identity, remote_tuple, local_conflicts) are
60 * typed json rather than jsonb on purpose: they hold an exact audit snapshot
61 * of the applied tuples and replica identity, and json preserves the verbatim
62 * representation whereas jsonb would normalize it. Indexing them (jsonb's main
63 * advantage) wouldn't help anyway, as the conflict log is looked up by its
64 * scalar columns (relid, conflict_type, commit timestamp) while these json
65 * columns are per-conflict payload to inspect, not search keys.
66 */
68 {.attname = "relid", .atttypid = OIDOID},
69 {.attname = "schemaname", .atttypid = TEXTOID},
70 {.attname = "relname", .atttypid = TEXTOID},
71 {.attname = "conflict_type", .atttypid = TEXTOID},
72 {.attname = "remote_xid", .atttypid = XIDOID},
73 {.attname = "remote_commit_lsn", .atttypid = LSNOID},
74 {.attname = "remote_commit_ts", .atttypid = TIMESTAMPTZOID},
75 {.attname = "remote_origin", .atttypid = TEXTOID},
76 {.attname = "replica_identity_full", .atttypid = BOOLOID},
77 {.attname = "replica_identity", .atttypid = JSONOID},
78 {.attname = "remote_tuple", .atttypid = JSONOID},
79 {.attname = "local_conflicts", .atttypid = JSONARRAYOID}
80};
81
82#define NUM_CONFLICT_ATTRS ((AttrNumber) lengthof(ConflictLogSchema))
83
84static const char *const ConflictTypeNames[] = {
85 [CT_INSERT_EXISTS] = "insert_exists",
86 [CT_UPDATE_ORIGIN_DIFFERS] = "update_origin_differs",
87 [CT_UPDATE_EXISTS] = "update_exists",
88 [CT_UPDATE_MISSING] = "update_missing",
89 [CT_DELETE_ORIGIN_DIFFERS] = "delete_origin_differs",
90 [CT_UPDATE_DELETED] = "update_deleted",
91 [CT_DELETE_MISSING] = "delete_missing",
92 [CT_MULTIPLE_UNIQUE_CONFLICTS] = "multiple_unique_conflicts"
93};
94
96static void errdetail_apply_conflict(EState *estate,
102 Oid indexoid, TransactionId localxmin,
105static void get_tuple_desc(EState *estate, ResultRelInfo *relinfo,
106 ConflictType type, char **key_desc,
110 Oid indexoid);
111static char *build_index_value_desc(EState *estate, Relation localrel,
112 TupleTableSlot *slot, Oid indexoid);
113
114/*
115 * Builds the TupleDesc for the conflict log table.
116 */
117static TupleDesc
119{
120 TupleDesc tupdesc;
121
123
124 for (int i = 0; i < NUM_CONFLICT_ATTRS; i++)
125 TupleDescInitEntry(tupdesc, i + 1,
127 ConflictLogSchema[i].atttypid,
128 -1, 0);
129
130 TupleDescFinalize(tupdesc);
131
132 return tupdesc;
133}
134
135/*
136 * Create a structured conflict log table for a subscription.
137 *
138 * The table is created within the system-managed 'pg_conflict' namespace to
139 * prevent users from manually dropping or altering it. This also prevents
140 * accidental name collisions with user-created tables with the same name.
141 *
142 * The table name is generated automatically using the subscription's OID
143 * (e.g., "pg_conflict_log_<subid>") to ensure uniqueness within the
144 * cluster and to avoid collisions during subscription renames.
145 */
146Oid
148{
149 TupleDesc tupdesc;
150 Oid relid;
151 char relname[NAMEDATALEN];
152
153 snprintf(relname, NAMEDATALEN, "pg_conflict_log_%u", subid);
154
155 /* Build the tuple descriptor for the new table. */
157
158 /* Create conflict log table. */
161 0, /* tablespace */
162 InvalidOid, /* relid */
163 InvalidOid, /* reltypeid */
164 InvalidOid, /* reloftypeid */
165 subowner,
167 tupdesc,
168 NIL,
171 false, /* shared_relation */
172 false, /* mapped_relation */
174 (Datum) 0, /* reloptions */
175 false, /* use_user_acl */
176 false, /* allow_system_table_mods */
177 true, /* is_internal */
178 InvalidOid, /* relrewrite */
179 NULL); /* typaddress */
180 Assert(OidIsValid(relid));
181
182 /* Release tuple descriptor memory. */
183 FreeTupleDesc(tupdesc);
184
185 /*
186 * We must bump the command counter to make the newly-created relation
187 * tuple visible for opening.
188 */
190
191 /*
192 * Create a TOAST table for the conflict log to support out-of-line
193 * storage of large json data.
194 */
196
198 (errmsg("created conflict log table \"%s\" for subscription \"%s\"",
200 subname)));
201
202 return relid;
203}
204
205/*
206 * Convert the string representation of a conflict logging destination to its
207 * corresponding enum value.
208 */
210GetConflictLogDest(const char *dest)
211{
212 /* NULL defaults to LOG. */
213 if (dest == NULL || pg_strcasecmp(dest, "log") == 0)
215
216 if (pg_strcasecmp(dest, "table") == 0)
218
219 if (pg_strcasecmp(dest, "all") == 0)
221
222 /* Unrecognized string. */
225 errmsg("unrecognized conflict_log_destination value: \"%s\"", dest),
226 errhint("Valid values are \"log\", \"table\", and \"all\".")));
227}
228
229/*
230 * Get the xmin and commit timestamp data (origin and timestamp) associated
231 * with the provided local row.
232 *
233 * Return true if the commit timestamp data was found, false otherwise.
234 */
235bool
238{
240 bool isnull;
241
243 &isnull);
245 Assert(!isnull);
246
247 /*
248 * The commit timestamp data is not available if track_commit_timestamp is
249 * disabled.
250 */
252 {
254 *localts = 0;
255 return false;
256 }
257
259}
260
261/*
262 * This function is used to report a conflict while applying replication
263 * changes.
264 *
265 * 'searchslot' should contain the tuple used to search the local row to be
266 * updated or deleted.
267 *
268 * 'remoteslot' should contain the remote new tuple, if any.
269 *
270 * conflicttuples is a list of local rows that caused the conflict and the
271 * conflict related information. See ConflictTupleInfo.
272 *
273 * The caller must ensure that all the indexes passed in ConflictTupleInfo are
274 * locked so that we can fetch and display the conflicting key values.
275 */
276void
280{
281 Relation localrel = relinfo->ri_RelationDesc;
283
285
286 /* Form errdetail message by combining conflicting tuples information. */
290 conflicttuple->indexoid,
291 conflicttuple->xmin,
292 conflicttuple->origin,
293 conflicttuple->ts,
294 &err_detail);
295
297
298 ereport(elevel,
300 errmsg("conflict detected on relation \"%s.%s\": conflict=%s",
302 RelationGetRelationName(localrel),
304 errdetail_internal("%s", err_detail.data));
305}
306
307/*
308 * Find all unique indexes to check for a conflict and store them into
309 * ResultRelInfo.
310 */
311void
313{
315
316 for (int i = 0; i < relInfo->ri_NumIndices; i++)
317 {
318 Relation indexRelation = relInfo->ri_IndexRelationDescs[i];
319
320 if (indexRelation == NULL)
321 continue;
322
323 /* Detect conflict only for unique indexes */
324 if (!relInfo->ri_IndexRelationInfo[i]->ii_Unique)
325 continue;
326
327 /* Don't support conflict detection for deferrable index */
328 if (!indexRelation->rd_index->indimmediate)
329 continue;
330
332 RelationGetRelid(indexRelation));
333 }
334
335 relInfo->ri_onConflictArbiterIndexes = uniqueIndexes;
336}
337
338/*
339 * Add SQLSTATE error code to the current conflict report.
340 */
341static int
343{
344 switch (type)
345 {
346 case CT_INSERT_EXISTS:
347 case CT_UPDATE_EXISTS:
356 }
357
358 Assert(false);
359 return 0; /* silence compiler warning */
360}
361
362/*
363 * Helper function to build the additional details for conflicting key,
364 * local row, remote row, and replica identity columns.
365 */
366static void
368{
369 bool first = true;
370
371 Assert(buf != NULL && tuple_values != NIL);
372
374 {
375 /*
376 * Skip if the value is NULL. This means the current user does not
377 * have enough permissions to see all columns in the table. See
378 * get_tuple_desc().
379 */
380 if (!tuple_value)
381 continue;
382
383 /* standard SQL punctuation, not translated */
384 if (!first)
386
388 first = false;
389 }
390}
391
392/*
393 * Add an errdetail() line showing conflict detail.
394 *
395 * The DETAIL line comprises of two parts:
396 * 1. Explanation of the conflict type, including the origin and commit
397 * timestamp of the local row.
398 * 2. Display of conflicting key, local row, remote new row, and replica
399 * identity columns, if any. The remote old row is excluded as its
400 * information is covered in the replica identity columns.
401 */
402static void
406 Oid indexoid, TransactionId localxmin,
408 StringInfo err_msg)
409{
412 char *origin_name;
413 char *key_desc = NULL;
414 char *local_desc = NULL;
415 char *remote_desc = NULL;
416 char *search_desc = NULL;
417
418 /* Get key, replica identity, remote, and local value data */
423 indexoid);
424
427
428 /* Construct a detailed message describing the type of conflict */
429 switch (type)
430 {
431 case CT_INSERT_EXISTS:
432 case CT_UPDATE_EXISTS:
434 Assert(OidIsValid(indexoid) &&
436
437 if (err_msg->len == 0)
438 {
441
442 if (tuple_buf.len)
443 appendStringInfo(&err_detail, _("Could not apply remote change: %s.\n"),
444 tuple_buf.data);
445 else
446 appendStringInfo(&err_detail, _("Could not apply remote change.\n"));
447
448
450 }
451
454
455 if (localts)
456 {
458 {
459 if (tuple_buf.len)
460 appendStringInfo(&err_detail, _("Key already exists in unique index \"%s\", modified locally in transaction %u at %s: %s."),
461 get_rel_name(indexoid),
463 tuple_buf.data);
464 else
465 appendStringInfo(&err_detail, _("Key already exists in unique index \"%s\", modified locally in transaction %u at %s."),
466 get_rel_name(indexoid),
468 }
469 else if (replorigin_by_oid(localorigin, true, &origin_name))
470 {
471 if (tuple_buf.len)
472 appendStringInfo(&err_detail, _("Key already exists in unique index \"%s\", modified by origin \"%s\" in transaction %u at %s: %s."),
473 get_rel_name(indexoid), origin_name,
475 tuple_buf.data);
476 else
477 appendStringInfo(&err_detail, _("Key already exists in unique index \"%s\", modified by origin \"%s\" in transaction %u at %s."),
478 get_rel_name(indexoid), origin_name,
480 }
481
482 /*
483 * The origin that modified this row has been removed. This
484 * can happen if the origin was created by a different apply
485 * worker and its associated subscription and origin were
486 * dropped after updating the row, or if the origin was
487 * manually dropped by the user.
488 */
489 else
490 {
491 if (tuple_buf.len)
492 appendStringInfo(&err_detail, _("Key already exists in unique index \"%s\", modified by a non-existent origin in transaction %u at %s: %s."),
493 get_rel_name(indexoid),
495 tuple_buf.data);
496 else
497 appendStringInfo(&err_detail, _("Key already exists in unique index \"%s\", modified by a non-existent origin in transaction %u at %s."),
498 get_rel_name(indexoid),
500 }
501 }
502 else
503 {
504 if (tuple_buf.len)
505 appendStringInfo(&err_detail, _("Key already exists in unique index \"%s\", modified in transaction %u: %s."),
506 get_rel_name(indexoid), localxmin,
507 tuple_buf.data);
508 else
509 appendStringInfo(&err_detail, _("Key already exists in unique index \"%s\", modified in transaction %u."),
510 get_rel_name(indexoid), localxmin);
511 }
512
513 break;
514
518 search_desc));
519
521 {
522 if (tuple_buf.len)
523 appendStringInfo(&err_detail, _("Updating the row that was modified locally in transaction %u at %s: %s."),
525 tuple_buf.data);
526 else
527 appendStringInfo(&err_detail, _("Updating the row that was modified locally in transaction %u at %s."),
529 }
530 else if (replorigin_by_oid(localorigin, true, &origin_name))
531 {
532 if (tuple_buf.len)
533 appendStringInfo(&err_detail, _("Updating the row that was modified by a different origin \"%s\" in transaction %u at %s: %s."),
534 origin_name, localxmin,
536 tuple_buf.data);
537 else
538 appendStringInfo(&err_detail, _("Updating the row that was modified by a different origin \"%s\" in transaction %u at %s."),
539 origin_name, localxmin,
541 }
542
543 /* The origin that modified this row has been removed. */
544 else
545 {
546 if (tuple_buf.len)
547 appendStringInfo(&err_detail, _("Updating the row that was modified by a non-existent origin in transaction %u at %s: %s."),
549 tuple_buf.data);
550 else
551 appendStringInfo(&err_detail, _("Updating the row that was modified by a non-existent origin in transaction %u at %s."),
553 }
554
555 break;
556
560
561 if (tuple_buf.len)
562 appendStringInfo(&err_detail, _("Could not find the row to be updated: %s.\n"),
563 tuple_buf.data);
564 else
565 appendStringInfo(&err_detail, _("Could not find the row to be updated.\n"));
566
567 if (localts)
568 {
570 appendStringInfo(&err_detail, _("The row to be updated was deleted locally in transaction %u at %s"),
572 else if (replorigin_by_oid(localorigin, true, &origin_name))
573 appendStringInfo(&err_detail, _("The row to be updated was deleted by a different origin \"%s\" in transaction %u at %s"),
574 origin_name, localxmin, timestamptz_to_str(localts));
575
576 /* The origin that modified this row has been removed. */
577 else
578 appendStringInfo(&err_detail, _("The row to be updated was deleted by a non-existent origin in transaction %u at %s"),
580 }
581 else
582 appendStringInfoString(&err_detail, _("The row to be updated was deleted"));
583
584 break;
585
589
590 if (tuple_buf.len)
591 appendStringInfo(&err_detail, _("Could not find the row to be updated: %s."),
592 tuple_buf.data);
593 else
594 appendStringInfo(&err_detail, _("Could not find the row to be updated."));
595
596 break;
597
601 search_desc));
602
604 {
605 if (tuple_buf.len)
606 appendStringInfo(&err_detail, _("Deleting the row that was modified locally in transaction %u at %s: %s."),
608 tuple_buf.data);
609 else
610 appendStringInfo(&err_detail, _("Deleting the row that was modified locally in transaction %u at %s."),
612 }
613 else if (replorigin_by_oid(localorigin, true, &origin_name))
614 {
615 if (tuple_buf.len)
616 appendStringInfo(&err_detail, _("Deleting the row that was modified by a different origin \"%s\" in transaction %u at %s: %s."),
617 origin_name, localxmin,
619 tuple_buf.data);
620 else
621 appendStringInfo(&err_detail, _("Deleting the row that was modified by a different origin \"%s\" in transaction %u at %s."),
622 origin_name, localxmin,
624 }
625
626 /* The origin that modified this row has been removed. */
627 else
628 {
629 if (tuple_buf.len)
630 appendStringInfo(&err_detail, _("Deleting the row that was modified by a non-existent origin in transaction %u at %s: %s."),
632 tuple_buf.data);
633 else
634 appendStringInfo(&err_detail, _("Deleting the row that was modified by a non-existent origin in transaction %u at %s."),
636 }
637
638 break;
639
643
644 if (tuple_buf.len)
645 appendStringInfo(&err_detail, _("Could not find the row to be deleted: %s."),
646 tuple_buf.data);
647 else
648 appendStringInfo(&err_detail, _("Could not find the row to be deleted."));
649
650 break;
651 }
652
653 Assert(err_detail.len > 0);
654
655 /*
656 * Insert a blank line to visually separate the new detail line from the
657 * existing ones.
658 */
659 if (err_msg->len > 0)
660 appendStringInfoChar(err_msg, '\n');
661
663}
664
665/*
666 * Extract conflicting key, local row, remote row, and replica identity
667 * columns. Results are set at xxx_desc.
668 *
669 * If the output is NULL, it indicates that the current user lacks permissions
670 * to view the columns involved.
671 */
672static void
674 char **key_desc,
678 Oid indexoid)
679{
680 Relation localrel = relinfo->ri_RelationDesc;
681 Oid relid = RelationGetRelid(localrel);
682 TupleDesc tupdesc = RelationGetDescr(localrel);
683 char *desc = NULL;
684
687
688 /*
689 * Report the conflicting key values in the case of a unique constraint
690 * violation.
691 */
694 {
695 Assert(OidIsValid(indexoid) && localslot);
696
697 desc = build_index_value_desc(estate, localrel, localslot,
698 indexoid);
699
700 if (desc)
701 *key_desc = psprintf(_("key %s"), desc);
702 }
703
704 if (localslot)
705 {
706 /*
707 * The 'modifiedCols' only applies to the new tuple, hence we pass
708 * NULL for the local row.
709 */
710 desc = ExecBuildSlotValueDescription(relid, localslot, tupdesc,
711 NULL, 64);
712
713 if (desc)
714 *local_desc = psprintf(_("local row %s"), desc);
715 }
716
717 if (remoteslot)
718 {
720
721 /*
722 * Although logical replication doesn't maintain the bitmap for the
723 * columns being inserted, we still use it to create 'modifiedCols'
724 * for consistency with other calls to ExecBuildSlotValueDescription.
725 *
726 * Note that generated columns are formed locally on the subscriber.
727 */
729 ExecGetUpdatedCols(relinfo, estate));
731 tupdesc, modifiedCols,
732 64);
733
734 if (desc)
735 *remote_desc = psprintf(_("remote row %s"), desc);
736 }
737
738 if (searchslot)
739 {
740 /*
741 * Note that while index other than replica identity may be used (see
742 * IsIndexUsableForReplicaIdentityFull for details) to find the tuple
743 * when applying update or delete, such an index scan may not result
744 * in a unique tuple and we still compare the complete tuple in such
745 * cases, thus such indexes are not used here.
746 */
748
750
751 /*
752 * If the table has a valid replica identity index, build the index
753 * key value string. Otherwise, construct the full tuple value for
754 * REPLICA IDENTITY FULL cases.
755 */
757 desc = build_index_value_desc(estate, localrel, searchslot, replica_index);
758 else
759 desc = ExecBuildSlotValueDescription(relid, searchslot, tupdesc, NULL, 64);
760
761 if (desc)
762 {
764 *search_desc = psprintf(_("replica identity %s"), desc);
765 else
766 *search_desc = psprintf(_("replica identity full %s"), desc);
767 }
768 }
769}
770
771/*
772 * Helper functions to construct a string describing the contents of an index
773 * entry. See BuildIndexValueDescription for details.
774 *
775 * The caller must ensure that the index with the OID 'indexoid' is locked so
776 * that we can fetch and display the conflicting key value.
777 */
778static char *
780 Oid indexoid)
781{
782 char *index_value;
785 bool isnull[INDEX_MAX_KEYS];
786 TupleTableSlot *tableslot = slot;
787
788 if (!tableslot)
789 return NULL;
790
792
793 indexDesc = index_open(indexoid, NoLock);
794
795 /*
796 * If the slot is a virtual slot, copy it into a heap tuple slot as
797 * FormIndexDatum only works with heap tuple slots.
798 */
799 if (TTS_IS_VIRTUAL(slot))
800 {
801 tableslot = table_slot_create(localrel, &estate->es_tupleTable);
802 tableslot = ExecCopySlot(tableslot, slot);
803 }
804
805 /*
806 * Initialize ecxt_scantuple for potential use in FormIndexDatum when
807 * index expressions are present.
808 */
809 GetPerTupleExprContext(estate)->ecxt_scantuple = tableslot;
810
811 /*
812 * The values/nulls arrays passed to BuildIndexValueDescription should be
813 * the results of FormIndexDatum, which are the "raw" input to the index
814 * AM.
815 */
816 FormIndexDatum(BuildIndexInfo(indexDesc), tableslot, estate, values, isnull);
817
819
821
822 return index_value;
823}
Subscription * MySubscription
Definition worker.c:484
const char * timestamptz_to_str(TimestampTz t)
Definition timestamp.c:1870
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:252
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define Assert(condition)
Definition c.h:1002
#define lengthof(array)
Definition c.h:932
#define StaticAssertDecl(condition, errmessage)
Definition c.h:1067
uint32 TransactionId
Definition c.h:795
#define OidIsValid(objectId)
Definition c.h:917
bool track_commit_timestamp
Definition commit_ts.c:121
bool TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts, ReplOriginId *nodeid)
Definition commit_ts.c:283
const char *const ConflictLogDestNames[]
Definition conflict.c:34
static const ConflictLogColumnDef ConflictLogSchema[]
Definition conflict.c:67
#define NUM_CONFLICT_ATTRS
Definition conflict.c:82
static TupleDesc create_conflict_log_table_tupdesc(void)
Definition conflict.c:118
bool GetTupleTransactionInfo(TupleTableSlot *localslot, TransactionId *xmin, ReplOriginId *localorigin, TimestampTz *localts)
Definition conflict.c:236
void ReportApplyConflict(EState *estate, ResultRelInfo *relinfo, int elevel, ConflictType type, TupleTableSlot *searchslot, TupleTableSlot *remoteslot, List *conflicttuples)
Definition conflict.c:277
static const char *const ConflictTypeNames[]
Definition conflict.c:84
static char * build_index_value_desc(EState *estate, Relation localrel, TupleTableSlot *slot, Oid indexoid)
Definition conflict.c:779
static void append_tuple_value_detail(StringInfo buf, List *tuple_values)
Definition conflict.c:367
static void get_tuple_desc(EState *estate, ResultRelInfo *relinfo, ConflictType type, char **key_desc, TupleTableSlot *localslot, char **local_desc, TupleTableSlot *remoteslot, char **remote_desc, TupleTableSlot *searchslot, char **search_desc, Oid indexoid)
Definition conflict.c:673
static void errdetail_apply_conflict(EState *estate, ResultRelInfo *relinfo, ConflictType type, TupleTableSlot *searchslot, TupleTableSlot *localslot, TupleTableSlot *remoteslot, Oid indexoid, TransactionId localxmin, ReplOriginId localorigin, TimestampTz localts, StringInfo err_msg)
Definition conflict.c:403
void InitConflictIndexes(ResultRelInfo *relInfo)
Definition conflict.c:312
static int errcode_apply_conflict(ConflictType type)
Definition conflict.c:342
Oid create_conflict_log_table(Oid subid, char *subname, Oid subowner)
Definition conflict.c:147
ConflictLogDest GetConflictLogDest(const char *dest)
Definition conflict.c:210
ConflictType
Definition conflict.h:32
@ CT_UPDATE_DELETED
Definition conflict.h:43
@ CT_MULTIPLE_UNIQUE_CONFLICTS
Definition conflict.h:55
@ CT_DELETE_MISSING
Definition conflict.h:52
@ CT_UPDATE_ORIGIN_DIFFERS
Definition conflict.h:37
@ CT_INSERT_EXISTS
Definition conflict.h:34
@ CT_UPDATE_EXISTS
Definition conflict.h:40
@ CT_UPDATE_MISSING
Definition conflict.h:46
@ CT_DELETE_ORIGIN_DIFFERS
Definition conflict.h:49
ConflictLogDest
Definition conflict.h:90
@ CONFLICT_LOG_DEST_TABLE
Definition conflict.h:92
@ CONFLICT_LOG_DEST_ALL
Definition conflict.h:93
@ CONFLICT_LOG_DEST_LOG
Definition conflict.h:91
int64 TimestampTz
Definition timestamp.h:39
int errcode(int sqlerrcode)
Definition elog.c:875
#define _(x)
Definition elog.c:96
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
int errhint(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define NOTICE
Definition elog.h:36
#define ereport(elevel,...)
Definition elog.h:152
char * ExecBuildSlotValueDescription(Oid reloid, TupleTableSlot *slot, TupleDesc tupdesc, Bitmapset *modifiedCols, int maxfieldlen)
Definition execMain.c:2457
Bitmapset * ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate)
Definition execUtils.c:1387
Bitmapset * ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition execUtils.c:1408
#define GetPerTupleExprContext(estate)
Definition executor.h:665
char * BuildIndexValueDescription(Relation indexRelation, const Datum *values, const bool *isnull)
Definition genam.c:178
Oid heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid reltypeid, Oid reloftypeid, Oid ownerid, Oid accessmtd, TupleDesc tupdesc, List *cooked_constraints, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, OnCommitAction oncommit, Datum reloptions, bool use_user_acl, bool allow_system_table_mods, bool is_internal, Oid relrewrite, ObjectAddress *typaddress)
Definition heap.c:1140
IndexInfo * BuildIndexInfo(Relation index)
Definition index.c:2446
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition index.c:2760
void index_close(Relation relation, LOCKMODE lockmode)
Definition indexam.c:178
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition indexam.c:134
int i
Definition isn.c:77
List * lappend_oid(List *list, Oid datum)
Definition list.c:375
bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
Definition lmgr.c:351
#define NoLock
Definition lockdefs.h:34
#define RowExclusiveLock
Definition lockdefs.h:38
char * get_rel_name(Oid relid)
Definition lsyscache.c:2242
char * get_qualified_objname(Oid nspid, char *objname)
Definition lsyscache.c:3720
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3682
static char * errmsg
bool replorigin_by_oid(ReplOriginId roident, bool missing_ok, char **roname)
Definition origin.c:513
#define InvalidReplOriginId
Definition origin.h:33
NameData attname
NameData relname
Definition pg_class.h:40
#define INDEX_MAX_KEYS
#define NAMEDATALEN
#define NIL
Definition pg_list.h:68
#define list_make1(x1)
Definition pg_list.h:244
#define foreach_ptr(type, var, lst)
Definition pg_list.h:501
#define list_make3(x1, x2, x3)
Definition pg_list.h:248
#define list_make2(x1, x2)
Definition pg_list.h:246
NameData subname
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define ERRCODE_T_R_SERIALIZATION_FAILURE
Definition pgbench.c:77
void pgstat_report_subscription_conflict(Oid subid, ConflictType type)
int pg_strcasecmp(const char *s1, const char *s2)
#define snprintf
Definition port.h:261
uint64_t Datum
Definition postgres.h:70
static TransactionId DatumGetTransactionId(Datum X)
Definition postgres.h:282
#define InvalidOid
unsigned int Oid
static int fb(int x)
@ ONCOMMIT_NOOP
Definition primnodes.h:59
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
#define RelationGetRelid(relation)
Definition rel.h:516
#define RelationGetDescr(relation)
Definition rel.h:542
#define RelationGetRelationName(relation)
Definition rel.h:550
#define RelationGetNamespace(relation)
Definition rel.h:557
Oid GetRelationIdentityOrPK(Relation rel)
Definition relation.c:904
void resetStringInfo(StringInfo str)
Definition stringinfo.c:126
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
const char * attname
Definition conflict.c:47
List * es_tupleTable
Definition execnodes.h:749
Definition pg_list.h:54
Form_pg_index rd_index
Definition rel.h:192
#define MinTransactionIdAttributeNumber
Definition sysattr.h:22
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
Definition tableam.c:92
void NewRelationCreateToastTable(Oid relOid, Datum reloptions)
Definition toasting.c:72
void FreeTupleDesc(TupleDesc tupdesc)
Definition tupdesc.c:569
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescFinalize(TupleDesc tupdesc)
Definition tupdesc.c:511
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:909
#define TTS_IS_VIRTUAL(slot)
Definition tuptable.h:253
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:438
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition tuptable.h:544
const char * type
void CommandCounterIncrement(void)
Definition xact.c:1130
uint16 ReplOriginId
Definition xlogdefs.h:69