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 1gcfCb-0007WP-Hc for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 23:36:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcfCa-0000hO-1a for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 23:36:32 +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 1gcfCZ-0000hH-PO for pgsql-hackers@lists.postgresql.org; Thu, 27 Dec 2018 23:36:31 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcfCW-0000Vb-MY for pgsql-hackers@postgresql.org; Thu, 27 Dec 2018 23:36:31 +0000 Received: by mail-wm1-x341.google.com with SMTP id g67so18574578wmd.2 for ; Thu, 27 Dec 2018 15:36:28 -0800 (PST) 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=SN3PuHU7eBRZNMrTBHLyt05+A+1yYHfTDUmPT96TFHQ=; b=sC/H+R3IGQyFJFzXpG2nj2mW+NGtYlPsiAaG6rMNd8sOk5QYHa3FmTpRbGVvViIlF2 LvX22ivbv8DPPJV+mFEr43avRAO/SphCMxDXNsVIuWNkjHa0FhXxkAjzyUdm8JJtdI3U 9Q4yhGtNeFR5ACvSxeYA12BlQrvzFxkRS3JzUn72HwRSLPIOfQcvZCOGiYNWby4UQBU0 RJ2a26nFB7yvkynintl8uFmt8hGobTN/4UBetAH1PF94wNXSepQ+6cFqnR8WHHVl38Y5 QWNzA6us4gjbNeu1xrK3/a+bP94mSdNaL6xocwiMtUASf5HKA+v3X58xNt/wyVn/Xww8 tDZQ== 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=SN3PuHU7eBRZNMrTBHLyt05+A+1yYHfTDUmPT96TFHQ=; b=lpxPJqiyDjHK6f/Xs2hYX4+UNJpedru7fSCkObg58OeT2moAdaN1KU8J9orWHdi71T hVWLU5xwNBAiY/x74gvJ58Xs2PK6UZTAQQYSEQ6E2oriCc8yUG1791sgURgxXsc5ljRe HoiKBBlCjKHAYC5OCmaOQp8CMaeax8QZoUIKpOY1GU7bVwWoVhrwk6uwMofMtdLvEu3v A7MbOi08snyuVuoh9IjRkCNs8Y6UGeKncnHLRxwpx5VqQAHD4mnt71tl2AAH1lfSzvCm cOYCfWuARvD57LmqnFGhI4XGfvZGMmbQ5G3pyKEugOqvmgcM2az057NShTuDp/XeYJ3b NM6A== X-Gm-Message-State: AA+aEWaN1DabCZ3ggPHH3cndWTCbs/oqKOMik7J/LpItRGXZcRlOSz/M ++aLXcxkapG6+fdsHclhjlxj8Q== X-Google-Smtp-Source: AFSGD/UK4Nq5o1yA/ae9tYN9DoVmNX8TVVtl2e9GdI/xsKZsQotopQ8Jop27g64gt/oODIP0jEtoaQ== X-Received: by 2002:a1c:7fca:: with SMTP id a193mr22503282wmd.36.1545953786858; Thu, 27 Dec 2018 15:36:26 -0800 (PST) Received: from ?IPv6:2a02:8308:13b:9400:7f0a:ad2f:38cf:def0? ([2a02:8308:13b:9400:7f0a:ad2f:38cf:def0]) by smtp.gmail.com with ESMTPSA id v4sm28774098wme.6.2018.12.27.15.36.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 15:36:26 -0800 (PST) Subject: Re: row filtering for logical replication To: Stephen Frost Cc: Tomas Vondra , =?UTF-8?Q?Fabr=c3=adzio_de_Royes_Mello?= , Euler Taveira de Oliveira , Pgsql Hackers , hironobu@interdb.jp References: <7106a0fc-8017-c0fe-a407-9466c9407ff8@2ndquadrant.com> <92e5587d-28b8-5849-2374-5ca3863256f1@2ndquadrant.com> <466cdec7-92a0-41c0-b74a-ec0be94d4451@2ndquadrant.com> <20181123190330.GI3415@tamriel.snowman.net> <20181214155645.GV3415@tamriel.snowman.net> <20181227191925.GJ2528@tamriel.snowman.net> From: Petr Jelinek Openpgp: preference=signencrypt Autocrypt: addr=petr.jelinek@2ndquadrant.com; prefer-encrypt=mutual; keydata= mQINBFawwSABEAC45Vua8rSggpM2kkMMmoOHz51a+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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/1 PLJtJBdRHucP76vUH9RlP9EE/Sg5DFQqsfSYPqxLW9r+ZfSEeT0APdz7TQC9MzNzUhyXvA5a RQQCRMXKbGaYhKkYEYiYOGqtTxN+PmyvNUBmFEcagBX2TXqEkgnI6zOnN13mB4SihJ2lne2r 9RNiPYs/hmRxYg== Message-ID: Date: Fri, 28 Dec 2018 00:36:25 +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: <20181227191925.GJ2528@tamriel.snowman.net> 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 On 27/12/2018 20:19, Stephen Frost wrote: > Greetings, > > * Petr Jelinek (petr.jelinek@2ndquadrant.com) wrote: >> On 14/12/2018 16:56, Stephen Frost wrote: >>> * Tomas Vondra (tomas.vondra@2ndquadrant.com) wrote: >>>> On 11/23/18 8:03 PM, Stephen Frost wrote: >>>>> * Fabrízio de Royes Mello (fabriziomello@gmail.com) wrote: >>>>>> On Fri, Nov 23, 2018 at 4:13 PM Petr Jelinek >>>>>> wrote: >>>>>>>> If carefully documented I see no problem with it... we already have an >>>>>>>> analogous problem with functional indexes. >>>>>>> >>>>>>> The difference is that with functional indexes you can recreate the >>>>>>> missing object and everything is okay again. With logical replication >>>>>>> recreating the object will not help. >>>>>>> >>>>>> >>>>>> In this case with logical replication you should rsync the object. That is >>>>>> the price of misunderstanding / bad use of the new feature. >>>>>> >>>>>> As usual, there are no free beer ;-) >>>>> >>>>> There's also certainly no shortage of other ways to break logical >>>>> replication, including ways that would also be hard to recover from >>>>> today other than doing a full resync. >>>> >>>> Sure, but that seems more like an argument against creating additional >>>> ones (and for preventing those that already exist). I'm not sure this >>>> particular feature is where we should draw the line, though. >>> >>> I was actually going in the other direction- we should allow it because >>> advanced users may know what they're doing better than we do and we >>> shouldn't prevent things just because they might be misused or >>> misunderstood by a user. >> >> That's all good, but we need good escape hatch for when things go south >> and we don't have it and IMHO it's not as easy to have one as you might >> think. > > We don't have a great solution but we should be able to at least drop > and recreate the publication or subscription, even today, can't we? Well we can drop thing always, yes, not having ability to drop things when they break would be bad design. I am debating ability to recover without rebuilding everything a there are cases where you simply can't rebuild everything (ie we allow filtering out deletes). I don't like disabling UDFs either as that means that user created types are unusable in filters, I just wonder if saying "sorry your replica is gone" is any better. > Sure, that means having to recopy everything, but that's what you get if > you break your publication/subscription. This is but off-topic here, but I really wonder how are you currently breaking your publications/subscriptions. >>>>> What that seems to indicate, to me at least, is that it'd be awful >>>>> nice to have a way to resync the data which doesn't necessairly >>>>> involve transferring all of it over again. >>>>> >>>>> Of course, it'd be nice if we could track those dependencies too, >>>>> but that's yet another thing. >>>> >>>> Yep, that seems like a good idea in general. Both here and for >>>> functional indexes (although I suppose sure is a technical reason why it >>>> wasn't implemented right away for them). >>> >>> We don't track function dependencies in general and I could certainly >>> see cases where you really wouldn't want to do so, at least not in the >>> same way that we track FKs or similar. I do wonder if maybe we didn't >>> track function dependencies because we didn't (yet) have create or >>> replace function and that now we should. We don't track dependencies >>> inside a function either though. >> >> Yeah we can't always have dependencies, it would break some perfectly >> valid usage scenarios. Also it's not exactly clear to me how we'd track >> dependencies of say plpython function... > > Well, we could at leasts depend on the functions explicitly listed at > the top level and I don't believe we even do that today. I can't think > of any downside off-hand to that, given that we have create-or-replace > function. > I dunno how much is that worth it TBH, the situations where I've seen this issue (pglogical has this feature for long time and suffers from the same lack of dependency tracking) is that somebody drops table/type used in a function that is used as filter. >>>>> In short, I'm not sure that I agree with the idea that we shouldn't >>>>> allow this and instead I'd rather we realize it and put the logical >>>>> replication into some kind of an error state that requires a resync. >>>> >>>> That would still mean a need to resync the data to recover, so I'm not >>>> sure it's really an improvement. And I suppose it'd require tracking the >>>> dependencies, because how else would you mark the subscription as >>>> requiring a resync? At which point we could decline the DROP without a >>>> CASCADE, just like we do elsewhere, no? >>> >>> I was actually thinking more along the lines of just simply marking the >>> publication/subscription as being in a 'failed' state when a failure >>> actually happens, and maybe even at that point basically throwing away >>> everything except the shell of the publication/subscription (so the user >>> can see that it failed and come in and properly drop it); I'm thinking >>> about this as perhaps similar to a transaction being aborted. >> >> There are several problems with that. First this happens in historic >> snapshot which can't write and on top of that we are in the middle of >> error processing so we have our hands tied a bit, it's definitely going >> to need bit of creative thinking to do this. > > We can't write to things inside the database in a historic snapshot and > we do have to deal with the fact that we're in error processing. What > about writing somewhere that's outside of the regular database system? > Maybe a pg_logical/failed directory? There's all the usual > complications from that around dealing with durable writes (if we need > to worry about that and I'm not sure that we do... if we fail to > persist a write saying "X failed" and we restart.. well, it's gonna fail > again and we write it then), and cleaning things up as needed (but maybe > this is handled as part of the DROP, and we WAL that, so we can re-do > the removal of the failed marker file...), and if we need to think about > what should happen on replicas (is there anything?). That sounds pretty reasonable. Given that this is corner-case user error we could perhaps do extra work to ensure things are fsynced even if it's all not too fast... > >> Second, and that's more soft issue (which is probably harder to solve) >> what do we do with the slot and subscription. There is one failed >> publication, but the subscription may be subscribed to 20 of them, do we >> kill the whole subscription because of single failed publication? If we >> don't do we continue replicating like nothing has happened but with data >> in the failed publication missing (which can be considered data >> loss/corruption from the view of user). If we stop replication, do we >> clean the slot so that we don't keep back wal/catalog xmin forever >> (which could lead to server stopping) or do we keep the slot so that >> user can somehow fix the issue (reconfigure subscription to not care >> about that publication for example) and continue replication without >> further loss? > > I would think we'd have to fail the whole publication if there's a > failure for any part of it. Replicating a partial set definitely sounds > wrong to me. Once we stop replication, yes, we should clean the slot > and mark it failed so that we don't keep back WAL and so that we allow > the catalog xmin to move forward so that the failed publication doesn't > run the server out of disk space. > I agree that continuing replication where some part of publication is broken seems wrong and that we should stop replication at that point. > If we really think there's a use-case for keeping the replication slot It's not so much about use-case as it is about complete change of behavior - there is no current error where we remove existing slot. The use case for keeping slot is a) investigation of the issue, b) just skipping the broken part of stream by advancing origin on subscription and continuing replication, with some luck that can mean only single table needs resyncing, which is better than rebuilding everything. I think some kind of automated slot cleanup is desirable, but likely separate feature that should be designed based on amount of outstanding wal or something. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services