Allowing TRUNCATE of FK target when session_replication_role=replica

From: Hannu Krosing <hannuk(at)google(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Allowing TRUNCATE of FK target when session_replication_role=replica
Date: 2023-10-31 08:09:24
Message-ID: CAMT0RQQfF3k_Ri7-zvQ2X=mt=d0Qx5qGJojk=1P8oaL6yU=+1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

Currently we do not allow TRUNCATE of a table when any Foreign Keys
point to that table.

At the same time we do allow one to delete all rows when
session_replication_role=replica

This causes all kinds of pain when trying to copy in large amounts of
data, especially at the start of logical replication set-up, as many
optimisations to COPY require the table to be TRUNCATEd .

The main two are ability to FREEZE while copying and the skipping of
WAL generation in case of wal_level=minimal, both of which can achieve
significant benefits when data amounts are large.

Is there any reason to not allow TRUNCATE when
session_replication_role=replica ?

Unless there are any serious objections, I will send a patch to also
allow TRUNCATE in this case.

Best Regards
Hannu

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro Horiguchi 2023-10-31 08:49:32 Re: A recent message added to pg_upgade
Previous Message torikoshia 2023-10-31 07:26:18 Re: Add new option 'all' to pg_stat_reset_shared()