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 1ul0m0-009oMg-Bd for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Aug 2025 07:47: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 1ul0lx-006fSy-OX for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Aug 2025 07:47:17 +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 1ul0lx-006fSp-6r for pgsql-hackers@lists.postgresql.org; Sun, 10 Aug 2025 07:47:17 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ul0lt-001glm-0I for pgsql-hackers@lists.postgresql.org; Sun, 10 Aug 2025 07:47:15 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3b78d337dd9so2055694f8f.3 for ; Sun, 10 Aug 2025 00:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754812032; x=1755416832; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=qp4aZq/8edOBCyKWlcNCCSu+t7CnGB05CyIa/qnC+GI=; b=BKZOe3MyWOrpcrVu/OAtReRfYXC4MGpQu7V7uFoLxiCNFYNZilgT7NL1NOZFT0X8aY hYtHWHpFv/ovoMXIJAwsx0j1U7sE6xqLQYFkC0SjiVBn7Wisah6QORagAdlZfQuIJMLW FqamKf02cNYGFBIANa++0odHeHszOBrQsKbOjqRPKS2+hkFRYqPThoHq3Ciq/FGxpcGZ igCUaEudR9BbQey+z8vnoKZ+DO46GHGrljy00WFNFw1GjQOFocFNKNPkftZ/0oLPlWV/ H6RB8liQFLao3nCN0TpK1E0r82+kKzALRhNA/rXPq9YLORcIVTMv2LqTVQ/te3VPYLWt fWPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754812032; x=1755416832; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qp4aZq/8edOBCyKWlcNCCSu+t7CnGB05CyIa/qnC+GI=; b=G6n5p/En8ZaedonelwjFzeF2qbPsbOfXNU67s99K+IiJXoHC5R2XAWvf26WpH/trGw qSGeIvYk3Nww8MnS0gn1244Qa7pctXtTYIshujUO6bYbmBMbCK/lXHLQh8D6RRLCjhbt Jzle15vPKCy1U6hMBX/CzD25Ct7kxcljus1uBqxZeaX2NyIP2Red89gHzaZEj+6S9FJW ad/ugXhNag37pXsylpSWrO4wjmp0hGr6mkNT4hKldu31dCY8ygC5fTOxJGHB14ZjJk3F cwKE74jyEa1MzR7HbUwbWlH6rN9JYrvHWy7ucu0kYeOF1apXJAW8dBv75KEa9poJ2ZHl mcDA== X-Gm-Message-State: AOJu0YySsjHYBL1o5ViAhHbYar2Jwc8SIW4EXAcgpj44PgmeOLsS+mQc 1/5i1u9FpAl0jDf6C3UBj5vLqLvtAeIRpQO0PJBvcve1F0aVSj2/XeK4sRnVGQ== X-Gm-Gg: ASbGncvHI7EipwV9minStbR80+nl0FF+c26xd404l+mnrZXzT6lbM5xEd2KtVtiW85i NGHntnC0bYDAOfUSD9sSnQaJLz6omrB//nj6wK+QNAIfO+uJNqz+xCasAqUH0uT+hopz4Ebr88z BkM+YLMU8ElK3iLfLjm14VJ+omslRsxhNQ+hWimH9cyLugZX7RglLsVuTMhBL98mzQvp45haFcl L7SMUcZjjpxpGiwRApFpxtRodG/hlFsrPKtlx4z+Eq946VKwyghn9vt8JrHI+DH4Pk83+V/KiK1 gLgK4VcmDMQ6AV7znA/PVuLL+yW55zYRs99Vd4i4zktIebg0j0bGgFFSHXpVkQujBnGpjWDm5sw 8Xr97ms671tzC58q0cz5j5mJ/yhP8fc/dyJcmFIOc0+BkbVY/IoATJmt2/jT1Ds2Ou6ufEsMRzm UccmAPU18cNtxLJYDnEcgrHWGcScesXhJvsLYxot71OPFnL261oeB1iA== X-Google-Smtp-Source: AGHT+IH++T2Mp4/tep6FN11+RuExnMEKkm956omon2+NSzNimNoFZ7D1kNIPjt/pNAUoDggj3XkHFQ== X-Received: by 2002:a05:6000:240c:b0:3b7:8e91:fd7e with SMTP id ffacd0b85a97d-3b900b5514dmr7440515f8f.49.1754812032128; Sun, 10 Aug 2025 00:47:12 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-181-182.eu-west-3.compute.amazonaws.com. [15.237.181.182]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3c4d02sm35363685f8f.33.2025.08.10.00.47.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Aug 2025 00:47:11 -0700 (PDT) Date: Sun, 10 Aug 2025 07:47:09 +0000 From: Bertrand Drouvot To: PostgreSQL Hackers Subject: Re: Adding per backend commit and rollback counters Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="u6+Li7FU79Mt/lVd" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --u6+Li7FU79Mt/lVd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Thu, Aug 07, 2025 at 08:17:26AM +0000, Bertrand Drouvot wrote: > Hi, > > On Mon, Aug 04, 2025 at 02:20:48PM +0000, Bertrand Drouvot wrote: > > This patch is pretty straightforward as it relies on the existing per backend > > statistics machinery that has been added in 9aea73fc61d (so that there is not > > that much design to discuss). > > Still, while working on adding more backend stats (more on that later), I > realized that in v1, I missed to use pgstat_report_fixed (recently added in > 793928c2d5a): the attached fixes that. > > Also, I think it's better to put the new xact pending counters in the existing > PgStat_BackendPending, done that way in the attached. Another metric that could be useful is to track the XIDs generated by backend. That would help to see if a backend is consuming XIDs at a high rate. We can not rely on the number of commits or rollbacks as they take into account the virtual transactions. So a new counter has been added in 0002 attached. Also, v3 changes the way the statistics are displayed. I've in mind to add much more statistics per backend (such a number of seqscans, vacuum count, analyze count..., I'll open a dedicated thread for those) and I think that a single view to display them all makes more sense than a lot of individual functions. This view is added in 0003. To sum up, v3 contains: 0001 - Adding per backend commit and rollback counters It relies on the existing per backend statistics that has been added in 9aea73fc61d. A new function is called in AtEOXact_PgStat() to increment those two new counters. 0002 - Adding XID generation count per backend This patch adds a new counter to record the number of XIDs generated per backend. It will help to detect if a backend is consuming XIDs at a high rate. Virtual transactions are not taken into account on purpose, we do want to track only the XID where there is a risk of wraparound. The counter is not part of PgStat_BackendPending, because we want to avoid an extra function call in this code path to increment the counter in PendingBackendStats. The counter increment here behaves more or less the same as we do for WAL statistics. 0003 - Adding the pg_stat_backend view This view displays one row per server process, showing statistics related to the current activity of that process. It currently displays the pid, the number of XIDs generated, the number of commits, the number of rollbacks and the time at which these statistics were last reset. It's built on top of a new function (pg_stat_get_backend_statistics()). The idea is the same as pg_stat_activity and pg_stat_get_activity(). Adding documentation and tests. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --u6+Li7FU79Mt/lVd Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-Adding-per-backend-commit-and-rollback-counters.patch"