Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t4DSq-00H1Ze-Q0 for pgsql-committers@arkaria.postgresql.org; Fri, 25 Oct 2024 06:06:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t4DSo-00CnNP-FM for pgsql-committers@arkaria.postgresql.org; Fri, 25 Oct 2024 06:06:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t4DSo-00CnNH-3M for pgsql-committers@lists.postgresql.org; Fri, 25 Oct 2024 06:06:22 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t4DSk-002k8i-OQ for pgsql-committers@lists.postgresql.org; Fri, 25 Oct 2024 06:06:21 +0000 Received: from [192.168.1.188] (adsl-39.176.58.137.tellas.gr [176.58.137.39]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4XZXN50zF9z49QB3; Fri, 25 Oct 2024 09:06:12 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1729836374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wTGMY1wr1FOns7o5oRE+1W/o8KXhbH8EMExzntgfST4=; b=PnGrtXkklfwuuZkHv/5mYCAvHpW3C+xTULqHMmxsv+EYqzNVCI9JVDBR8I54UkxUpcGabM rPXRrLTB2wP1NYk1uMs+HbR6Agj/ZP5TDrhTnLkGi0S4m2g+EIKxZ9tj9nA6AElhwR/n/C 9tO+qDUVCH1/wYgPqbJef7vmH8XQoqFhDeCng6hcpZ1nJJG2jLK3PLJrCIIZ4Pt0Q6qpqa 9OVhkkvtz5Y88u7yd7d6m0duLjSk4SvH4SIV253Upoi3wW3izzuHvydE2ILaXpzsR7AvGl 0S+Zd40QjeBubXAht1ddrjBi177S5m5wVMXsB6qrVdDx6ddtBhSckvrFsRHbfw== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1729836374; a=rsa-sha256; cv=none; b=qIMkep5/6uejE27YzMDm5sBPiDiw2xDiH1dco7yYR8SysuLUimOcJPWX7uE3niCLo6GvdZ O70Mp+gV7bus0J+WQ0heYT5EQVKegYrJxAOVnsS7PZmX0E09UOBUd9ox9+K0nvSH8fXwxE /xNDwE8KPq4YAty47bUqVd0Ke/UevTevVFEIY0MXG3dkZdcx3hGaNjUo019lnqjc4Otzcc PW8Gd+F60Z+g8sbmdlurgos80Prx94tZ/UhhLbjngbrlWMZlaW1UBlRvwRhHgZAXaOvppk gdQ2ouegEeZ5xalUt+GD4HVSbT4ZXHSVE0ApIe2fiEb1/XKNEXLMgIBApOjgLQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1729836374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wTGMY1wr1FOns7o5oRE+1W/o8KXhbH8EMExzntgfST4=; b=eAAaYWJa7Kg0ABWxmkPMUgagrhY1esnc2HGBGNUQJflB4A+VhWeD5rkQqKyjwIBGCQyGEM /WLNqdU/l2cBdA8sqPmU+Ifsg/isYx/CpeIfgk1RYVEmhQnQjXcTov4ojVW3imXSf3sBRq KTrz38P5EGXKZxmZIRXRJnpHTNJfZRulbrWT6K+xIjd6WpFr2Hzx3FkOuTqBEgXJ17kg76 zVH7OuFi2TDWF1nQWyw3ySUpN6+8sf2KqflZ12y3uEzlvQj3saBBv9vJV6/JoaraBIRphC fLnviCYFdL8OxagHg03DG3hn8XE5Txa4F5nQJ39fc+TzYKRBMxBN883ekeTsHg== Message-ID: Date: Fri, 25 Oct 2024 09:06:10 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pgsql: Implement pg_wal_replay_wait() stored procedure To: Alexander Korotkov , Pavel Borisov Cc: Peter Eisentraut , Michael Paquier , pgsql-committers@lists.postgresql.org References: <18c0fa64-0475-415e-a1bd-665d922c5201@eisentraut.org> <1f5b399a-76b1-48e1-87b0-f511e61818f3@eisentraut.org> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk If you call this procedure on a stand-alone server, you get: postgres=# call pg_wal_replay_wait('1234/0'); ERROR: recovery is not in progress DETAIL: Recovery ended before replaying target LSN 1234/0; last replay LSN 0/0. The DETAIL seems a bit misleading. Recovery never ended, because it never started in the first place. Last replay LSN is indeed 0/0, but that's not helpful. If a standby server has been promoted and you pass an LSN that's earlier than the last replay LSN, it returns successfully. That makes sense I guess; if you connect to a standby and wait for it to replay a commit that you made in the primary, and the standby gets promoted, that seems correct. But it's a little inconsistent: If the standby crashes immediately after promotion, and you call pg_wal_replay_wait() after recovery, it returns success. However, if you shut down the promoted server and restart it, then last replay LSN is 0/0, and the call will fail because no recovery happened. What is the use case for the 'no_error' argument? Why would you ever want to pass no_error=true ? The separate pg_wal_replay_wait_status() function feels weird to me. Also it surely shouldn't be marked IMMUTABLE nor parallel safe. This would benefit from more documentation, explaining how you would use this in practice. I believe the use case is that you want "read your writes" consistency between a primary and a standby. You commit a transaction in the primary, and you then want to run read-only queries in a standby, and you want to make sure that you see your own commit, but you're ok with slightly delayed results otherwise. It would be good to add a chapter somewhere in the docs to show how to do that in practice with these functions. -- Heikki Linnakangas Neon (https://neon.tech)