Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgG0d-00016V-CV for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Oct 2021 00:44:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mgG0a-0008LH-K3 for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Oct 2021 00:44:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgG0a-0008L7-8o for pgsql-hackers@lists.postgresql.org; Fri, 29 Oct 2021 00:44:36 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mgG0X-0005hf-Kv for pgsql-hackers@postgresql.org; Fri, 29 Oct 2021 00:44:35 +0000 Received: by mail-io1-xd31.google.com with SMTP id v65so10523653ioe.5 for ; Thu, 28 Oct 2021 17:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=biWmSrSEqHlLI4SvE4AdDl91t2067lrHwC8Mu9aCJK0=; b=j7yCmVT/8Z2CWbmUB6Vb4FNIryjE5qjcKy7eslblXduWWKdBSfNvEhBh603WWho5Ec UZf9kX7Tua4oP0Tbof9K0UJbUn9Q5m79nOR8AxoGaNBLwBeFcGysf47q5zrIKtk2mPoG XFzbR2xybzGePKaDiseDp2/Kq7tAyLCPjr+OWCdB2C3MiqBN6nOM0V9Lg20ZeEiLKgsZ Q0gYY03oZRMsuVgh/k9t1K5JhtWQAqV/8etPNBAGKuQUE/s9cRLA71JPiGFj6ggRlxe7 iFOvzj4sz625NfyjlWhd7YV675fCulbXXnB5mAMKnhV8islCs89tIOTGFcFGJk3B5Fc0 vwyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=biWmSrSEqHlLI4SvE4AdDl91t2067lrHwC8Mu9aCJK0=; b=Lxlps8yF/Ws/sy7eNnBoyCuZTw/l13gru/iwgSSuNUyvn/ZO8cMyystc6e9kjqrvxh adfN6WnZStnO6WhXCqP4k3R/vD+pyx+1E99vgZQovVr1zx6yD8hQaGkE4YI9gxQR8+nh MTzdHAm3Z/A9bdFufw2cFv3xQI67kU0tXshaVeFQlZ4ZZ5jYoawaPLygAAEC//2a+NKj /6KBOrCEktNEqnH47zHNYwmlZQcYMEkeVg8pgeineik5xBz58QURetN2dj4Q+QOXs1Co rtrMLkySF2FkFjytPizS4TjHh9MmvAv7d0ZPKzapVjhteTkz09zLuwANWtcIFXN1z+E+ 2aEQ== X-Gm-Message-State: AOAM533m2UBvtbxQSgQnKk9rDqNuDCbgOsDJC80yMmD0t+hk8kUvM2ap 0ZTa9ZTQtxQdQHPKaRkiNsTSeziYzwqi+xcBaUc= X-Google-Smtp-Source: ABdhPJwybmHy8QN0rhsXHYIcEoKd7l7NoZ6IuGVMPaQDed3TDgWAQNQmJbxeaUB8YD8EjE9zoPDIDwUJPXVy74z0zgk= X-Received: by 2002:a5e:c90f:: with SMTP id z15mr5233651iol.103.1635468272583; Thu, 28 Oct 2021 17:44:32 -0700 (PDT) MIME-Version: 1.0 References: <202107281526.o74ieuj6sj7z@alvherre.pgsql> <2b14d595-1e8b-e5b6-6098-6a11d19fa1c7@amazon.com> <688cbedf-a172-f0d8-8352-d4ea223bceeb@amazon.com> <20211028210755.afmwcvpo6ajwdx6n@alap3.anarazel.de> In-Reply-To: <20211028210755.afmwcvpo6ajwdx6n@alap3.anarazel.de> From: Robert Haas Date: Thu, 28 Oct 2021 20:44:21 -0400 Message-ID: Subject: Re: Minimal logical decoding on standbys To: Andres Freund Cc: "Drouvot, Bertrand" , Alvaro Herrera , Ibrar Ahmed , Amit Khandekar , fabriziomello@gmail.com, tushar , Rahila Syed , pgsql-hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Oct 28, 2021 at 5:07 PM Andres Freund wrote: > > I think that, in order to have > > any chance of being acceptable, this would need to be restructured so > > that it pulls data from an existing relcache entry that is known to be > > valid, without attempting to create a new one. That is, > > get_rel_logical_decoding() would need to take a Relation argument, not > > an OID. > > Hm? Once we have a relation we don't really need the helper function anymore. Well, that's fine, too. > > I also think it's super-weird that the value being logged is computed > > using RelationIsAccessibleInLogicalDecoding(). That means that if > > wal_level < logical, we'll set onCatalogTable = false in the xlog > > record, regardless of whether that's true or not. Now I suppose it > > won't matter, because presumably this field is only going to be > > consulted for whatever purpose when logical replication is active, but > > I object on principle to the idea of a field whose name suggests that > > it means one thing and whose value is inconsistent with that > > interpretation. > > Hm. Not sure what a good solution for this is. I don't think we should make > the field independent of wal_level - it doesn't really mean anything with a > lower wal_level. And it increases the illusion that the table is guaranteed to > be a system table or something a bit. Perhaps the field name should hint at > this being logically decoding related? Not sure - I don't know what this is for. I did wonder if maybe it should be testing IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation) i.e. RelationIsAccessibleInLogicalDecoding() with the removal of the XLogLogicalInfoActive() and RelationNeedsWAL() tests. But since I don't know what I'm talking about, all I can say for sure right now is that the field name and the field contents don't seem to align. > > I also notice that 0003 deletes a comment that says "We need to force > > hot_standby_feedback to be enabled at all times so the primary cannot > > remove rows we need," but also that this is the only mention of > > hot_standby_feedback in the entire patch set. If the existing comment > > that we need to do something about that is incorrect, we should update > > it independently of this patch set to be correct. But if the existing > > comment is correct then there ought to be something in the patch that > > deals with it. > > The patch deals with this - we'll detect the removal of row versions that > aren't needed anymore and stop decoding. Of course you'll most of the time > want to use hs_feedback, but sometimes it'll also just be a companion slot on > the primary or such (think slots for failover or such). Where and how does this happen? > > Another part of that same deleted comment says "We need to be able to > > correctly and quickly identify the timeline LSN belongs to," but I > > don't see what the patch does about that, either. I'm actually not > > sure exactly what that's talking about > > Hm - could you expand on what you're unclear about re LSN->timeline? It's just > that we need to read a WAL page for a certain LSN, and for that we need the > timeline? I don't know - I'm trying to understand the meaning of a comment that I think you wrote originally. > > This function's sister, read_local_xlog_page(), contains a bunch of logic > > that tries to make sure that we're always reading every record from the > > right timeline, but there's nothing similar here. I think that would likely > > have to be fixed in order for decoding to work on standbys, but maybe I'm > > missing something. > > I think that part actually works, afaict they both rely on the same > XLogReadDetermineTimeline() for that job afaict. What might be missing is > logic to update the target timeline. Hmm, OK, perhaps I mis-spoke, but I think we're talking about the same thing. read_local_xlog_page() has this: * RecoveryInProgress() will update ThisTimeLineID when it first * notices recovery finishes, so we only have to maintain it for the * local process until recovery ends. */ if (!RecoveryInProgress()) read_upto = GetFlushRecPtr(); else read_upto = GetXLogReplayRecPtr(&ThisTimeLineID); tli = ThisTimeLineID; That's a bulletproof guarantee that "tli" and "ThisTimeLineID" are up to date. The other function has nothing similar. -- Robert Haas EDB: http://www.enterprisedb.com