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 1sxkRh-00C73i-C9 for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Oct 2024 09:54:29 +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 1sxkRg-0093f3-1U for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Oct 2024 09:54:28 +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 1sxkRf-0093ev-NU for pgsql-hackers@lists.postgresql.org; Mon, 07 Oct 2024 09:54:27 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sxkRc-002w1v-V1 for pgsql-hackers@lists.postgresql.org; Mon, 07 Oct 2024 09:54:26 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42cc43454d5so32466715e9.3 for ; Mon, 07 Oct 2024 02:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728294863; x=1728899663; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pTyN/nR7wt8Js7VYUgIfFqZ0kd6uZ618FkVpkvAlhRY=; b=Y+dHA//R+e5s7tzvX4y9oIIDMD/WfeOZtSiN4zVBXOL9dHYKsEWdrYQVUxdc7mD1Jd U2qGRVjaFaVjeQdWWon10gxIwp4lp5Sp5GCV1/l6Um3n9tWR6h7wVuavR6E8eiFyZHw5 7ZZqumrVFjgE1nHqWlkovh0qfbIc0q7UMq22pktdFusnGA8/l7QmvP47qEihwhB/Xbl4 b+xXnJw+g5qR512GLGBZ+oh2p9nDMZbfGu7syA6wiO7+yLKkvzvtTVYCYInubGEdMooD d08Ku6kU9uQqaBl26pH63yc00X5lUH0vFMczTGgQNOm6tog+gjhsYoCmbUVk+q3ojgyo ovXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728294863; x=1728899663; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pTyN/nR7wt8Js7VYUgIfFqZ0kd6uZ618FkVpkvAlhRY=; b=QZsO5xwZjXKtl9/o+WZJ6AhsSE+UhI7zHKXVnCn4PYIVwdJ1FXaoMIFadIKsE5h21P il96Ner3FflMCcL5W9zDG1PUZHt6DHw44jQwOiKDO01poKlSJbKn5Pc2xO+fA+Woqe2Z DpJMKXRkRN5U6bMPNdyo61vkBJLQ+mc8ji3YXqub8XEhcTNq+ilZE2uMJ/0PWqR+tlc4 6sIJIgmR5FwUB4X/NAWXJEjdukVU3DeJxL7y9Eui/T7RsRKmugYyFRsCJEU7nbQC1v6T M78o7LlvD4Q8kQPdCaZPtHM7wyc14FPmKwNqBKujrHFlcUSz3XzUgfFyTcCXhpx1HOf7 pKwA== X-Forwarded-Encrypted: i=1; AJvYcCWmvd8X4wgnWnBG7ulAwg0Y+FUftVAwIz0pjegjq40cmSNE1r/TzF06ERqDYQHug3hmXOI3WgdbmnXqEmiC@lists.postgresql.org X-Gm-Message-State: AOJu0YwySfiYU4CtAUGJoAkPT2zp6FlDiOU1H5seYfUk2f6mJ7FNuCDM daR/bX0VFR1vmB/2U61zgCuY4teY5vBMz3mdD11twMzPcJCPxAgP X-Google-Smtp-Source: AGHT+IEKfcL17YpZutNgkK2PYW4DVA/1OVGy5jr/imfu3ZVcsdVz9+0xICzSOBjk41aug++dBzMh/g== X-Received: by 2002:a05:600c:3106:b0:426:6876:83bb with SMTP id 5b1f17b1804b1-42f85abeb0cmr79867675e9.17.1728294863497; Mon, 07 Oct 2024 02:54:23 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d16920be2sm5340544f8f.60.2024.10.07.02.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2024 02:54:23 -0700 (PDT) Date: Mon, 7 Oct 2024 09:54:21 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: Nazir Bilal Yavuz , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: per backend I/O statistics Message-ID: References: <202409051303.qumelxccgzzn@alvherre.pgsql> 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 Fri, Sep 20, 2024 at 01:26:49PM +0900, Michael Paquier wrote: > On Tue, Sep 17, 2024 at 01:56:34PM +0000, Bertrand Drouvot wrote: > > No problem at all! (I re-explained because I'm not always 100% sure that my > > explanations are crystal clear ;-) ) > > We've discussed a bit this patch offline, but after studying the patch > I doubt that this part is a good idea: > > + /* has to be at the end due to FLEXIBLE_ARRAY_MEMBER */ > + PgStatShared_IO io; > } PgStat_ShmemControl; > > We are going to be in trouble if we introduce a second member in this > routine that has a FLEXIBLE_ARRAY_MEMBER, because PgStat_ShmemControl > relies on the fact that all its members after deterministic offset > positions in this structure. Agree that it would be an issue should we have to add a new FLEXIBLE_ARRAY_MEMBER. > So this lacks flexibility. This choice > is caused by the fact that we don't exactly know the number of > backends because that's controlled by the PGC_POSTMASTER GUC > max_connections so the size of the structure would be undefined. Right. > There is a parallel with replication slot statistics here, where we > save the replication slot data in the dshash based on their index > number in shmem. Hence, wouldn't it be better to do like replication > slot stats, where we use the dshash and a key based on the procnum of > each backend or auxiliary process (ProcNumber in procnumber.h)? If at > restart max_connections is lower than what was previously used, we > could discard entries that would not fit anymore into the charts. > This is probably not something that happens often, so I'm not really > worried about forcing the removal of these stats depending on how the > upper-bound of ProcNumber evolves. Yeah, I'll look at implementing the dshash based on their procnum and see where it goes. > So, using a new kind of ID and making this kind variable-numbered may > ease the implementation quite a bit, while avoiding any extensibility > issues with the shmem portion of the patch if these are > fixed-numbered. Agree. > This would rely on the fact that we would use the ProcNumber for the > dshash key, and this information is not provided in pg_stat_activity. > Perhaps we should add this information in pg_stat_activity so as it > would be easily possible to do joins with a SQL function that returns > a SRF with all the stats associated with a given connection slot > (auxiliary or backend process)? I'm not sure that's needed. What has been done in the previous versions is to get the stats based on the pid (see pg_stat_get_backend_io()) where the procnumber is retrieved with something like GetNumberFromPGProc(BackendPidGetProc(pid)). Do you see an issue with that approach? > The active PIDs of the live sessions are not stored in the active > stats, why not? That was not needed. We can still retrieve the stats based on the pid thanks to something like GetNumberFromPGProc(BackendPidGetProc(pid)) without having to actually store the pid in the stats. I think that's fine because the pid only matters at "display" time (pg_stat_get_backend_io()). Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com