Re: Proposal: Conflict log history table for Logical Replication

From: shveta malik <shveta(dot)malik(at)gmail(dot)com>
To: vignesh C <vignesh21(at)gmail(dot)com>
Cc: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Zhijie Hou <houzhijie22(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, shihao zhong <zhong950419(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, saurabh singh <saurabh(dot)singh214(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, shveta malik <shvetamalik(at)gmail(dot)com>
Subject: Re: Proposal: Conflict log history table for Logical Replication
Date: 2026-11-26 04:26:49
Message-ID: CAJpy0uDJq6RACkPfzW6UnZO2U1up+zxQSkcB1PwarVvuWGraXw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 26, 2026 at 8:27 AM vignesh C <vignesh21(at)gmail(dot)com> wrote:
>
> On Wed, 25 Nov 2026 at 17:23, Nisha Moond <nisha(dot)moond412(at)gmail(dot)com> wrote:
> >
> > Attached v2 patch fixing above as well as other comments from Hou-san at [2].
>
> DROP SUBSCRIPTION ... CASCADE drops the objects that depend on the
> subscription's conflict log table (CLT), such as views but sql_drop
> event triggers don't see those objects.
> CREATE TABLE dropped_log (object_type text, object_identity text);
> CREATE FUNCTION log_drops() RETURNS event_trigger LANGUAGE plpgsql AS $$
> BEGIN
> INSERT INTO dropped_log
> SELECT object_type, object_identity FROM pg_event_trigger_dropped_objects();
> END $$;
> CREATE EVENT TRIGGER log_drops ON sql_drop EXECUTE FUNCTION log_drops();
>
> CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=postgres' PUBLICATION pub1
> WITH (connect = false, slot_name = NONE, conflict_log_destination = 'table');
> -- <oid> is the subscription's OID
> CREATE VIEW v AS SELECT relid FROM pg_conflict.pg_conflict_log_<oid>;
>
> DROP SUBSCRIPTION sub1 CASCADE;
> SELECT * FROM dropped_log;
> --------------+-----------------
> subscription | sub1
> (1 row)
>
> The view v was dropped, but it is not in the list.
>
> drop_sub_conflict_log_table() drops the table with
> PERFORM_DELETION_INTERNAL. deleteObjectsInList() skips event-trigger
> tracking for every object of a deletion when that flag is set
> (dependency.c:196, and the comment at line 255). Only the subscription
> is reported, because DropSubscription() adds it by itself.
>
> I felt for CASCADE, drop the conflict table without
> PERFORM_DELETION_INTERNAL flag like the changes in the attached patch.
> Thoughts?

I agree with the problem sattement. But using your test, I noticed that:

-- Drop SUBSCRIPTION RESTRICT (no dependencies) reports only the
subscription to sql_drop event triggers.

-- Drop SUBSCRIPTION CASCADE (no dependencies) reports both the
subscription and the conflict log table.

Is this difference intentional? Shouldn't RESTRICT also report both?
Or should it be the other way around: the CLT's drop should not be
visible to event triggers, the same way its creation isn't?
Create/Alter Sub that create the CLT report only the subscription to
event triggers, never the CLT, so reporting its drop (only in the
CASCADE path) seems a bit inconsistent. Thoughts?

You can see that the CLT's creation is not reported, using a
ddl_command_end triggers:

CREATE TABLE created_log (command_tag text, object_type text,
object_identity text);

CREATE FUNCTION log_creates() RETURNS event_trigger LANGUAGE plpgsql AS $$
BEGIN
INSERT INTO created_log
SELECT command_tag, object_type, object_identity
FROM pg_event_trigger_ddl_commands();
END $$;

CREATE EVENT TRIGGER log_creates ON ddl_command_end EXECUTE FUNCTION
log_creates();

thanks
Shveta

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-11-26 04:27:15 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Min, Baohong 2026-11-26 04:24:39 Re: [PATCH v2] Reduce LWLockWaitListLock() cache-line contention with adaptive spin reads