On Fri, Nov 27, 2026 at 9:48 AM vignesh C <[email protected]> wrote:
>
> Hi,
>
> During the review of the conflict log table patch, it was suggested
> that subscription OID preservation be split into a separate patch at
> [1], as it is also needed for the commit timestamp upgrade work.
> Accordingly, the first patch handles subscription OID preservation,
> while the second patch handles preserving conflict log tables and
> conflict_log_destination across upgrades.
>
> 0001: Preserve subscription OIDs across pg_upgrade
> In binary-upgrade mode, pg_dump emits
> binary_upgrade_set_next_pg_subscription_oid() before each CREATE
> SUBSCRIPTION, and CreateSubscription() uses this OID instead of
> assigning a new one. This requires adding a new pg_upgrade_support
> function and therefore a catversion bump. The change is independent of
> conflict log tables and is also needed for the upcoming commit
> timestamp upgrade at [2].
>
> 0002: Preserve conflict log tables and conflict_log_destination during upgrade
> The name of a conflict log table is derived from the subscription OID,
> and the table is referenced through
> pg_subscription.subconflictlogrelid. In binary-upgrade mode, pg_dump
> now dumps conflict log tables with their original OIDs, along with
> their privileges, comments, and security labels. CreateSubscription()
> links the subscription to the already restored conflict log table and
> reports an error if the table is missing. A conflict log table is
> dumped only when its subscription is also selected for dumping.  In
> normal mode, conflict log tables and their associated metadata are not
> dumped, since the tables are created again when the subscription is
> restored. The ACLs of the pg_conflict schema are dumped in the same
> way as those of pg_catalog.
>
> This version only splits the v98 patch posted at [3] into two patches;
> there are no other changes.
>
> [1] - 
> https://www.postgresql.org/message-id/CAA4eK1%2Bz29LbhwRqJy9KXV%2B1s2a7hkqq5MGX1WYvcQ%3DwkkpK%3DQ%40mail.gmail.com
> [2] - 
> https://www.postgresql.org/message-id/CAFPTHDa5aP8ixTZBygGAe48E1N=dvupzcxikw7bnkixlmn3...@mail.gmail.com
> [3] - 
> https://www.postgresql.org/message-id/CALDaNm08sHU%3DBowHwEdurWt0-XwsAYB0drL_1%3DS-_XJC4atnqQ%40mail.gmail.com
>


Thanks. A few comments:


1)
+  <para>
+   If a subscription has been created with the
+   <link 
linkend="sql-createsubscription-params-with-conflict-log-destination"><literal>conflict_log_destination</literal></link>
+   option set to <literal>table</literal> or <literal>all</literal>,
+   <application>pg_dump</application> does not dump that conflict log table
+   or its contents, unless the table is named explicitly with
+   <option>-t</option> or <option>-n</option>.  Restoring the subscription
+   creates a new, empty conflict log table, whose name is derived from the OID
+   of the new subscription.
+   Privileges, comments and security labels that had been set on the old
+   conflict log table are not restored, and must be set again on the new
+   table if needed.  In binary-upgrade mode, which
+   <application>pg_upgrade</application> uses, the subscription OID and its
+   conflict log table are preserved instead, with its contents, privileges,
+   comments and security labels.
+  </para>

A few small problems:
a) 'that conflict log table' is not clear
b)  'table is named explicitly with -t or -n': table can not be named i wth -n
c) 'with its contents, privileges,comments and security labels.': In
binary-upgrade mode, contents are not preserved as such, these are
carried by pg_upgrade,
so little change needed in last sentence.

Suggestion, take if you agree.

  <para>
   If a subscription has been created with the
   <link 
linkend="sql-createsubscription-params-with-conflict-log-destination"><literal>conflict_log_destination</literal></link>
   option set to <literal>table</literal> or <literal>all</literal>,
   <application>pg_dump</application> does not dump its conflict log table
   or its contents, unless the table is named explicitly with
   <option>-t</option>, or its schema <literal>pg_conflict</literal> is named
   with <option>-n</option>.  Restoring the subscription creates a new, empty
   conflict log table, whose name is derived from the OID of the new
   subscription.
   Privileges, comments and security labels that had been set on the old
   conflict log table are not restored, and must be set again on the new
   table if needed.  In binary-upgrade mode, which
   <application>pg_upgrade</application> uses, the subscription OID and its
   conflict log table are preserved instead, with the table's privileges,
   comments and security labels, and <application>pg_upgrade</application>
   carries over the table's contents.
  </para>

2)
+ reltup = SearchSysCache1(RELOID, ObjectIdGetDatum(logrelid));
+ if (!HeapTupleIsValid(reltup))
+ elog(ERROR, "cache lookup failed for relation %u", logrelid);
+ relowner = ((Form_pg_class) GETSTRUCT(reltup))->relowner;
+ ReleaseSysCache(reltup);
+
+ if (relowner != owner)
+ ATExecChangeOwner(logrelid, owner, true, AccessExclusiveLock);
+ }

ATExecChangeOwner() does these tests already internally.

3)
getSubscriptions:
a)
+ if (fout->remoteVersion >= 200000)
+ appendPQExpBufferStr(query,
+ " s.subconflictlogdest\n");
+ else
+ appendPQExpBufferStr(query,
+ " NULL AS subconflictlogdest\n");

b)
+ if (PQgetisnull(res, i, i_subconflictlogdest))
+ subinfo[i].subconflictlogdest = NULL;
+ else
+ subinfo[i].subconflictlogdest =
+ pg_strdup(PQgetvalue(res, i, i_subconflictlogdest));
+

c)
@@ -5620,6 +5716,11 @@ dumpSubscription(Archive *fout, const
SubscriptionInfo *subinfo)
  if (pg_strcasecmp(subinfo->suborigin, LOGICALREP_ORIGIN_ANY) != 0)
  appendPQExpBuffer(query, ", origin = %s", subinfo->suborigin);

+ if (subinfo->subconflictlogdest &&
+ pg_strcasecmp(subinfo->subconflictlogdest, "log") != 0)
+ appendPQExpBuffer(query, ", conflict_log_destination = %s",
+  subinfo->subconflictlogdest);
+

Shall we replace these with:
----------------------
a)
(The idea is to put 'log' (default) instead of NULL on older versions):

if (fout->remoteVersion >= 200000)
appendPQExpBufferStr(query,
" s.subconflictlogdest\n");
else
appendPQExpBufferStr(query,
" 'log' AS subconflictlogdest\n");

b)
subinfo[i].subconflictlogdest =
pg_strdup(PQgetvalue(res, i, i_subconflictlogdest));

c)

if (pg_strcasecmp(subinfo->subconflictlogdest, "log") != 0)
appendPQExpBuffer(query, ", conflict_log_destination = %s",
 subinfo->subconflictlogdest);
-----------

This is similar to how we deal with 'suborigin', by selecting its
default value on older versions instead of NULL. We need not to deal
with NULL by placing null-checks everywhere.


4)

+ * other modes, CREATE SUBSCRIPTION creates them again, so nothing
+ * about them is dumped, not even their ACLs, as that would refer to a
+ * table that no longer exists.


Shall we rephrase it to:
* other modes, CREATE SUBSCRIPTION creates them again, so nothing
* about them is dumped, not even their ACLs, as the restored
* subscription's table has a different name".

thanks
Shveta


Reply via email to