Re: [PATCH] session_replication_role = replica with TRUNCATE - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: [PATCH] session_replication_role = replica with TRUNCATE
Date
Msg-id f7f87cb1-1a98-ffbf-4296-8b13bbcfd185@2ndquadrant.com
Whole thread Raw
In response to [PATCH] session_replication_role = replica with TRUNCATE  (Marco Nenciarini <marco.nenciarini@2ndquadrant.it>)
Responses Re: [PATCH] session_replication_role = replica with TRUNCATE
Re: [PATCH] session_replication_role = replica with TRUNCATE
List pgsql-hackers
On 12/29/17 07:01, Marco Nenciarini wrote:
> The current behavior of session_replication_role = replica with TRUNCATE
> is not the same of with the other commands.
> It does not check FKs for INSERT/UPDATE/DELETE but it does for TRUNCATE,
> so one cannot execute TRUNCATE on a table when it is possible to DELETE
> from table without WHERE clause.
> 
> I'm attaching a simple patch to make TRUNCATE match behavior of DELETE
> for session_replication_role = replica.

I'm wondering whether this shouldn't be fixed the other way around,
namely have foreign keys always enforced on replicas.

I'm not aware of an explanation why it currently works the way it does,
other than that FKs happen to be implemented by triggers and triggers
happen to work that way.  But I think it's pretty bogus that logical
replication subscriptions can insert data that violates constraints.
It's also weird that you can violate deferred unique constraints but not
immediate ones (I think, not tested).

So I'm proposing the attached alternative patch, which creates
constraint triggers to be TRIGGER_FIRES_ALWAYS by default.

Thoughts?

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment

pgsql-hackers by date:

Previous
From: Atri Sharma
Date:
Subject: Re: GSoC 2018 Project Ideas & Mentors - Last Call
Next
From: Stephen Frost
Date:
Subject: Re: GSoC 2018 Project Ideas & Mentors - Last Call