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 1qGVnJ-0007Ek-1D for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Jul 2023 02:29:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qGVnH-0001sB-FU for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Jul 2023 02:29:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qGVnH-0001s2-61 for pgsql-hackers@lists.postgresql.org; Tue, 04 Jul 2023 02:29:31 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qGVnE-001uec-Nw for pgsql-hackers@lists.postgresql.org; Tue, 04 Jul 2023 02:29:29 +0000 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5577900c06bso3993172a12.2 for ; Mon, 03 Jul 2023 19:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688437767; x=1691029767; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=9W2ETxzViGwJHWSnAwas3LWX+xVVcYl2BIYqcUB/gCg=; b=BdEe6DyzJb4y5ieHhyczAjFUGjwuS9mKCHD2J3f5qxcOXJUDn4zYPfUipy3qFhEuaU TiY7SqLhBldRcPOzm0AWtTr2M9vcTWsdmiSLbhV/1obN2EaDkALOJHmEDG/MtNdZs6Kj +GVCJwneEgm3liGZwysp83VYoPxNfTqsSgTycburbdz01nrb0o/zuiPsXhAr2osCt6cH /rx6RCwdQj7qL2r1OTOWu77peJAm5Y61GtI9vx7OIe5M8Kt3zeBiuf1H9IdAWQQB3pFO kPLP4d053Ym+DXCRmMe1utq3qeUjKLJkQUnL4xHF2bWdvk72vdeL+VoCuOIEnG2R2rr4 KXNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688437767; x=1691029767; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=9W2ETxzViGwJHWSnAwas3LWX+xVVcYl2BIYqcUB/gCg=; b=R3EaNXTU46Dydt2DvG61J7HcML3BEqZvFR8AzM5A4hFUsOrOP6GopWY1tD+po6qqI3 HNFazBaZZDvK8pkrd82f+9LjwZfi3tO2BI+IaNXZqQk+Z4No8C3A0yNrIEnEFcuFHy1m 69icfU3+53MdxPpJyIBH1pm9vYy9hoBzcf3zRfBp0xvA8DuaKDZITOZ64E17dhFIw2ls vwi5HO3GGbHaiS8Db+5tg8R3kTFtysXJcW7wO0WnkoDX4CCO8jnSC+A88HjEKYDnmNXa cPm4Q0/vvOk9bn26Kcp1m//M6VhA9B9K9SFZGOiLqsnvYCZj8dwJ9Au05w7pK0XFjQAh BE7Q== X-Gm-Message-State: ABy/qLZhwRqIctICi/coruKzU1ntUv9GZb6HaQmg+LXeI9S9bfIvuosV q7HXagj9wmvV996xqDzkXEU= X-Google-Smtp-Source: APBJJlG71gJO5jg2CwDMB6f4N4Bk2rA7xgt6Uy5FfMNb7BJZRfF21H7DCxsmaUEnK2ifMMjHhZUmXg== X-Received: by 2002:a17:902:e5c1:b0:1b2:a63:95aa with SMTP id u1-20020a170902e5c100b001b20a6395aamr15139029plf.54.1688437767146; Mon, 03 Jul 2023 19:29:27 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id y19-20020a1709029b9300b001b53be3d942sm15900178plp.232.2023.07.03.19.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 19:29:26 -0700 (PDT) Date: Tue, 04 Jul 2023 11:29:24 +0900 (JST) Message-Id: <20230704.112924.1693682640969530760.horikyota.ntt@gmail.com> To: tomas.vondra@enterprisedb.com Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Is a pg_stat_force_next_flush() call sufficient for regression tests? From: Kyotaro Horiguchi In-Reply-To: <022124fb-70c4-e59f-029e-b752853f7c84@enterprisedb.com> References: <022124fb-70c4-e59f-029e-b752853f7c84@enterprisedb.com> User-Agent: Mew version 6.8 on Emacs 27.2 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Tue_Jul__4_11_29_24_2023_799)--" Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Tue_Jul__4_11_29_24_2023_799)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit At Mon, 3 Jul 2023 15:45:52 +0200, Tomas Vondra wrote in > So I'm wondering if pg_stat_force_next_flush() is enough - AFAICS this > only sets some flag for the *next* pgstat_report_stat() call, but how do > we know that happens before the query execution? > > Shouldn't there be something like pg_stat_flush() that actually does the > flushing, instead of just setting the flag? The reason for the function is that pg_stat_flush() is supposed not to be called within a transaction. AFAICS pg_stat_force_next_flush() takes effect after a successfull transaction end and before the next command execution. To verify this, I put in an assertion to check that the flag gets consumed before reading of pg_stat_io (a.diff), then ran pgbench with the attached custom script. As expected, it didn't fire at all during several trials. When I wrapped all lines in t.sql within a begin-commit block, the assertion fired off immediately as a matter of course. Is there any chance concurrent backends or some other things can actually hinder the backend from reusing buffers? regards. -- Kyotaro Horiguchi NTT Open Source Software Center ----Next_Part(Tue_Jul__4_11_29_24_2023_799)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="a.diff" diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index d743fc0b28..6529e737ea 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -225,7 +225,7 @@ static dlist_head pgStatPending = DLIST_STATIC_INIT(pgStatPending); * Force the next stats flush to happen regardless of * PGSTAT_MIN_INTERVAL. Useful in test scripts. */ -static bool pgStatForceNextFlush = false; +bool pgStatForceNextFlush = false; /* * Force-clear existing snapshot before next use when stats_fetch_consistency diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 2a4c8ef87f..7f60b2834a 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -1352,7 +1352,9 @@ pg_stat_get_io(PG_FUNCTION_ARGS) ReturnSetInfo *rsinfo; PgStat_IO *backends_io_stats; Datum reset_time; + extern bool pgStatForceNextFlush; + Assert(!pgStatForceNextFlush); InitMaterializedSRF(fcinfo, 0); rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; ----Next_Part(Tue_Jul__4_11_29_24_2023_799)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="t.sql" --begin; select pg_stat_force_next_flush(); select sum(reuses) from pg_stat_io; --commit; ----Next_Part(Tue_Jul__4_11_29_24_2023_799)----