Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNhvv-0005eY-Uz for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Aug 2022 21:47:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oNhvt-0003wb-Mi for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Aug 2022 21:47:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNhvs-0003wS-Rl for pgsql-hackers@lists.postgresql.org; Mon, 15 Aug 2022 21:47:37 +0000 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNhvn-0001Ji-8t for pgsql-hackers@postgresql.org; Mon, 15 Aug 2022 21:47:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1660600052; x=1692136052; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=ejGXVZZydKKPMLORWt+shoC9sHkn5efmF425PPP66/4=; b=sWdfj3pyE2YnLQuoOHM/bH+I5LRxLuFB0XE5+cEwEfmlkJlKKtZoYxRl 57HjCrhWpHbKBOw/khjXrFjzdLHmPbrl0u9/Kh9H5utC2l7L2TIAuciUG kz2E6XkcGGM61+xhcxD198jSun7FMDfVr1y6uo/pK54jjQGzm8aRjkxHb w=; X-IronPort-AV: E=Sophos;i="5.93,239,1654560000"; d="scan'208";a="218104296" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-41c1ef8b.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2022 21:47:28 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-41c1ef8b.us-east-1.amazon.com (Postfix) with ESMTPS id 70B0F160BC6; Mon, 15 Aug 2022 21:47:26 +0000 (UTC) Received: from EX13D18UWA002.ant.amazon.com (10.43.160.199) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Mon, 15 Aug 2022 21:47:25 +0000 Received: from [10.111.246.40] (10.43.160.55) by EX13D18UWA002.ant.amazon.com (10.43.160.199) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Mon, 15 Aug 2022 21:47:25 +0000 Message-ID: <36e8f3ee-dd29-83e3-7f04-3cdb1737d6a3@amazon.com> Date: Mon, 15 Aug 2022 14:47:25 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 Subject: Re: identifying the backend that owns a temporary schema Content-Language: en-US To: Nathan Bossart , References: <20220815205811.GA250990@nathanxps13> From: Jeremy Schneider In-Reply-To: <20220815205811.GA250990@nathanxps13> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.43.160.55] X-ClientProxiedBy: EX13D23UWA003.ant.amazon.com (10.43.160.194) To EX13D18UWA002.ant.amazon.com (10.43.160.199) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/15/22 1:58 PM, Nathan Bossart wrote: > Hi hackers, > > As Greg Stark noted elsewhere [0], it is presently very difficult to > identify the PID of the session using a temporary schema, which is > particularly unfortunate when a temporary table is putting a cluster in > danger of transaction ID wraparound. I noted [1] that the following query > can be used to identify the PID for a given backend ID: > > SELECT bid, pg_stat_get_backend_pid(bid) AS pid FROM pg_stat_get_backend_idset() bid; > > But on closer inspection, this is just plain wrong. The backend IDs > returned by pg_stat_get_backend_idset() might initially bear some > resemblance to the backend IDs stored in PGPROC, so my suggested query > might work some of the time, but the pg_stat_get_backend_* backend IDs > typically diverge from the PGPROC backend IDs as sessions connect and > disconnect. I didn't review the patch itself yet, but I'd like to chime in with a big "+1" for the idea. I've had several past experiences getting called to help in situations where a database was getting close to wraparound and the culprit was a temp table blocking vacuum. I went down this same trail of pg_stat_get_backend_idset() and I can attest that it did work once or twice, but it didn't work other times. AFAIK, in PostgreSQL today, there's really no way to reliably get the PID of the session holding particular temp tables. (The idea of iterating through backends with gdb and trying to find & dump some obscure data structure seems completely impractical for regular production ops.) I'll take a look at the patch if I can... and I'm hopeful that we're able to move this idea forward and get this little gap in PG filled once and for all! -Jeremy -- Jeremy Schneider Database Engineer Amazon Web Services