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 1iXm3k-0008IA-Ko for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2019 12:59:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXm3i-0001n6-A9 for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2019 12:59:42 +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 1iXm3h-0001mz-Ti for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2019 12:59:42 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXm3a-0001qP-Ck for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2019 12:59:41 +0000 Received: by mail-wr1-x441.google.com with SMTP id i12so4246008wrn.11 for ; Thu, 21 Nov 2019 04:59:33 -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=b2RrwBPe2eTpTPtWG+KZ9liIR7Kv9OKSTYfD0abMTi8=; b=R+b61pxiwMBS4lm1oYbnx+2tBlE/N+g039hA6O5krlSZVtF6BudlouMzHkgpD9TQt1 lTrTVVLDxZVIS4qHm22WEkW20Zn3n939C8bpRjWnfzvRo276RiGmWXnyJfNlwVnSIET1 Jtg/6W57081N7AGeqTnwt7JA0vO7+AOj7qEPv4K3t69xkIEeItoe79deXy1pqxvmaCgI LhHFEfnZq0nl1NjosIGYDnHWLtj6AFZi/8NzsX3KcMjWPTeH6zITxPcYh0xYOYfDy5OX Rp/4GMA5E/mGjF6n6YvjUEBPtumHSFC0ia/eoQv+MRMo9BGqzoMbApmNjpZJ9mgMWfJY hTaw== 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=b2RrwBPe2eTpTPtWG+KZ9liIR7Kv9OKSTYfD0abMTi8=; b=CyCCfPU+eH116OPgyFc8O6MNczl+TrgCwVH22yfE8oxXNrIJxEGTCTRFfBmQ+7SML9 sd51LGbTyHd7dXhbozKEy2NlSyFZjZat/9W5Kp5vpkgLMgJWvqxmQC9NfqG5/x+Rut7j cGzdLpDzKapNMzcJDECcEJxbOmRiM1gziJsnAfal7xBcog5xHZ8F7rDv2rfqI7zlHmKY oFEsdSPBJkRY2zOiwwz47slAyIvTT3yCx/mkF84ZkCmoxohbecpePxnEhPp+92lgLw4y AUMcHC5aStU29PsnydEitUTVk0a5bfTzRs82yo3PLCnypgcVrxc6t1rAbhIU+q8zVg7C W0ug== X-Gm-Message-State: APjAAAX84In32xgZsLZA57gGb5qImt5NS/Ezq+W9V63i6BUOKX9aeIVr Cul8kwqfV4wM11rkmxngrV6VmIRxc4o= X-Google-Smtp-Source: APXvYqzbrSGPywUHvILxEd/SqdJVWmI0mHSSbqMR9sBYy5LV8F/7dytdq91nDpGEw3JzO8IUAUj2uQ== X-Received: by 2002:adf:8543:: with SMTP id 61mr10964679wrh.171.1574341173265; Thu, 21 Nov 2019 04:59:33 -0800 (PST) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id e16sm3221144wrj.80.2019.11.21.04.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 04:59:32 -0800 (PST) Date: Thu, 21 Nov 2019 13:59:30 +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: <20191121125930.or5fhpi2yjgkmjye@development> References: <16129-a0c0f48e71741e5f@postgresql.org> <20191121103940.gpadc7xmssl63sad@development> <20191121115326.arierrbeok6we5sv@core.my.home> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191121115326.arierrbeok6we5sv@core.my.home> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Nov 21, 2019 at 12:53:26PM +0100, Ondřej Jirman wrote: >Hello, > >On Thu, Nov 21, 2019 at 11:39:40AM +0100, Tomas Vondra wrote: >> On Thu, Nov 21, 2019 at 01:14:18AM +0000, PG Bug reporting form wrote: >> > The following bug has been logged on the website: >> > >> > Bug reference: 16129 >> > Logged by: Ondrej Jirman >> > Email address: ienieghapheoghaiwida@xff.cz >> > PostgreSQL version: 12.1 >> > Operating system: Arch Linux >> > Description: >> > >> > Hello, >> > >> > I've upgraded my main PostgreSQL cluster from 11.5 to 12.1 via pg_dumpall >> > method and after a while I started getting segfault in logical replication >> > worker. >> > >> > My setup is fairly vanilla, non-default options: >> > >> > shared_buffers = 256MB >> > work_mem = 512MB >> > temp_buffers = 64MB >> > maintenance_work_mem = 4GB >> > effective_cache_size = 16GB >> > max_logical_replication_workers = 30 >> > max_replication_slots = 30 >> > max_worker_processes = 30 >> > wal_level = logical >> > >> > I have several databases that I subscribe to from this database cluster >> > using logical replication. >> > >> > Replication of one of my databases (running on ARMv7 machine) started >> > segfaulting on the subscriber side (x86_64) like this: >> > >> > #0 0x00007fc259739917 in __memmove_sse2_unaligned_erms () from >> > /usr/lib/libc.so.6 >> > #1 0x000055d033e93d44 in memcpy (__len=620701425, __src=, >> > __dest=0x55d0356da804) at /usr/include/bits/string_fortified.h:34 >> > #2 tts_virtual_materialize (slot=0x55d0356da3b8) at execTuples.c:235 >> > #3 0x000055d033e94d32 in ExecFetchSlotHeapTuple >> > (slot=slot@entry=0x55d0356da3b8, materialize=materialize@entry=true, >> > shouldFree=shouldFree@entry=0x7fff0e7cf387) at execTuples.c:1624 > >I forgot to add that publisher is still PostgreSQL 11.5. > >> Hmmm, so it's failing on this memcpy() in tts_virtual_materialize: >> >> else >> { >> Size data_length = 0; >> >> data = (char *) att_align_nominal(data, att->attalign); >> data_length = att_addlength_datum(data_length, att->attlen, val); >> >> memcpy(data, DatumGetPointer(val), data_length); > >This is a bytea column in one of the tables on the publisher. > >So this looks like it's segfaulting while trying to copy too much bytes >(data_length determined as 620,701,425 bytes): > >#1 0x000055d033e93d44 in memcpy (__len=620701425, __src=, __dest=0x55d0356da804) at /usr/include/bits/string_fortified.h:34 > >But maximum length of any bytea valaue in the publisher database is <200kB. > OK. So the public.videos.cover_image column, I suppose? Anyway, this likely means the pointer bogus, in some way. Maybe it's pointing to already freed memory, or something like that. >> >> slot->tts_values[natt] = PointerGetDatum(data); >> data += data_length; >> } >> >> The question is, which of the pointers is bogus. You seem to already >> have a core file, so can you inspect the variables in frame #2? I think >> especially >> >> p *slot >> p natt >> p val >> p *att >> >> would be interesting to see. > >(gdb) p *slot >$1 = {type = T_TupleTableSlot, tts_flags = 20, tts_nvalid = 8, tts_ops = 0x558149ff4da0 , tts_tupleDescriptor = 0x7fcca2ea7548, tts_values = 0x55814adfbc10, > tts_isnull = 0x55814adfbc50, tts_mcxt = 0x55814adfb6e0, tts_tid = {ip_blkid = {bi_hi = 65535, bi_lo = 65535}, ip_posid = 0}, tts_tableOid = 0} >(gdb) p natt >$2 = 2 >(gdb) p val >$3 = >(gdb) p slot->tts_values[nat] >No symbol "nat" in current context. >(gdb) p slot->tts_values[natt] >$4 = 94013795319824 >(gdb) p *slot->tts_values[natt] >$5 = -1812161596 >(gdb) p *att >$6 = {attrelid = 55240, attname = {data = "cover_image", '\000' }, atttypid = 17, attstattarget = -1, attlen = -1, attnum = 3, attndims = 0, attcacheoff = -1, atttypmod = -1, > attbyval = false, attstorage = 120 'x', attalign = 105 'i', attnotnull = true, atthasdef = false, atthasmissing = false, attidentity = 0 '\000', attgenerated = 0 '\000', attisdropped = false, > attislocal = true, attinhcount = 0, attcollation = 0} > OK, nothing obviously bobus here, I think. It's not entirely clear to me why this works (gdb) p *slot->tts_values[natt] $5 = -1812161596 because tts_values[natt] is not a pointer, I think. So I'm not sure how to interpret the dereference. It would be interesting to see the first couple of bytes? I think somehing like (gdb) p ((char*)slot->tts_values[natt])[$n] for $n between 0 and 3 should do the trick. >> Also, how does the replicated schema look like? Can we see the table >> definitions? > > ... >CREATE TABLE public.videos ( > id integer NOT NULL, > title text NOT NULL, > cover_image bytea NOT NULL, > metadata jsonb NOT NULL, > category integer NOT NULL, > published date NOT NULL, > added timestamp without time zone DEFAULT now() NOT NULL, > played boolean DEFAULT false NOT NULL >); OK, so this is the problematic table. Any idea what operation triggers the issue? Having a small reproducer (say, a single-row insert or so) would be very helpful. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services