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 1qZ08t-003WZB-FT for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Aug 2023 02:32:15 +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 1qZ08s-003A21-BV for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Aug 2023 02:32:14 +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 1qZ08s-003A1i-18 for pgsql-hackers@lists.postgresql.org; Thu, 24 Aug 2023 02:32:13 +0000 Received: from mail-yw1-x1133.google.com ([2607:f8b0:4864:20::1133]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qZ08o-000dKC-Lb for pgsql-hackers@postgresql.org; Thu, 24 Aug 2023 02:32:12 +0000 Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-58fc4d319d2so49029087b3.1 for ; Wed, 23 Aug 2023 19:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692844330; x=1693449130; 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=ESWSv3OFqJAlKIgJiVoxJQeVPW6jcWfA5oCRm0ytZMY=; b=GXs513efnoFzhJme6MHQD70t2M9D8A4GZHBoFVs+cUfJFQyoNapvCjWwZoS2CNVJ8/ avS/PWyiPFChKM9a69mgkSJUVhymvd1BVqMtspoddOsoTqwPTlk2rdGUHHYDpFWUuv97 +W87+/oV67qbbG6YokMKe2jaNTfHg48lu/wD0imcNpzn3/rBDvVzxx/vdtM4fRBFQltP wERZl6JUfx7KyZvknFXvYG/aDZ3krSVaYoKQWyPub7G67+J9MGsVBQiyxnntLRBLzb9E vgN9tdLhBk5KDOaBL4fANMVEB/fH4mXd12kOx/RxtzfyJN5OBFe6KqjhQQqVIdCMFWR1 a6Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692844330; x=1693449130; 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=ESWSv3OFqJAlKIgJiVoxJQeVPW6jcWfA5oCRm0ytZMY=; b=Dhdeu8L6haW7CpkltEyNVJxTo2xbMXcdO9QDjn3vjwqbFPP5GcCk0Z9GzVORN1TjDd 0j2SX1+tfO3WihPtorOn1R0su+uyIveiuZPsFxFaUw2qukJhO7e6EGd29ehU0R5yhgL+ qIDh3WQrhsCtu4wNu6otoRN2r/1iIo69ovvTis0tB7YNl9+7rFszdO98SRgL47YFqvPU 5nuRkwQhCHi8+qi4zNLsoNt8KT/ze+pxBXmw0CrezeT1wKEejoiNb3vT0hWXVUm7TjMt EUmfNf7Sxp3DxYpQx5ZYuxyMDrKCq/Ted0xdPwbwGEZ7NhI1m170l8LTeW5Y1JM75mZi uYrQ== X-Gm-Message-State: AOJu0Yz94jyxnn695lsMmfOHQCld0nPkfnngfBwzKI88ALb84LKRS4Vt aXJ2CrJjLEhcSnj400qTGpI= X-Google-Smtp-Source: AGHT+IGGqqRNoUNJM1Fth+7dI5wT0PXenqsl0tZXf708YJVRHD48QxYkTDJVX4jHvFQoMZ09Fn5G5A== X-Received: by 2002:a0d:cb02:0:b0:589:f4ec:4d51 with SMTP id n2-20020a0dcb02000000b00589f4ec4d51mr14424650ywd.3.1692844329756; Wed, 23 Aug 2023 19:32:09 -0700 (PDT) Received: from nathanxps13.lan ([2600:6c42:7af0:90e0:b566:b514:3899:b807]) by smtp.gmail.com with ESMTPSA id d9-20020a81ab49000000b005925c896bc3sm851101ywk.53.2023.08.23.19.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 19:32:09 -0700 (PDT) Date: Wed, 23 Aug 2023 19:32:06 -0700 From: Nathan Bossart To: Ian Lawrence Barwick Cc: pgsql-hackers Subject: Re: pg_stat_get_backend_subxact() and backend IDs? Message-ID: <20230824023206.GA1128857@nathanxps13.lan> 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 On Thu, Aug 24, 2023 at 10:22:49AM +0900, Ian Lawrence Barwick wrote: > Looking at the code, this is happening because > "pgstat_fetch_stat_local_beentry()" > expects to be passed the backend ID as an integer representing a 1-based index > referring to "localBackendStatusTable", but "pg_stat_get_backend_subxact()" > is presumably intended to take the actual BackendId , as per other > "pg_stat_get_XXX()" > functions. Yes, this was changed in d7e39d7, but 10ea0f9 seems to have missed the memo. > Assuming I am not misunderstanding something here (always a > possibility, apologies > in advance if this is merely noise), what is actually needed is a function which > accepts a BackendId (as per "pgstat_fetch_stat_beentry()"), but returns a > LocalPgBackendStatus (as per "pgstat_fetch_stat_local_beentry()") like the > attached, clumsily named "pgstat_fetch_stat_backend_local_beentry()". I think you are right. The relevant information is only available in LocalPgBackendStatus, but there's presently no helper function for obtaining the "local" status with the BackendId. > +LocalPgBackendStatus * > +pgstat_fetch_stat_backend_local_beentry(BackendId beid) > +{ > + LocalPgBackendStatus key; > + > + pgstat_read_current_status(); > + > + /* > + * Since the localBackendStatusTable is in order by backend_id, we can use > + * bsearch() to search it efficiently. > + */ > + key.backend_id = beid; > + > + return (LocalPgBackendStatus *) bsearch(&key, localBackendStatusTable, > + localNumBackends, > + sizeof(LocalPgBackendStatus), > + cmp_lbestatus); > +} We could probably modify pgstat_fetch_stat_beentry() to use this new function. I suspect we'll want to work on the naming, too. Maybe we could name them pg_stat_fetch_local_beentry_by_index() and pg_stat_fetch_local_beentry_by_backendid(). -- Nathan Bossart Amazon Web Services: https://aws.amazon.com