Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYBI2-0007sW-RC for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Dec 2018 14:51:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYBI1-0000xO-F4 for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Dec 2018 14:51:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYBI1-0000xH-7r for pgsql-hackers@lists.postgresql.org; Sat, 15 Dec 2018 14:51:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYBHz-00017B-7I for pgsql-hackers@lists.postgresql.org; Sat, 15 Dec 2018 14:51:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBFEpV4V023466; Sat, 15 Dec 2018 09:51:31 -0500 From: Tom Lane To: Alvaro Herrera cc: Michael Paquier , Robert Haas , PostgreSQL Hackers Subject: Re: removal of dangling temp tables In-reply-to: <20181215132116.5v25mjgyy7y77pzw@alvherre.pgsql> References: <20181215132116.5v25mjgyy7y77pzw@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Sat, 15 Dec 2018 10:21:16 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23464.1544885491.1@sss.pgh.pa.us> Date: Sat, 15 Dec 2018 09:51:31 -0500 Message-ID: <23465.1544885491@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > On 2018-Dec-15, Michael Paquier wrote: >> Isn't that what tempNamespaceId can be used for in PGPROC now? The flag >> would be set only when a backend creates a new temporary schema so as it >> can be tracked as the owner of the schema. > Oh, we already have it! Sorry, I overlooked it. With that, it seems > the patch is fairly simple ... I wonder about the locking implications > in autovacuum, though -- the value is set in backends without acquiring > a lock. I was wondering about that too. But I think it's probably OK. If autovacuum observes that (a) a table is old enough to pose a wraparound hazard and (b) its putatively owning backend hasn't yet set tempNamespaceId, then I think it's safe to conclude that that table is removable, despite the theoretical race condition. Autovacuum would need to acquire a deletion lock and then check that the table is still there, to avoid race conditions if the backend starts to clean out the schema immediately after it looks. But I think those race conditions exist anyway (consider a fresh backend that starts cleaning out its temp schema immediately), so if we have a problem with concurrent deletion attempts then that problem exists already. > I wonder how this thing works in parallel query workers. Surely workers are not allowed to create or delete temp tables. regards, tom lane