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 1uiw3c-000NMl-1V for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Aug 2025 14:20:56 +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 1uiw3a-001dIU-QJ for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Aug 2025 14:20:54 +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 1uiw3a-001dGS-98 for pgsql-hackers@lists.postgresql.org; Mon, 04 Aug 2025 14:20:54 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uiw3X-000hIA-11 for pgsql-hackers@lists.postgresql.org; Mon, 04 Aug 2025 14:20:53 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3b7825e2775so3701500f8f.2 for ; Mon, 04 Aug 2025 07:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754317251; x=1754922051; darn=lists.postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=mq8HJswd39aGj+O1Pj0dk3k8rFXR4+TFkmTGqNl6nl8=; b=VfDluBWOOgx8XNjDSzHsWuWplvF30YYXZmbSbe/n2uPOJKf3X0oaE7WghAF4NW68k1 GfTOY/eaCabxsipswX+aLOiSVjQHRyTXHMXvIB+2HU+VslyFILL09Tz+AYo3gGS/2zGl AylD3lsY2mpKVQIR7H3nw/QM/rw5V9CBmbMq+MfaC4n0hKrY/je4UsENPU/ApN++7F01 9SkG+V7IWkhyTVQ5DFY0ZpD8eutiF6XuDvEZAEX/kehA4bq1vNKxcHCBS9oHMKPlGyaJ YexKo/KNrsSLv+yU/ZGspHavuw+hdl1r0EEGGqP+lLnwtV0jINBZ1b8qLd3eFhId18Js zXng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754317251; x=1754922051; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mq8HJswd39aGj+O1Pj0dk3k8rFXR4+TFkmTGqNl6nl8=; b=Alhnq6Dzlsyljk0DAG6NOoTnYv/GrtXq/AISO9KWVnW7KFjnPw9Isy4PoDzaHZ9Ylc 13V3ZXlrkp/zuAN/fPDgJxM1OcZ1UDOn0rx9tW5q5myBtGkTHHG8mOkFuUXMeC4Fk2kZ Dx54vASkdd8awbHEOjkn0SptBX9sxX6sa4gNO9JQG6y0h+DMYrhFUEYXpXTn8+mEEb7E LIVU7WOnnyUEv69z0iFZqemUbb1Y9RzzmVzc2rVvwJtphf1eyCXgGKBjC3T521zwGd5N b0vmBLRHqZKuNwKP45si86BkyqxSOUdDYvIjYm0QUCcbkkfjNoERyN8hiEfUpAxSAENJ Re+g== X-Gm-Message-State: AOJu0YxcyFrjcrD65dBAZbIIKOl2VSb+4xea3+0HJTjCNDoMPgJk/h4r jSAoop8ENNReQLGFdqFblxh2hw3DvpFdecNCZpEabNxQq7PewKMPVdSlKM0/lQ== X-Gm-Gg: ASbGncsUJFMa7uPi8SF+FW38wbW36wsZllqp/4UXsU5eHpT8Rv4boeimB3VajDqvITO f0kETnfFf4DDa2AMXo7oZWztny1jtOl/Og1wFyHbsHDZ/+ttx/ZGi5QiVbYcaB3bvmyjiTQdXy/ fFFExs85OHVNodLOlnG+P9G6eHeaFlDCoOVFNLjJgY+fG+ESeXFDl3cQHqWVqk6+M6erLYze//C ZPaYZp29xfYqwaZnujbsI55WZXlrc5qgqB8UUbdZWMbo4oUP46uxQ6UN6K7nniZgjRQlFz8RH6t 8SJfkLW78oD/empd+iCngFQ9ni7Dqf/zyBFxs9DOMkJPGDz6GpHlJk8iavA7pEH5Ibgz1FyhKVJ sdRfboMd20SA2RIUiFdCOTEtREhP28Gk6q3jUHVraizI4J9TMWTw9e1/H/7tQd2ki5mB0DiJedd L9oXkDDawAE3b0qBq0nUwBoyPlvuVzNKKThbZl135j5uNdakgF0YnXgQ== X-Google-Smtp-Source: AGHT+IFTFP8ayI5gWPBYSaoHBuslq/34IJyOnCpymKmCgIm7YIMLi5yuld4tzgfpZ50oGoqn7Tp2rQ== X-Received: by 2002:a05:6000:430d:b0:3b7:899c:e867 with SMTP id ffacd0b85a97d-3b8d94d48a4mr6249900f8f.59.1754317250735; Mon, 04 Aug 2025 07:20:50 -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-3b79c4a2187sm16204391f8f.70.2025.08.04.07.20.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Aug 2025 07:20:49 -0700 (PDT) Date: Mon, 4 Aug 2025 14:20:48 +0000 From: Bertrand Drouvot To: PostgreSQL Hackers Subject: Adding per backend commit and rollback counters Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ZnbSmJtA6EgjuGCe" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ZnbSmJtA6EgjuGCe Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi hackers, PFA a patch for $SUBJECT. Currently we can find xact_commit and xact_rollback in pg_stat_database but we don't have this information per backend. This patch adds 2 functions: pg_stat_get_backend_xact_commit() and pg_stat_get_backend_xact_rollback() to report the number of transactions that have been committed/rolled back for a given backend PID. I think having this information per-backend could be useful, for example, to: - check which application is producing the highest number of commit / rollback - check if the application's hosts have "uniform" commit/rollback pattern - check if some application's hosts are doing a lot of rollback (as compared to the other hosts): that could mean those hosts are not using an up-to-date application version 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). On a side note, I noticed that when a transaction fails, say this way: postgres=# insert into bdt2 values(1); ERROR: relation "bdt2" does not exist Then the existing pg_stat_get_db_xact_rollback() does not return the rollback increment (so does pg_stat_database.xact_rollback). Indeed, the flush is done during the next commit or explicit rollback. Maybe we could add an extra counter, that tracks the transactions that have not been explicitly rolled back (xact_error or such) and flush it at the right time. Looking forward to your feedback, Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --ZnbSmJtA6EgjuGCe Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Adding-per-backend-commit-and-rollback-counters.patch"