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 1kSYxp-00070U-Of for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Oct 2020 05:04:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSYxo-0005Cu-FQ for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Oct 2020 05:04:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSYxo-0005Cn-98 for pgsql-bugs@lists.postgresql.org; Wed, 14 Oct 2020 05:04:36 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSYxk-0004CR-LN for pgsql-bugs@lists.postgresql.org; Wed, 14 Oct 2020 05:04:35 +0000 Received: by mail-pg1-x543.google.com with SMTP id r10so1206169pgb.10 for ; Tue, 13 Oct 2020 22:04:32 -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:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=cQCKBdFwQODiIwejX2/idU3nH9jxwhzoOefnU5Hf07g=; b=U6HrIVfLx5UMjw8cerIoDU5XJZpTUT0SvKgm8CLtWxqefG6Y1PFq0qecu0xLQ1cIn0 LAD8v6r53Y2xzyU7HoLqGVgNvzSEcKiW7sgUyzpol/I4hBhv8UNSW1KyYyYXMXKRZn4r R0D58/WQB94U57bV409NdPLpoQYM5vW2mZmy6rVNi8snweIYKptklnc10rJPGH853Mvx 8q1zoo9PswsKWKnBJqsWf+4LS0o7y4lKqXfAQFBLgOrarthZb0ZprLWhS1L15Dj5iOLp wg6QVql8GDLZpQAcYhajke03hwsD/EYURqTK67cWPWfrmS3N8iAQhU9HK2+VpSR+Ge1y SPLA== 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:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cQCKBdFwQODiIwejX2/idU3nH9jxwhzoOefnU5Hf07g=; b=HrS69G0Pjf5SMpNvOXwScR2NM47tfKo3/YKIRqVPewsouK1iFkc29rWrpe/hXQUHCV 7ozJCERNw6NB02XeQvl8kfBrbg9Fr5ZYq37305zL2TTrSMeQ+xC15HRnMUAOHDXxAYme 4ItKkhwTeemgAb9g2IUgSk/g1DuFyuFxcR2Hcl13Ccwbde5ohhRfnJbvfFW0JpEAAKzH lXVwwah+/9UsN5KpsmPN5TvJXVNGd66VzvnLExgL4WsF88IqhIL1UUIug4MH+g3njXkO /fiA+MmuMxT6m9npWYTzTFv6y6iOCge9K1Kgp1sIq4WLgHIApYE7sxktoLeharIf6VE9 sWxQ== X-Gm-Message-State: AOAM533XDRQwq+JQnwCWXvUVkty7RgqO5U9hEAIdN/0iw/OgMqJJCDdJ F8ReBekAogJVCwEtSB5Zl9HKgQ== X-Google-Smtp-Source: ABdhPJxbjimXKrjj9Pec5SCwzZkOaShIEAnVsw/IjqvSxcKAP7J/JWTqlPKOCE/HCn3oELHGPmUC7A== X-Received: by 2002:a63:6f46:: with SMTP id k67mr2348585pgc.296.1602651870780; Tue, 13 Oct 2020 22:04:30 -0700 (PDT) Received: from ?IPv6:2a02:8308:10c:500:79d0:4245:4340:3286? ([2a02:8308:10c:500:79d0:4245:4340:3286]) by smtp.gmail.com with ESMTPSA id y10sm1528985pff.119.2020.10.13.22.04.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Oct 2020 22:04:29 -0700 (PDT) Subject: Re: BUG #16643: PG13 - Logical replication - initial startup never finishes and gets stuck in startup loop To: Alvaro Herrera Cc: Tom Lane , Henry Hinze , pgsql-bugs@lists.postgresql.org, Peter Eisentraut References: <20201014011207.GA18985@alvherre.pgsql> From: Petr Jelinek Message-ID: <4a37c0e0-88a5-5d09-19c6-390b8412d3e6@2ndquadrant.com> Date: Wed, 14 Oct 2020 07:04:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201014011207.GA18985@alvherre.pgsql> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 14/10/2020 03:12, Alvaro Herrera wrote: > On 2020-Oct-12, Petr Jelinek wrote: > >>> However, and this is one reason why I'd welcome Petr/Peter thoughts on >>> this, I don't really understand what happens in LogicalRepApplyLoop >>> afterwards with a tablesync worker; are we actually doing anything >>> useful there, considering that the actual data copy seems to have >>> occurred in the CopyFrom() call in copy_table? In other words, by the >>> time we return control to ApplyWorkerMain with a slot name, isn't the >>> work all done, and the only thing we need is to synchronize protocol and >>> close the connection? >> >> There are 2 possible states at that point, either tablesync is ahead (when >> main apply lags or nothing is happening on publication side) or it's behind >> the main apply. When tablesync is ahead we are indeed done and just need to >> update the state of the table (which is what the code you removed did, but >> LogicalRepApplyLoop should do it as well, just a bit later). When it's >> behind we need to do catchup for that table only which still happens in the >> tablesync worker. See the explanation at the beginning of tablesync.c, it >> probably needs some small adjustments after the changes in your first patch. > > ... Ooh, things start to make some sense now. So how about the > attached? There are some not really related cleanups. (Changes to > protocol.sgml are still pending.) > It would be nice if the new sentences at the beginning of tablesync.c started with uppercase, but that's about as nitpicky as I can be :) > If I understand correcly, the early exit in tablesync.c is not saving *a > lot* of time (we don't actually skip replaying any WAL), even if it's > saving execution of a bunch of code. So I stand by my position that > removing the code is better because it's clearer about what is actually > happening. > I don't really have any problems with the simplification you propose. The saved time is probably in order of hundreds of ms which for table sync is insignificant. -- Petr Jelinek 2ndQuadrant - PostgreSQL Solutions for the Enterprise https://www.2ndQuadrant.com/