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 1t5MBB-005YRm-3r for pgsql-committers@arkaria.postgresql.org; Mon, 28 Oct 2024 09:36:53 +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 1t5MB9-005GwU-6U for pgsql-committers@arkaria.postgresql.org; Mon, 28 Oct 2024 09:36:51 +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 1t5MB8-005GwJ-VH for pgsql-committers@lists.postgresql.org; Mon, 28 Oct 2024 09:36:51 +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 1t5MB6-003FbO-Gc for pgsql-committers@lists.postgresql.org; Mon, 28 Oct 2024 09:36:50 +0000 Received: from [192.168.1.110] (dsl-hkibng22-50ddb7-241.dhcp.inet.fi [80.221.183.241]) (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 4XcSvb6l53z49Q16; Mon, 28 Oct 2024 11:36:43 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1730108204; 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=SFAAH4H5oPPUBvdQHm6FRWjY7+YD0YWvWiAJAi5AOG8=; b=mMzhS0r9ETxEOrfblRtJSRuMwSjikQnKSsLslLj4ZVuHqgP7FQjDhluzb5WQKSJD0aWdzl YKOGAaNd0lUmUV2nj3mK1V6kZfCDigJywrvdjidPhbrLxEp3a3w/UWgZ57xVFhGXpcMKbx biezh+qgYGC6DNUqcPpGqgeL5YDL1TATVt0oAlck98ujdRS9awL0xQ/hLzeXCgHt0RKM+a XW4chLLsKSBQXY0q7QN4xi/kdv55FyEByGAaLAGvRRQbtnShnJ9ALXEYkysCb/tHD02Wbo lSlCkOHa29h0f7s+0e/k3/bWSt86sgficOwQUOPtfnyOo/GNRP4rs/4iUqZIBQ== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1730108204; a=rsa-sha256; cv=none; b=FXIT6XW8/RD1heGBaFMIiQ590gSJKC/o4TG2jr+9K/6YX3ylb9C1Xahe0Rci+teduwxm5H XHb5IAU1tiDURdUVfN2C8+a1QFXeIKjBmaAavWVNXh67wydlAKRmA31D5i22kT9P8apIkr INaHAEMbkfmrLFF1HKd+mm0CrvLY3yKONzZ87rtkVfyr8bSX+b1qI8LHEHjfmsl90fc6Lz jcsKBEuk9tYM2CSOp1cvgPMZu3Ip3uJkvyHxsKSMpoXna0p+FjqyBsKWl5oxg08LwrGXs4 LwTPJgBLrY3brLxWcRLNuMXts1cWcQdgwFXkOL85vouM1VGYnrBqMXCadb3JAA== 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=1730108204; 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=SFAAH4H5oPPUBvdQHm6FRWjY7+YD0YWvWiAJAi5AOG8=; b=go3xTMGv8l4YNXFe6hIlvjfXLrYOzZ6wGOwo35uEBaKJJ0OjQdSS9idb3aMLVAp0zUINUa 6vF2X/WHs+J/dU4X64vTID25ZzxCnsbk6xeYHLUA6/TLPP9GGWdjsPFlfMFMuEdhSHf54H ZGcdphGXxcy88bCqhEISIMI9el3Obr6YfH5uhl9pWXgyghHWGVwJ64yVgy5eMSNJbX7I++ e2WTdWu7AwbJzewUpM9gO7RSndknkL4FC8yY2v1fZfiktn+Ob9wNpieq/uRJM/IVHXPBoS 0SaOUzHSUE4ilJN20xUQs3tey6PF9LxBV7II64PHgkiIJK4C6Gn0qh+oTOsBcA== Message-ID: <14de8671-e328-4c3e-b136-664f6f13a39f@iki.fi> Date: Mon, 28 Oct 2024 11:36:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pgsql: Implement pg_wal_replay_wait() stored procedure To: Alexander Korotkov Cc: Pavel Borisov , 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 On 25/10/2024 14:56, Alexander Korotkov wrote: > I see that pg_wal_replay_wait_status() might look weird, but it seems > to me like the best of feasible solutions. I haven't written many procedures, but our docs say: > Procedures do not return a function value; hence CREATE PROCEDURE lacks a RETURNS clause. However, procedures can instead return data to their callers via output parameters. Did you consider using an output parameter? > Given that > pg_wal_replay_wait() procedure can't work concurrently to a query > involving pg_wal_replay_wait_status() function, I think > pg_wal_replay_wait_status() should be stable and parallel safe. If you call pg_wal_replay_wait() in the backend process, and pg_wal_replay_wait_status() in a parallel worker process, it won't return the result of the wait. Probably not what you'd expect. So I'd argue that it should be parallel unsafe. > This is the brief answer. I will be able to come back with more > details on Monday. Thanks. A few more minor issues I spotted while playing with this: - If you pass a very high value as the timeout, e.g. INT_MAX-1, it wraps around and doesn't wait at all - You can pass NULLs as arguments. That should probably not be allowed, or we need to document what it means. This is disappointing: > postgres=# set default_transaction_isolation ='repeatable read'; > SET > postgres=# call pg_wal_replay_wait('0/55DA24F'); > ERROR: pg_wal_replay_wait() must be only called without an active or registered snapshot > DETAIL: Make sure pg_wal_replay_wait() isn't called within a transaction with an isolation level higher than READ COMMITTED, another procedure, or a function. Is there any way we could make that work? Otherwise, the feature just basically doesn't work if you use repeatable read. -- Heikki Linnakangas Neon (https://neon.tech)