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.96) (envelope-from ) id 1vwixo-008vsY-0A for pgsql-hackers@arkaria.postgresql.org; Sun, 01 Mar 2026 15:44:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vwixm-00Dr4h-2b for pgsql-hackers@arkaria.postgresql.org; Sun, 01 Mar 2026 15:44:10 +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.96) (envelope-from ) id 1vwixm-00Dr4Y-1h for pgsql-hackers@lists.postgresql.org; Sun, 01 Mar 2026 15:44:10 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vwixj-00000001tI4-0K1b for pgsql-hackers@lists.postgresql.org; Sun, 01 Mar 2026 15:44:09 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-b9373af81cdso435231366b.2 for ; Sun, 01 Mar 2026 07:44:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772379846; cv=none; d=google.com; s=arc-20240605; b=lRhUpb1UrxLG1tsEyBPY/ymPjDQ49nsICxzRvSl6Kv9yDCg1srz56c3281hzKKOBm5 MY//YMpVgIW17WMZrAfJ9qOSMzHzEOLeGHjQXFZqe/fw3pU1fZnvENAkc7t8gtTfOvd0 mwrVD/Q4KobGkKg1wSIrmeUC2H+W8gVMLU/qigGKKxFNvPxC9aQTbNMKHClqnDKkU6cj UScCDfpIq/TVWnalRnIPQihZogM9U3Y/gh5EtjDP1QkptILHJpSQGMmfielN/aKIr3FM 1ADhEzJZnV4Al4ZX1CRvJwigq3vIf+QTHlP4xNNVpzaeKn/1t+qF9NOA8XajdhE756SB SH2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=YaJEY1BWuf/3PpWjVvX2psAnJyogbO05XKh8OEkD8GI=; fh=Dvi8OJWljtokaLTuKEL4b86jrkDCm/ML/42DEqJzcRo=; b=P23qBuJqCp6UEe2V1LwAwhyFnvOl6TtwTbVFr6RDU/sV+weRPNQ6MmtohSiSAWucxz rUapefCvH1pl2cpqGTzTkNm1fmruoYpSoBh3r1V+AgSqjVweXtJH1E53wGyiZxXqRg2N iznTeJ60a9rH+O//ndDNT0tLgRh1BwYfpb7fAhzcnED5qB8HlOIt8nZYYrbwq/kDZ228 idU1FkRhxfNIzFlsuVBxP3teQc/XqU0fAUEjj2cQpB5Sh15A5XjoduEPK7qMl3+pqSxF UW2wJnaA1vv8dNEpA67RyRFLDOkYSmUZJpj8k6WITOERx7PsaqbIHpHl2mbADziWHpEU Vq4w==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772379846; x=1772984646; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YaJEY1BWuf/3PpWjVvX2psAnJyogbO05XKh8OEkD8GI=; b=NgQAj1Lme3semPakdAH4Wk88CA63CKO+c7W+fuYxGH+zNfxFc5u1uSx0MFdhzpxOIE Gt3+4iExLPrWy/rhMQWtSp7c01zAwfMpkk4dNYaKhaFh72a/e99doIUvVe0PR36jQVpi 6F24UIAkRrGGk0XUBVmKftN5wehKgqkgS1TFCSMTGG7GI4TxTZJMn4plwj3KSAWfYy84 gs5RNki9MzRMnNwfoEEr4djQcKQUwlyx/HtV53ooFwWogs/2/ltHYes3716w0iZahg8b NDdQ5U/+oAo3NtBUlVhtcXAVYUAVI22W6bYvIKHNmIqp/GMuV0DrdUedSRdAVDRKo+rQ 2l0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772379846; x=1772984646; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YaJEY1BWuf/3PpWjVvX2psAnJyogbO05XKh8OEkD8GI=; b=FCSF2mUZN9zMRhB9fszVD6LO5aa15nadxLd8AgiFQy3IH2RE+2NFFFM5UTPgWxyH/y G5Qxemvld8CmzAj1fI+j/+S/2rvN+yPO2SoLC5yvXCpxETur+qBLm36JL2LEq37WwS/B luF0Dx1PhGOEuX1T+ld3K1wZgCVfK1Mo//mFh8gEmkfWdu+8Runo9VbYLEhPpA50Mcs/ iwvOiG1EPix0KkdnF3PsenvU0CjROqxC04igMidpLEnAz0p7TLM4UEX017io0/xoufix 73GcBd3Ozd2nDr2B2tfXGFcCwadJ98CA5ekKqKILuMal35ZIgrWS8GW3VWQ10L8sOhdU AuKQ== X-Gm-Message-State: AOJu0Yz29V0e8FE8shOxOwNL0Pa7jSK5WE026HCwVPRBwXpyTNYkwIW7 aIACIKipPKBNDznVqodqA6Ti1YyOC0TKXSyVaBtwcNJ1t7EO52a4jJ/w6HQ61e4bBJ9QI8cLSBp +IF6d2LGOoh6n+URlRAubTkO7moyVwwo= X-Gm-Gg: ATEYQzwxoN2d+sy764z0BPFTFwcjTgTuZsUoZSWUCctPPiSyQPtJmvn4nPnnfbgww7x 1xpewO+JuIEfBbsS8CX0NKFUe60vOd34WGcH82NiRQ6igwbkqfTfdBO7Fbg2IM+DvU/d218Sg3t w5WM8F/1lMISLcXucScthstyFDqgidsaklIrMvE56TlX+2nel60tnU1tjx3pTlATla5qDbHmdce 0uK9pdG2YXqfZvSWPb3sRkvsikLDPuNJyttdi490BKKTJIk0l79s5H+6pUspQJeIZBVAI6rRbq8 wmduYA== X-Received: by 2002:a17:906:d92a:b0:b83:95c7:f87b with SMTP id a640c23a62f3a-b9376523912mr425486766b.37.1772379845975; Sun, 01 Mar 2026 07:44:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Sun, 1 Mar 2026 09:43:54 -0600 X-Gm-Features: AaiRm51oGwNfEmWDtLw2yy_bICNv80LPupwOMlv88g7KJJHov2rH92M1h_NKShc Message-ID: Subject: Re: pg_stat_statements: Add gc_count and query_file_size to pgss_info To: Lukas Fittl Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > Hi, > > Over the last weeks we've been fighting again with pg_stat_statements > issues, specifically with the issue of having too many unique entries, > and the corresponding problem of large query text files and LWLock > wait events related to pg_stat_statements. Yeah, LWLock:pg_stat_statements related to garbage collection can be really bad when large files must be recreated with live query texts, or if this GC must occur often (in the case of high query entry churn). A high dealloc count is already a good indicator of the need for GC, but most people, in my experience, do not realize there is a GC process, since it is not documented or exposed. A high dealloc is already a good indicator of the need for gc, but most people, in my experience, don't realize there is a gc process, since it's not documented and not exposed. > I think we can improve debugging for such situations by adding two > more columns to pg_stat_statements_info that expose information > already tracked: > > 1) "gc_count", showing when the pg_stat_statements query garbage > collection cycles occur (which can correlate with > LWLock:pg_stat_statements) > > 2) "query_file_size" which tells us the extent of the query text file, > so we can fine-tune when we query the texts from pg_stat_statements in > monitoring scripts (i.e. query it less frequently if the query text > file is very large). I do agree that having such additional information, with proper documentation, is a good idea. However, I do wonder if we should hold off on adding any of this info in 19 because of the point you make below, which could completely change the information we need to expose. Adding this information in 19 and then removing it for 20 may not be worthwhile. > I've had a patch to improve this prepared for a previous cycle, but > wasn't sure it was still needed because of the discussion re: keeping > query texts in shared memory. But since it looks like that won't > change for 19 (though I'm hoping to contribute more to improving that > in the PG 20 cycle), see attached for consideration. 19 has 4ba012a8ed, which allows us to serialize and deserialize query texts stored in, for example, DSA, with a dsa_pointer tracked by the entry of a custom stats kind. I was also planning on continuing this work for 20, and getting 4ba012a8ed was an important prerequisite for this. What do you think? [1] [https://www.postgresql.org/message-id/CAA5RZ0s9SDOu+Z6veoJCHWk+kDeTktAtC-KY9fQ9Z6BJdDUirQ@mail.gmail.com] -- Sami Imseih Amazon Web Services (AWS)