On Mon, May 31, 2021 at 12:20 PM Dilip Kumar <dilipbal...@gmail.com> wrote: > > On Mon, May 31, 2021 at 8:04 AM tanghy.f...@fujitsu.com > <tanghy.f...@fujitsu.com> wrote: > > > > On Friday, May 28, 2021 6:51 PM, Dilip Kumar <dilipbal...@gmail.com> wrote: > > > Seems you did not set the replica identity for updating the tuple. > > > Try this before updating, and it should work. > > > > Thanks for your reply. I tried it. > > > > > ALTER TABLE toasted_key REPLICA IDENTITY USING INDEX toasted_key_pkey; > > > > This didn't work. > > > > > or > > > > > > ALTER TABLE toasted_key REPLICA IDENTITY FULL. > > > > It worked. > > > > And I noticed if the length of PRIMARY KEY (toasted_key) is short, data > > could be synchronized successfully with default replica identity. > > Could you tell me why we need to set replica identity? > > Looks like some problem if the replica identity is an index and the > value is stored externally, I will debug this and let you know.
The problem is if the key attribute is not changed we don't log it as it should get logged along with the updated tuple, but if it is externally stored then the complete key will never be logged because there is no log from the toast table. For fixing this if the key is externally stored then always log that. Please test with the attached patch. -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com
From 965c18471919e231ec94edac9025f7178f121206 Mon Sep 17 00:00:00 2001 From: Dilip Kumar <dilipkumar@localhost.localdomain> Date: Mon, 31 May 2021 14:37:26 +0530 Subject: [PATCH v1] Extract unchanged replica identity key if it is stored externally If replica identity is set to key and the key is not modified we don't log key seperately because it should be logged along with the updated tuple. But if the key is stored externally we must have to detoast and log it separately. --- src/backend/access/heap/heapam.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index bd60129..27d60e6 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8407,8 +8407,11 @@ ExtractReplicaIdentity(Relation relation, HeapTuple tp, bool key_changed, return tp; } - /* if the key hasn't changed and we're only logging the key, we're done */ - if (!key_changed) + /* + * if the key hasn't changedand we're only logging the key, we're done. + * But if tuple has external data then we might have to detoast the key. + */ + if ((!key_changed) && !HeapTupleHasExternal(tp)) return NULL; /* find out the replica identity columns */ -- 1.8.3.1