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.98.2) (envelope-from ) id 1x9bzY-000000027uw-37nW for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Sep 2026 05:27:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x9bzY-00000009Wzt-06In for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Sep 2026 05:27:32 +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.98.2) (envelope-from ) id 1x9bzX-00000009Wzk-38Sv for pgsql-hackers@lists.postgresql.org; Thu, 24 Sep 2026 05:27:31 +0000 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x9bzV-00000000ySW-0PD3 for pgsql-hackers@lists.postgresql.org; Thu, 24 Sep 2026 05:27:30 +0000 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49e7bcb94d3so11242535e9.2 for ; Wed, 23 Sep 2026 22:27:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790227648; x=1790832448; darn=lists.postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=AorAGiGhVArE3nQ+yEADLjVLSzzuQJEK/Lhii/K5vws=; b=eAogrgvCOOSJKjGCy6e5ZWW4qv7pYMXQNkxbf5aORG02kBmMTbhkPNxIAAtFdycHqi GabfcQrTU5u17Tn1y56jTEgaJLRfW03wJ9M4zEbgAGdBtQHrRm6OCPNVwGnPIvdkszzF +Uh9VzlnohZnMBP5ED+zvGSfeE15bRI1h6nhie5kKTqWmYBn0c02/1XshBp6fY2QDiPB NIFT7Uld/iwg6gTXB+X9FRA2dMuDV3T6jwqmZD0pfE5liBV4Qyk5WW8b3Up0spaKkGRR 8kq8VqtsSQkQZ+FkDfqpauJgazw8n/Yc/UfcM+79VNVcWesrMO1R/GZzG2mdYU5veYFT 3nCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790227648; x=1790832448; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AorAGiGhVArE3nQ+yEADLjVLSzzuQJEK/Lhii/K5vws=; b=26pCFX6KsApZ5SIKSM9e8yyulYNZn7Hd2elbCL2cCU4GXSPRlwdcolg0+7zJBeXfax Bkj3txfbpqRFxUhnkT1XTkGoHKQ3R7d7O1oclPb6s++Bz9y332n2Q8gGM+2nsbYBjqAx xTDFArIrc/33Smma+PIXC9qeJTcdx77h6TXEnIIozdwGXxCZZ98jy4Vanpan7zocLaor avBj9y3jQFSL0IBztBlJqKse2H03H1lpQK9H9RMJ+hM/8zuq1yJXEemIPZm0HLHNTsB1 QqF9duUxXgSEHZv1gz4A9CcFsxmaXqkKjTdzt8E0Nbmye1CaijZZKBwmjASxppyR1pog NEYA== X-Forwarded-Encrypted: i=1; AKwUvByzjjKrVHBTyH8WTzyzZN+/IJohTcHntNzUtJ1aP+PmV8Xp8lsRAiSwVFUYZKotl7zXdeJ5bfV3/yL58NyF@lists.postgresql.org X-Gm-Message-State: AFuF++nIeN5utWemTiJq5O7h6q9YYc68pPajlJojXN4RmTeMlDte0uCD sRT2+nv2vJFeOPFHq9hP1RDNCJJbSUpc5a9KOyWQ3e22ckkoAGNYPIXk X-Gm-Gg: AYBFou1xaWpJbhSYoKYY0qvDe2YtmB1UoQL82qoqrI73YIZfOElyvX7sW/Yws6SoE/7 iyXhM1anQ7SK82MoUBHU4AvoQS/LuqszjOqp1AvvzD5qpZiozXXB/QKEL/NFaF4mvMNmW+gNfOi qp+uziHvanaNQYmxwavpEibGvVpjhDTSX3TgQ3EuXUZdNscZmcQcnSfwRxLR82j/Gas0NxWzGUc BiFNKU43aimZlKc1avDgsu1wIixr9mtPzvVCMd5xHVV5lzrVNyVJWoDCUCPOo5GJsRG/w0qijL/ CiE/P5KwX/dmlUo2QiTf2/EGOm7LCi9VrU77tcI+QCv+8IasUWZnqxhDMgbw+T1e4IPtFL2bdzz JaCOb/zeaRoa0AkEBhjsnkZoZHeXOuZDSGGWmHQBVMkzMmL4u8ec2rlH5EshY2TljeXka2Ghu/7 02NzHDsUdG8pz0ve4Xedfyee6nh27aOq0ZBhfTzDZcPbLWzS/OjrYXrceAS0bE1rX4/vUc8IF9O mttvb9Xs10KnLm8vlFMJV8Xn+XQQt7eaqBihGPII1mZWhpjXBxINM1qOsY= X-Received: by 2002:a05:600c:34c6:b0:49e:7cff:f8ca with SMTP id 5b1f17b1804b1-49fe66f4dc9mr21067065e9.29.1790227648087; Wed, 23 Sep 2026 22:27:28 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe5de4de4sm40350035e9.8.2026.09.23.22.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 22:27:27 -0700 (PDT) Date: Thu, 24 Sep 2026 05:27:26 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: shihao zhong , Jim Jones , pgsql-hackers Subject: Re: Add a permission check to pg_stat_get_backend_subxact() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, Sep 24, 2026 at 10:01:02AM +0900, Michael Paquier wrote: > On Wed, Sep 23, 2026 at 07:23:01AM +0000, Bertrand Drouvot wrote: > > typedef struct PgStat_Backend > > { > > + int pid; /* PID of the backend owning these stats */ > > TimestampTz stat_reset_timestamp; > > > > 0002 explicitly says that it is not intended for backpatching, but what about > > 0001? If it is backpatched to v18, adding pid here changes the offsets of all > > the existing fields. > > The main use case of > backend stats is for benchmarking and get numbers with longer-running > connections, so as a whole I think that we are making a big issue of > something that is not really one in practice. I'm not sure I agree with that assumption. Per-backend statistics can also be used for monitoring and diagnostics, including with high connection turnover. That said, I agree that ProcNumber reuse while statistics are held should be rare in practice. > Note that there is a parallel with replication slot stats, which are > indexed not by name but with an integer number. A backend could grab > in a snapshot data from slot 1, while concurrent activity has the idea > to drop and recreate a slot. The snapshot would still refer to the > data of the previous slot. If we aim at improving this kind of use > cases with stats snapshots, and I am not sure that it's really worth > bothering, this should work across all the stats kinds, not be plugged > multiple times across the board. Your replication slot point makes sense. If we want to address those, a generic approach would probably be better than special handling for backend statistics. Storing the user ID with the statistics is enough for the permission check, so dropping the PID from v10-0001 makes sense to me. Maybe worth adding a comment to pgstat_fetch_stat_backend_by_pid() mentioning that cached statistics may belong to an older backend that used the same ProcNumber, to avoid this being rediscovered later? (If so, I'll draft such a patch). > The role ID case is different: we want consistency to check for the > permissions. Agreed. What about v10-0002? I think this is different. pgstat_read_current_status() is constructing one activity snapshot entry from the activity entry and PGPROC. Without the cross check, it may combine the PID and user ID of one backend with the subxact counters of another one. Is the PID check there worth keeping for HEAD? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com