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 1tzFKq-00HDrC-GM for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Mar 2025 13:37: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 1tzFKo-005ud1-E1 for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Mar 2025 13:37:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzFKn-005uct-Ug for pgsql-hackers@lists.postgresql.org; Mon, 31 Mar 2025 13:37:50 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tzFKk-002EbE-30 for pgsql-hackers@lists.postgresql.org; Mon, 31 Mar 2025 13:37:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1743428265; bh=Qa+XfMLcHXIbPDyQTtspKxFHkSOTQyafZQAazbOPAHQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=OZSI+82JqsaqPFsZenAXQJlf3TMH755yLNZB6zhlFFtybGpL8UynpsnFLWy441kTe 7hLLTVZNMmV2S6wWooqXCcPXh0wL/zScG3JqQsOwst1Jtf+pylZSfP6IrSL/ZbChgK lXA4dXkEPYPKYd8OZ/zfct9rYSO4eIRIZ5+v1J8wC1EVcyECoswX1l6v0wv3v/dXvl JzZRPZmrBIAihyaHUyU8IQSS9yqZ+yvJXhy9uFb3KeDJpM9zfKafr5gMnJIBnH8QgV KVZpAVzXQ0hXkAtyRcizV34DCYOb/VHJSXLuDo3RyMVFJqBGJMQ9FUqUVaAg51eTHR o5JR0/6GGlhHQ== Received: from mail.postgrespro.ru (webmail-slave-mstn.l.postgrespro.ru [192.168.2.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.imamov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 1123B5FFDE; Mon, 31 Mar 2025 16:37:45 +0300 (MSK) MIME-Version: 1.0 Date: Mon, 31 Mar 2025 16:37:44 +0300 From: Aidar Imamov To: Nazir Bilal Yavuz Cc: Joseph Koshakow , Andres Freund , PostgreSQL Hackers Subject: Re: Add pg_buffercache_evict_all() and pg_buffercache_mark_dirty[_all]() functions In-Reply-To: References: <568288111d505a81ebb2a89cea9eacb2@postgrespro.ru> Message-ID: X-Sender: a.imamov@postgrespro.ru Organization: PostgresPro Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/03/31 10:32:00 #27843261 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi! I've reviewed the latest version of the patches and found a few things worth discussing. This is probably my final feedback on the patches at this point. Maybe Joseph has something to add. After this discussion, I think it would be helpful if one of the more experienced hackers could take a look at the overall picture (perhaps we should set the status "Ready for Committer"? To be honest, I'm not sure what step that status should be set at). pg_buffercache--1.5--1.6.sql: It seems that there is no need for the OR REPLACE clause after the pg_buffercache_evict() function has been dropped. Maybe we should remove the RETURNS clause from function declarations that have OUT parameters? Doc: "When there are OUT or INOUT parameters, the RETURNS clause can be omitted" pg_buffercache_evict_relation(): The function is marked as STRICT so I think we do not need for redundant check: > if (PG_ARGISNULL(0)) > ereport(ERROR, > (errcode(ERRCODE_INVALID_PARAMETER_VALUE), > errmsg("relation cannot be null"))); Doc: "returns null whenever any of its arguments are null", "the function is not executed when there are null arguments;". EvictUnpinnedBuffer(): Maybe edit this comment a little (just not to repeat the sentences): > buf_state is used to check if the buffer header lock has been acquired > before > calling this function. If buf_state has a non-zero value, it means that > the buffer > header has already been locked. This information is useful for evicting > specific > relation's buffers, as the buffers headers need to be locked before > this function > can be called with such a intention. EvictUnpinnedBuffer() & EvictRelUnpinnedBuffers(): Why did you decide to use the assert to check for NULLs? I understand that currently, the use of these functions is limited to a specific set of calls through the pg_buffercache interface. However, this may not always be the case. Wouldn't it be better to allow users to choose whether or not they want to receive additional information? For example, you could simply ignore any arguments that are passed as NULL. Additionally, I believe it would be beneficial to include some regression tests to check at least the following cases: return type, being a superuser, bad buffer id, local buffers case. Also, there's a little thing about declaring functions as PARALLEL SAFE. To be honest, I don't really have any solid arguments against it. I just have some doubts. For example, how will it work if the plan is split up and we try to work on an object in one part, while the other part of the plan evicts the pages of that object or marks them as dirty... I can't really say for sure about that. And in that context, I'd suggest referring to that awesome statement in the documentation: "If in doubt, functions should be labeled as UNSAFE, which is the default." regards, Aidar Imamov