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 1jMvHF-0002bm-2N for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2020 15:09:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jMvHD-0008K1-V2 for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Apr 2020 15:09:03 +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 1jMvHD-0008Jt-Kt for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2020 15:09:03 +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 1jMvHB-0002gP-KR for pgsql-hackers@lists.postgresql.org; Fri, 10 Apr 2020 15:09:03 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 1C95621C5E48; Fri, 10 Apr 2020 18:09:00 +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 D2F8921C5822; Fri, 10 Apr 2020 18:08:59 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1586531339; bh=OP7Wt+IMLWI1gCgqgUg//Q1QgMiXeeTmgicdMz7zCBo=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=H3qg5kyx2aMQHZ2mkv/8nhIinPKZr0CvZhPzJ7Szs3qSO87ILBKXu5T8wehQcKqLk UbGSy2FAQ+GTCuFacp4lgZ3uQAR46E17p1ZBwqKZY5d8/mMYqveQD9eeOaLEvlU+vx IR+XgRj0Lj/cCfmMAH8EYMr9STNKMXkQHpUTKBuM= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 10 Apr 2020 18:08:59 +0300 From: Alexey Kondratov To: Fujii Masao Cc: Tom Lane , 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: <759206c1-265f-97da-d135-fcecbced646b@oss.nttdata.com> 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> <759206c1-265f-97da-d135-fcecbced646b@oss.nttdata.com> 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-10 05:25, Fujii Masao wrote: > On 2020/04/10 3:16, Alexey Kondratov wrote: >> 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; > > I can imagine that some users want to specify the LSN to wait for, > from the result of another query, for example, > SELECT pg_wait_for_lsn(lsn) FROM xxx. If this is valid use case, > isn't the function better? > I think that the main purpose of the feature is to achieve read-your-writes-consistency, while using async replica for reads. In that case lsn of last modification is stored inside application, so there is no need to do any query for that. Moreover, you cannot store this lsn inside database, since reads are distributed across all replicas (+ primary). Thus, I could imagine that 'xxx' in your example states for some kind of stored procedure, that fetches lsn from the off-postgres storage, but it looks like very narrow case to count on it, doesn't it? Anyway, I am not against implementing this as a function. That was just another option to consider. Just realized that the last patch I have seen does not allow usage of wait on primary. It may be a problem if reads are pooled not only across replicas, but on primary as well, which should be quite usual I guess. In that case application does not know either request will be processed on replica, or on primary. I think it should be allowed without any warning, or just saying some LOG/DEBUG at most, that there was no waiting performed. Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company