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 1tDN6d-000EgD-Hf for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Nov 2024 12:13:20 +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 1tDN5b-00Ckft-Jm for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Nov 2024 12:12:16 +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 1tDN5b-00Ckfl-4W for pgsql-hackers@lists.postgresql.org; Tue, 19 Nov 2024 12:12:15 +0000 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tDN5X-002gUv-0g for pgsql-hackers@postgresql.org; Tue, 19 Nov 2024 12:12:14 +0000 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2e8b:0:640:9795:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id D265A608F2; Tue, 19 Nov 2024 15:12:06 +0300 (MSK) Received: from smtpclient.apple (unknown [2a02:6b8:b081:b587::1:5]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 5CQv788TwW20-IQVteIcD; Tue, 19 Nov 2024 15:12:06 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1732018326; bh=6JoKrl0nT/Uc/xTIDDuKVVPhwDbordJgb6JJwft4H+Q=; h=Message-Id:To:Date:References:Cc:In-Reply-To:From:Subject; b=qihsjl5yhsmGZbvDAxrknweUOzah/L7sCNoxQi4ySyQzfDHDG/egb9gY0edRLZgjZ icXZpVWGEOwR7ZqnwaOYcIXj7eccUUs3RMBcRC0rK1zo9GmFalqJCkJHF2JrocMsy6 l9l8aJzbOpgnMpY61L7eOJ57R5nFBlT+BdYmOg2Q= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: Sample rate added to pg_stat_statements From: "Andrey M. Borodin" In-Reply-To: Date: Tue, 19 Nov 2024 17:11:55 +0500 Cc: pgsql-hackers Content-Transfer-Encoding: quoted-printable Message-Id: <6707FCA9-FD1A-4609-A1A6-142456C14E0C@yandex-team.ru> References: To: Ilia Evdokimov X-Mailer: Apple Mail (2.3776.700.51) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 18 Nov 2024, at 23:33, Ilia Evdokimov = wrote: >=20 > Hi hackers, >=20 > Under high-load scenarios with a significant number of transactions = per second, pg_stat_statements introduces substantial overhead due to = the collection and storage of statistics. Currently, we are sometimes = forced to disable pg_stat_statements or adjust the size of the = statistics using pg_stat_statements.max, which is not always optimal. = One potential solution to this issue could be query sampling in = pg_stat_statements. >=20 > A similar approach has been implemented in extensions like = auto_explain and pg_store_plans, and it has proven very useful in = high-load systems. However, this approach has its trade-offs, as it = sacrifices statistical accuracy for improved performance. This patch = introduces a new configuration parameter, pg_stat_statements.sample_rate = for the pg_stat_statements extension. The patch provides the ability to = control the sampling of query statistics in pg_stat_statements. >=20 > This patch serves as a proof of concept (POC), and I would like to = hear your thoughts on whether such an approach is viable and applicable. +1 for the idea. I heard a lot of complaints about that pgss is costly. = Most of them were using it wrong though. But at least it could give an = easy way to rule out performance impact of pgss. > On 19 Nov 2024, at 15:09, Ilia Evdokimov = wrote: >=20 > I believe we should also include this check in the pgss_ExecutorEnd() = function because sampling in pgss_ExecutorEnd() ensures that a query not = initially sampled in pgss_ExecutorStart() can still be logged if it = meets the pg_stat_statements.sample_rate criteria. This approach adds = flexibility by allowing critical queries to be captured while = maintaining efficient sampling. Is there a reason why pgss_ProcessUtility is excluded? Best regards, Andrey Borodin.=