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.92) (envelope-from ) id 1j9U63-0002og-4g for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Mar 2020 13:29:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9U5z-00011V-QV for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Mar 2020 13:29:55 +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 1j9U5z-00010d-AB for pgsql-bugs@lists.postgresql.org; Wed, 04 Mar 2020 13:29:55 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1j9U5r-0003B8-Et for pgsql-bugs@lists.postgresql.org; Wed, 04 Mar 2020 13:29:53 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 36DD421C1C2D; Wed, 4 Mar 2020 16:29:45 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from ars-thinkpad (nat03-43-2.netorn.net [188.35.130.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id E6B3321C08BB; Wed, 4 Mar 2020 16:29:44 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1583328584; bh=tp+qIYzAqsxe4/+zWdMF5IB6Tkidg6Ye/tq1O29SRs0=; h=References:From:To:Cc:Subject:In-reply-to:Date; b=LZRVKt1LiOa3/alano45q90nPoeePgwHTuPHgWB6225zI/JqLfQiC82ogL5jU0RMR 34ywGbbyeYSi9iT7WL1ZJ56gsMf2Qv1SM8AwvnGmFPseXwEH0wS/3gpwI/6Q7Jc5xY 0f3z5mZ6GBQp5EQJm6mQc1Bgqp2EHSNCOQqOqkuk= References: <87ftjifoql.fsf@ars-thinkpad> <20191024213157.7pm6niybfxgpvmgg@alap3.anarazel.de> <87eez1fh48.fsf@ars-thinkpad> <8736bs81sx.fsf@ars-thinkpad> <871rrb942q.fsf@ars-thinkpad> <87zhdx76d5.fsf@ars-thinkpad> <8736bjoiax.fsf@ars-thinkpad> <87o8tf6w59.fsf@ars-thinkpad> <87mu8y7u9r.fsf@ars-thinkpad> User-agent: mu4e 1.2.0; emacs 26.0.50 From: Arseny Sher To: Amit Kapila Cc: Andres Freund , "Hsu\, John" , "pgsql-bugs\@lists.postgresql.org" Subject: Re: ERROR: subtransaction logged without previous top-level txn record In-reply-to: Date: Wed, 04 Mar 2020 16:29:44 +0300 Message-ID: <87lfog6yev.fsf@ars-thinkpad> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Kapila writes: >> Because when we create the slot we don't demand to stream from some >> specific point. In fact we just can't, because we don't know since which >> LSN it is actually possible to stream, i.e. when we'd have good snapshot >> and no old (which we haven't seen in full) xacts running. It is up to >> snapbuild.c to define this point. The previous coding was meaningless: >> we asked for some random restart_lsn and snapbuild.c would silently >> advance it to earliest suitable LSN. >> > > Hmm, if this is the case then it should be true even without solving > this particular problem and we should be able to make this change. Right. > Leaving that aside, I think this change can make copy replication slot > functionality to also skip using serialized snapshots with this patch > which is not our intention. As I say at [1] logical slot copying facility is currently anyway broken in this regard: restart_lsn is copied, but confirmed_flush isn't, and the right fix, in my view, is to avoid DecodingContextFindStartpoint there altogether (by checking donor's confirmed_flush is valid and copying it) which would render this irrelevant. To speculate, even if wanted to go through DecodingContextFindStartpoint for slot copying and establish confirmed_flush on our own, surely we'd need to handle serialized snapshots exactly as new slot creation does because dangers of getting SNAPBUILD_CONSISTENT too early are the same in both cases. > Also, it doesn't seem like a good idea to ignore setting > start_decoding_at when we already set slot->data.restart_lsn with this > value. Well, these two fields have absolutely different values. BTW I find the naming here somewhat unfortunate, and this phrase suggests that it indeed leads to confusion. Slot's restart_lsn is the LSN since which we start reading WAL and by setting data.restart_lsn we prevent WAL we need from recycling. start_decoding_at is the LSN since which we start *streaming*, i.e. actually replaying COMMITs. So setting the first one (as we must hold WAL) and not the second one (as we don't know the streaming point yet when we start slot creation) is just fine. [1] https://www.postgresql.org/message-id/flat/CA%2Bfd4k70BXLTm-N6q18LrL%3DGbKtwY3-2%2B%2BUVFw05SvFTkZgTyQ%40mail.gmail.com -- cheers, arseny