Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gH94w-00006b-KG for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Oct 2018 15:03:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gH94t-0005JY-KU for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Oct 2018 15:03:39 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1gH94t-0005JR-AH for pgsql-bugs@lists.postgresql.org; Mon, 29 Oct 2018 15:03:39 +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 1gH94q-0000Lb-0d for pgsql-bugs@lists.postgresql.org; Mon, 29 Oct 2018 15:03:38 +0000 Received: by mail-wr1-x442.google.com with SMTP id d17-v6so8766298wre.11 for ; Mon, 29 Oct 2018 08:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=gtf81cLcRVpepfZO9onBP6Rq6goxnBkU8fBt5YKkgNs=; b=pBMEiAPMjODKYOxYo4iS0UKTG+3AVrNu6NoCH+adrUk6+GuM6HMysuPxfSDsXScDh4 WjZ6gK0hKGKYo7c8rQcwVZF23P0hIq9mYgdJkWiZlDIpt1eiT5G4t+tw57NgDUhipjbg 4kxAdph4SplGPD8offtio34BcUGkemnqXYzBmU/TyOUQ9SRIgcFaL99AoePj7wVhZtLU 3CZ4ddx5C+vbyW0mfO/RtyvCcZdlPq7XWBjae1uYosSvObRccAqGB3C5JKppWCSI+tha YeRicUj1/Xn3260i3prFaFHRoMtZDjvm8d28TH/gaeVqfyEfFxTQRQEMAZPF+mCSlz0K ebnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=gtf81cLcRVpepfZO9onBP6Rq6goxnBkU8fBt5YKkgNs=; b=jmydvBt/oooyQZHfdA72uT/Rs5Fe1kqaSym2ZyFDjUx1HZNfCJQ5IUu08YkUCmGch9 GZ/kGuI/sKwZldcqk25HKhstyJKgHSVN3xUQrGOEECZtKHkO4c+fhUmIZC4YorPM91jq K/Nu96UehVOch3Lph6T2TCTBfjpweveBHuB1Bvqow/pfZcjUwHtozUWHrtQFB9iMNKDu 2MeBlZZ8Rwqye+SeFXRbCcG1Anqka6e4yV/JjmMTzZc+xcoiXR2LTKssD4czYW7EcB3P B7UK5gyTXIAt0FEh0sIQyW6dAfUJrVcb1lCIJ+ZBAptZo3KyHs8uUl16PzNEGEd9LNxh IUlg== X-Gm-Message-State: AGRZ1gLqIkXl9LdHIfwp+pADI3VgMFS5FP4Tpk5OccH9hzWJ9vWsLzzZ Qut5Y5JpGichz0Ozlk+tYOrejw== X-Google-Smtp-Source: AJdET5eaYFEs4T7dn+07cUMSbA2kwkogKgyduSAy6QCL+2N4yyUWXmdw7kuiE2i+Ng/ufm+oMcL5ew== X-Received: by 2002:adf:ff05:: with SMTP id k5-v6mr7934173wrr.73.1540825412689; Mon, 29 Oct 2018 08:03:32 -0700 (PDT) Received: from [192.168.0.99] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id r131-v6sm14816743wmb.32.2018.10.29.08.03.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Oct 2018 08:03:31 -0700 (PDT) Subject: Re: BUG #15114: logical decoding Segmentation fault To: Michael Paquier Cc: =?UTF-8?B?0J/QtdGC0YrRgCDQodC70LDQstC+0LI=?= , Alvaro Herrera , Andres Freund , Petr Jelinek , pgsql-bugs@lists.postgresql.org, Peter Eisentraut References: <20180326160801.ja4j43hwrc35iuhb@alvherre.pgsql> <20180416175901.mdevawuuhvwo3yk6@alvherre.pgsql> <20180427012203.GG3419@paquier.xyz> <11af0d1b-e48f-fba3-5b1e-49886f648f52@2ndquadrant.com> <20181029015438.GC14242@paquier.xyz> From: Petr Jelinek Openpgp: preference=signencrypt Autocrypt: addr=petr.jelinek@2ndquadrant.com; prefer-encrypt=mutual; keydata= xsFNBFawwSABEAC45Vua8rSggpM2kkMMmoOHz51a+fi3OXFfnrStVh80pM2/J9nSzjrIKQKf H5PtRnoYzSKnoUDoLOkLwDYitK3HzUUWXma+AWAqef2Y0GSZ7A3jJkD+JHOfkpS1CIpkEB/e WjA8Wqegwzc/OEE5111/l0Q1e6jxgZI86h8MMnm35Of1Y6Lz4kqWCyxHhaTJKTCkq66ICQ2C VJkbvuUoEE+Hr/I38dPHTAqIlCnycVnJPLHBQ/UYGHR/USF8qI/qJJx6tJcNAEqz69QZ/VlY 31UyJHdYe5NtBVz+rYZCOVWfpe3crbHuq9FjAPT+xcZefdxridmMKuW8eBmmXI9iZ3EG+X8J IsdLWL8QoqW0lnO1otYz1QDjdOvbEpq+u5/TAU8pgtaYH2J+6/GaQ6hMLyLBkaIAtnqlLCzq pxXcxMsFT14P5/rZA7EbBI8RS1ZIWJBlS2oO+dtVuENLJUC0SpptaRyn/uyOIopt7hSmBekL SzFnet7P9qofFJY+fQEz84v0G1gvwonHGHiCGgLpbMdPtnfPzda1aiTURvvOD7w/RmX1/ogk TqSGO4ejVNO/28QYouxmxzy8jbbIEiLCbHpLR/M/TvYHHPURxcx+MxVl3G+d/4Ihy4abxOdW pe9zLIcVMvqiUFQO28/79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xLW9r+ZfSEeT0APdz7TQC9MzNzUhyXvA5a RQQCRMXKbGaYhKkYEYiYOGqtTxN+PmyvNUBmFEcagBX2TXqEkgnI6zOnN13mB4SihJ2lne2r 9RNiPYs/hmRxYg== Message-ID: <4cc78025-2bdd-082d-fe38-a35366ba8867@2ndquadrant.com> Date: Mon, 29 Oct 2018 16:03:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181029015438.GC14242@paquier.xyz> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Michael, On 29/10/2018 02:54, Michael Paquier wrote: > On Sun, Oct 28, 2018 at 11:59:49PM +0100, Petr Jelinek wrote: >> I wrote my own patch to solve this which is quite similar to Alvaro's >> except that it does not do the manual work to build indexes list as we >> already have RelationGetReplicaIndex which does all the necessary work >> and also uses the same rd_idattr for cache that >> RelationGetIndexAttrBitmap does, it's better for performance and looks >> safe to me. >> >> I attached both patch for PG11+ (ie master) and the backport patch for >> PG10, they only differ in the line identified above as problematic. > > Hmm. I am studying this patch, and this visibly cannot be easily > reproduced? I would have imagined that something like this would be > enough, with a predicate index on the publisher side which is in charge > of loading the : > -- connect to publisher > \c postgres postgres /tmp 5432 > create table aa (a int not null, b int); > create function copy_int(a int) returns int as $$ select $1 $$ > language sql immutable; > create index aai on aa (b) where copy_int(b) > 0; > create unique index aai2 on aa (a); > alter table aa replica identity using index aai2; > create publication big_tables for table aa; > insert into aa values (generate_series(1,100), 1); > > -- connect to subscriber > \c postgres postgres /tmp 5433 > create table aa (a int not null, b int); > create function copy_int(a int) returns int as $$ select $1 $$ > language sql immutable; > create index aai on aa (b) where copy_int(b) > 0; > create unique index aai2 on aa (a); > alter table aa replica identity using index aai2; > create subscription sub_name CONNECTION 'host=/tmp dbname=postgres > user=postgres' PUBLICATION big_tables; > > Is there something I am missing? It needs to be function that requires snapshot to be built, which yours does not. This all happens because we try to inline the SQL functions into expression so all the expression machinery for running the function gets involved and if the function needs snapshot the snapshot will be created (which is where the crash comes from). The reason why it breaks for OP is that his IMMUTABLE function is not actually IMMUTABLE, that's also why we don't see it reported much. Given this I am not sure if we want to add test for this as it's something one should not do because it has unpredictable side effects, but if you think it will be useful anyway I can whip something out. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services