0001-Add-new-columns-to-CLT-and-add-upgrade-changes.patch

application/octet-stream

Filename: 0001-Add-new-columns-to-CLT-and-add-upgrade-changes.patch
Type: application/octet-stream
Part: 0
Message: Re: Proposal: Conflict log history table for Logical Replication
From bedd4868cf811893a2222378124b7146e23ad8f1 Mon Sep 17 00:00:00 2001
From: Vignesh C <vignesh21@gmail.com>
Date: Tue, 26 May 2026 14:41:03 +0530
Subject: [PATCH] Add new columns to CLT and add upgrade changes

Add new columns v20_new_col1 and v20_new_col2 of type TEXT
to conflict log tables.
Also update pg_dump binary upgrade logic to add these columns
during pg_upgrade.
---
 src/backend/replication/logical/conflict.c |  8 ++++++--
 src/bin/pg_dump/pg_dump.c                  | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/backend/replication/logical/conflict.c b/src/backend/replication/logical/conflict.c
index adf49bda7a7..84d91fef948 100644
--- a/src/backend/replication/logical/conflict.c
+++ b/src/backend/replication/logical/conflict.c
@@ -72,7 +72,9 @@ static const ConflictLogColumnDef ConflictLogSchema[] = {
 	{ .attname = "remote_origin",    .atttypid = TEXTOID },
 	{ .attname = "remote_tuple",     .atttypid = JSONOID },
 	{ .attname = "replica_identity", .atttypid = JSONOID },
-	{ .attname = "local_conflicts",  .atttypid = JSONARRAYOID }
+	{ .attname = "local_conflicts",  .atttypid = JSONARRAYOID },
+	{ .attname = "v20_new_col1",     .atttypid = TEXTOID },
+	{ .attname = "v20_new_col2",     .atttypid = TEXTOID },
 };
 
 #define NUM_CONFLICT_ATTRS lengthof(ConflictLogSchema)
@@ -1347,10 +1349,12 @@ prepare_conflict_log_tuple(EState *estate, Relation rel,
 	else
 		nulls[attno++] = true;
 
-	values[attno] = build_local_conflicts_json_array(estate, rel,
+	values[attno++] = build_local_conflicts_json_array(estate, rel,
 													 conflict_type,
 													 conflicttuples);
 
+	values[attno++] = CStringGetTextDatum("v20_new_col1");
+	values[attno] = CStringGetTextDatum("v20_new_col2");
 	Assert(attno + 1 == NUM_CONFLICT_ATTRS);
 
 	oldctx = MemoryContextSwitchTo(ApplyContext);
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index f260035879d..1844a9d20a7 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -5765,6 +5765,21 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo)
 						  qsubname,
 						  subinfo->subconflictlogdest);
 
+	if (dopt->binary_upgrade && fout->remoteVersion >= 190000 &&
+		(pg_strcasecmp(subinfo->subconflictlogdest, "log") != 0))
+	{
+		appendPQExpBufferStr(query,
+						  	 "\n\nSET allow_system_table_mods = on;\n");
+		appendPQExpBuffer(query,
+						  "\n\nALTER TABLE pg_conflict.pg_conflict_log_for_subid_%d ADD COLUMN v20_new_col1 TEXT;\n",
+						  subinfo->dobj.catId.oid);
+		appendPQExpBuffer(query,
+						  "\n\nALTER TABLE pg_conflict.pg_conflict_log_for_subid_%d ADD COLUMN v20_new_col2 TEXT;\n",
+						  subinfo->dobj.catId.oid);						  
+		appendPQExpBufferStr(query,
+						  	 "\n\nSET allow_system_table_mods = off;\n");
+	}
+
 	/*
 	 * In binary-upgrade mode, we allow the replication to continue after the
 	 * upgrade.
-- 
2.53.0