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 1gYArB-0005jO-G1 for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Dec 2018 14:23:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYAr8-0002LP-Vb for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Dec 2018 14:23:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYAr8-0002LH-Ar for pgsql-hackers@lists.postgresql.org; Sat, 15 Dec 2018 14:23:50 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYAr0-00023t-Fi for pgsql-hackers@postgresql.org; Sat, 15 Dec 2018 14:23:48 +0000 Received: by mail-wr1-x441.google.com with SMTP id c14so8086863wrr.0 for ; Sat, 15 Dec 2018 06:23:42 -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=XxZ8RDkFXU0NUcexBn2rKy22y29cP7C3qGGLpE2UQN4=; b=h2UF2b/KmrHjODCuS1dU1KWY6ZBWjNW87GSjDt1R+rlbhPfRdh2tcv8P6gmxG19c7f 7YqTOLtn0sb4O28MciKOeEE4nfQ4mmgClHS0BxLtEbhc821YcQ+waEJCNopwRlMI50mF uoEUI6y/h7krmwcuSKVmGT5l8OzEWvLwwrY54V7rv5PLPHiRPaaFYkXjRusXjj38QMpe f05rAiH+/u8QxYLUDSQvwomH7IHA0jZU4w3cMQ+UVDlnHORiN/OBusAeILsqde5vLlue q1KRrfdh3GF3gYWsOhJHwxaPLK7RpZ4JIYl/inT1C+12a50ho5pSh3ve2UmTwYlWBol3 YB8Q== 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=XxZ8RDkFXU0NUcexBn2rKy22y29cP7C3qGGLpE2UQN4=; b=EfhM9+ccX7kG81QHjZd1St3l/F84k9ilc4Z9pvRt6rs0i7ePz0z3+HGREKyOEbOrMd j8Wh49IKv8D1nHmkGzwoPy9ngHhWU0Hy/1PNfdCSCdd4rx8hLlkM5iMt3NclSwUdEHaX qDNRYrKUrldSOU5Ve2sO3SH8knvzTbdzY1xlBbrYVPGlYPD8ocBnZzy1ropS6UZTB7+g MDutLKcvR1IOjE6hC79ka1CCKMFsnd6iafxnbRnLCCpD4bBO9zBhXO7NS7sc5ln5BOTK gqhqvJ0noFg9HFsHxeiQurt/v6kiU642OgNeKPGlHKjeZLpnFYU1xt7V4MgVvlpjQudG Rpfg== X-Gm-Message-State: AA+aEWY8UbLzmB9+uecmtDt4jviFmH8ZY54tAONQMAyF4YirKAcFxhvZ CZ9zO2Z+XZicHaYJutlF9HY02A== X-Google-Smtp-Source: AFSGD/VtR3C3C6MIdILOxD4T8RMUMj6dJc+nrvDbWQC7bCDOrukzmKMqewUVHNTpemonJv4eoz6LmA== X-Received: by 2002:adf:fc89:: with SMTP id g9mr5490224wrr.96.1544883820649; Sat, 15 Dec 2018 06:23:40 -0800 (PST) Received: from [192.168.0.234] (ip-86-49-240-48.net.upcbroadband.cz. [86.49.240.48]) by smtp.gmail.com with ESMTPSA id r69sm11726671wmd.4.2018.12.15.06.23.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Dec 2018 06:23:40 -0800 (PST) Subject: Re: row filtering for logical replication To: Stephen Frost , Tomas Vondra Cc: =?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> 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+MxVl3G+d/4Ihy4abxOdW pe9zLIcVMvqiUFQO28/79Gfhb7G4K+L21ORB82QY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TQC9MzNzUhyXvA5a RQQCRMXKbGaYhKkYEYiYOGqtTxN+PmyvNUBmFEcagBX2TXqEkgnI6zOnN13mB4SihJ2lne2r 9RNiPYs/hmRxYg== Message-ID: Date: Sat, 15 Dec 2018 15:23:39 +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: <20181214155645.GV3415@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 14/12/2018 16:56, Stephen Frost wrote: > Greetings, > > * 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. That's why I would do the simple and safe way first before allowing more, otherwise we'll be discussing this for next couple of PG versions. >>> 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... > >>> 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. 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? -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services