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 1jMbin-00034X-Jr for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Apr 2020 18:16:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jMbil-0000zA-SX for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Apr 2020 18:16:11 +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 1jMbil-0000z3-Jh for pgsql-hackers@lists.postgresql.org; Thu, 09 Apr 2020 18:16:11 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jMbii-0007K5-Lh for pgsql-hackers@lists.postgresql.org; Thu, 09 Apr 2020 18:16:11 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 098EB21C5E3C; Thu, 9 Apr 2020 21:16:07 +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 mail.postgrespro.ru (cyclops.l.postgrespro.ru [192.168.27.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id B798521C595D; Thu, 9 Apr 2020 21:16:06 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1586456166; bh=XDEsvH3vYSl8gGBp6Lu1CO5Rm1UKiTisnSzfyGyczts=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=Od5Lh/4qANCqjGXAOoiNbfO83H88841s3/BmgX6H9cKz6B4Wo4UbfTsJDiZNge0Yu XM+8Ido95EPZqFeYmedpPP+SefDfrgm7X/bN6zy1dgDYt2JKQXNFkFYz5YsbXbpHyp VQVneL4YQjFtBKNpZl3sx1SMpRtM83mowQ0UhRvk= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 09 Apr 2020 21:16:05 +0300 From: Alexey Kondratov To: Tom Lane Cc: Fujii Masao , Kyotaro Horiguchi , a.akenteva@postgrespro.ru, a.korotkov@postgrespro.ru, i.kartyshov@postgrespro.ru, amit.kapila16@gmail.com, pgsql-hackers@lists.postgresql.org Subject: Re: [HACKERS] make async slave to wait for lsn to be replayed In-Reply-To: <27171.1586439221@sss.pgh.pa.us> References: <20200408.100945.375702947246835193.horikyota.ntt@gmail.com> <13716.1586378146@sss.pgh.pa.us> <20200409.161107.580344062273684114.horikyota.ntt@gmail.com> <880834ee-4b18-6d5d-9dae-6520c5eb2bef@oss.nttdata.com> <27171.1586439221@sss.pgh.pa.us> User-Agent: Roundcube Webmail/1.4.0 Message-ID: X-Sender: a.kondratov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-04-09 16:33, Tom Lane wrote: > Fujii Masao writes: >> On 2020/04/09 16:11, Kyotaro Horiguchi wrote: >>> At Wed, 08 Apr 2020 16:35:46 -0400, Tom Lane >>> wrote in >>>> Why is this getting grafted onto BEGIN/START TRANSACTION in the >>>> first place? > >>> The rationale for not being a fmgr function is stated in the >>> following >>> comments. [...] > >> This issue happens because the function is executed after BEGIN? If >> yes, >> what about executing the function (i.e., as separate transaction) >> before BEGIN? >> If so, the snapshot taken in the function doesn't affect the >> subsequent >> transaction whatever its isolation level is. > > I wonder whether making it a procedure, rather than a plain function, > would help any. > Just another idea in case if one will still decide to go with a separate statement + BEGIN integration instead of a function. We could use parenthesized options list here. This is already implemented for VACUUM, REINDEX, etc. There was an idea to allow CONCURRENTLY in REINDEX there [1] and recently this was proposed again for new options [2], since it is much more extensible from the grammar perspective. That way, the whole feature may look like: WAIT (LSN '16/B374D848', TIMEOUT 100); and/or BEGIN WAIT (LSN '16/B374D848', WHATEVER_OPTION_YOU_WANT); ... COMMIT; It requires only one reserved keyword 'WAIT'. The advantage of this approach is that it can be extended to support xid, timestamp, csn or anything else, that may be invented in the future, without affecting the grammar. What do you think? Personally, I find this syntax to be more convenient and human-readable compared with function call: SELECT pg_wait_for_lsn('16/B374D848'); BEGIN; [1] https://www.postgresql.org/message-id/aad2ec49-5142-7356-ffb2-a9b2649cdd1f%402ndquadrant.com [2] https://www.postgresql.org/message-id/20200401060334.GB142683%40paquier.xyz Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company