Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXudP-0001ol-KD for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2019 22:09:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXudO-0006IB-FJ for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2019 22:09:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXudO-0006I4-73 for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2019 22:09:06 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXudK-0006l9-P2 for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2019 22:09:05 +0000 Received: by mail-wr1-x442.google.com with SMTP id z7so2893200wrl.13 for ; Thu, 21 Nov 2019 14:09:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=dWXnerRAilgkHNaGXJqQ2act0WbihUWz1veoRV2w7t4=; b=kQL4aML2M/3a5L040mptaUNfUG82y/7L6ePbmUx9t/R2/vG4hALlLn0yPDJxFbxnQi AKEXgaln+keogLaL0qlyuCmk8LrPlPXCcbVxwu6rAMZ7CIPEBUctbP+SJsFhbudJHGdd K4PfhbnLuRfEfX3C1tA9T8/kog3h7ZDcHyJ4XFeM5kG66rdcrBgNMFk/OETD0QOX3nef kx2uBpVY39fPp6eaR8W6GtY7rkQRW5Hke8EfjIZQ06yMGODlfGjO4voG1+UJrWvfH+lA ZGpFVg+cgQcIowRkdc2r9m7Q3B0YEbkH3lT1jcYUQjJ9IMmCjVsTkwH24tCekx6PYfcQ 9VKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=dWXnerRAilgkHNaGXJqQ2act0WbihUWz1veoRV2w7t4=; b=dg/5YdryHPIwsIgRpHC9uvNBNgIIwFvSbrUyYS5Rrdm/B5wEmr0YewLk3cNjjzcNrB 5Q8uQGZpgFwVUVRBwGIBLso8StNAX+VRDu5ipIOgiAGiHt8UvmxCN5No3LBO3b3qCUHJ REHjdDINYhBlTab+V3t+qqe+ZzoQAfpERZfwy7UyijiP+X0iQJj6Js+NQ1NuETtYWRzj ElR8Xfl+2J6LbsVyjOzpoZBI5M5T1RVCUwjF+6QoEdCllMd3vQH7yt8jStLO+hBD/J/A Db25rIrzn4F88lqcnLHMjL021UR5XUiXg1yXUFL6RaBdghp4iR5KHHr+z7ySOeWdAezi z8Ng== X-Gm-Message-State: APjAAAUg3qFaOEWbeCAV6Nhd7V5nA00YyF8AGlmo/Ftka7s+Ea/CBX3K B+PaxliY/WbVBipr3MQJhlKLiJ/XAik= X-Google-Smtp-Source: APXvYqwlpXBIknMb0iZsj9IlcZHhcZaiWi1Lg/pkjhQx+Pqor64f7+QgrOFS5UJBH7it5zgVCGfd/g== X-Received: by 2002:a5d:518c:: with SMTP id k12mr13933874wrv.104.1574374141587; Thu, 21 Nov 2019 14:09:01 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id y21sm391636wmi.6.2019.11.21.14.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 14:08:57 -0800 (PST) Date: Thu, 21 Nov 2019 23:08:54 +0100 From: Tomas Vondra To: =?utf-8?Q?Ond=C5=99ej?= Jirman Cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16129: Segfault in tts_virtual_materialize in logical replication worker Message-ID: <20191121220854.ebdzjtloel56sfwu@development> References: <20191121135523.aybyo7o6yzxxungd@core.my.home> <20191121143503.nkdwgjwb7xjopeuq@development> <20191121150716.szxqukxrtpjpckm3@core.my.home> <20191121152732.hu6y4wzw7nkxpsvk@development> <20191121155707.pqkgjphh65o5fapz@core.my.home> <20191121161502.xfiy65i3cm6adscr@core.my.home> <20191121165752.dffge6bh756xlfdg@development> <20191121173555.midj6vp4dmiiqs24@core.my.home> <20191121185844.6qsqhwzzuhu3fpsg@core.my.home> <20191121214115.3tgefmvkmrzaim74@development> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191121214115.3tgefmvkmrzaim74@development> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Nov 21, 2019 at 10:41:15PM +0100, Tomas Vondra wrote: >On Thu, Nov 21, 2019 at 07:58:44PM +0100, Ondřej Jirman wrote: >>On Thu, Nov 21, 2019 at 06:35:55PM +0100, Ondřej Jirman wrote: >>>One missing piece is what exactly is the contents of the outstanding output from >>>pgoutput plugin, that the replica crashes on and doesn't apply. Are there any >>>tools for inspecting the binary output from the pgoutput plugin? Maybe that can >>>provide a clue. >> >>So I've looked at it manually, and the segfaulting transaction doesn't make >>much sense to me. On primary a row with 37880 byte cover_image was inserted, >>but pgoutput plugin sends these records: >> >>B >>R - public.videos title cover_image metadata,... >>U - new row where cover_image tuple doesn't have any data, just a flag ('u') >>C >> >>Which means 'unchanged toast column' according to logical/proto.c >> >>Yet cover_image is defined as not null. >> >>I guess it's some special handling for VARATT_IS_EXTERNAL_ONDISK. > >Actually, no. The second message is 'U' so update, not insert. And we >don't send TOAST values (oversized values, stored aside) that were not >updated. Which is this case, because the cover_image was not updated (as >implied by the 'u' flag). > >For the record, the decoded data looks like this: > >1) relation structure (8 columns) > >R, 19048, public, videos, d, 8, > (true, id, 23 => int4, 0xffffffff) > (false, title, 25 => text, 0xffffffff) > (false, cover_image, 17 => bytea, 0xffffffff) > (false, metadata, 3802 => jsonb, 0xffffffff) > (false, category, 23 => int4, 0xffffffff) > (false, published, 1082 => date, 0xffffffff) > (false, added, 1114 => timestamp, 0xffffffff) > (false, played, 16 => uuid, 0xffffffff) > >2) update, with the TOAST value undefined/unchanged > >U, 19048, N, 8, > (4, 8393), > (86, Pazderka: O média se povede boj. Kdyby nás politici milovali, bylo by něco špatně), > u, /* unchanged bytea */ > (313, {.. json ..}), > (3, 242), > (10, 2019-11-18), > (26, 2019-11-18 12:50:01.816376), > (1, t) > >So it's perfectly well formatted, I think. > >> >>To me this looks like this transaction is assuming data for bytea column >>cover_image are already replicated from earlier? >> >>Maybe it is not though? It's certainly breaking some assumption on the >>replica, because this is the precise point where segfault happens. >> > >I think this more and more seems like some sort of bug in the apply >code, not resetting a NULL flag and interpreting the bogus value as >a valid pointer. Wouldn't the be the first such bug. > FWIW my hunch is the bug is somewhere in this chunk of code from apply_heap_update: if (found) { /* Process and store remote tuple in the slot */ oldctx = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); ExecCopySlot(remoteslot, localslot); slot_modify_cstrings(remoteslot, rel, newtup.values, newtup.changed); MemoryContextSwitchTo(oldctx); EvalPlanQualSetSlot(&epqstate, remoteslot); /* Do the actual update. */ ExecSimpleRelationUpdate(estate, &epqstate, localslot, remoteslot); } Can you please switch to this fram in the backtrace and: 1) Print newtup.values and newtup.changed matches, so that we can check it contains the tuple I shared before? There should be 8 elements in each, with 'values' being values formatted as text, and 'changed' being flags which values were updated. 2) Print remoteslot->tts_tupleDescriptor. 3) Print rel->attrmap (should have 8 elements) 4) Print remoteslot->tts_values and remoteslot->tts_isnull (8 elements). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services