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 1oBGdq-0005p4-Ld for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Jul 2022 14:13:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oBGdp-0007K7-7b for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Jul 2022 14:13:33 +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 1oBGdo-0007I8-Ph for pgsql-bugs@lists.postgresql.org; Tue, 12 Jul 2022 14:13:32 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oBGdm-0001gI-JM for pgsql-bugs@lists.postgresql.org; Tue, 12 Jul 2022 14:13:32 +0000 Received: from falcon-note (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id EA3ED21C0BE2; Tue, 12 Jul 2022 17:13:28 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1657635209; bh=afMGWtxICXMf0wkyT0f2hHyH6GjT5hYalBiIKCcc3ts=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=BEZoA79aBEN+8Nh1A5E73Oyl7rG52LGxHZ365UutKuHtjQxEfyPZa3Legw3NcObRL LLvng/bzXFOZyaIAiRaiK7FA7jsWNo+mFt3Xaij1PQlUGyjuO7wYqEW0gZyHK95N7i Y5hxDx0b4Qodh8Wvy14rXgqTKciwWmouG6A823Q4= Message-ID: <24a26615b66d84abf2083a10ff1ca59933a7b4e2.camel@postgrespro.ru> Subject: Re: can't drop table due to reference from orphaned temp function From: Yura Sokolov To: Andres Freund , Miles Delahunty , Tom Lane Cc: pgsql-bugs@lists.postgresql.org, Robert Haas Date: Tue, 12 Jul 2022 17:13:28 +0300 In-Reply-To: <20220219213139.2gpsrqwp7hlmn634@alap3.anarazel.de> References: <20220219180002.6tubjq7iw7m52bgd@alap3.anarazel.de> <20220219213139.2gpsrqwp7hlmn634@alap3.anarazel.de> Organization: PostgresPro Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Good day, Andres. В Сб, 19/02/2022 в 13:31 -0800, Andres Freund пишет: > Hi, > > On 2022-02-19 10:00:02 -0800, Andres Freund wrote: > > See backtrace below [1]. The same problem does *not* exist when starting to > > use the same temp schema in a new session (which drops the old contents > > first), which kind of explains why we've not previously noticed this. > > > > But even so, I'm surprised we haven't noticed this before. > > Ah, there's a reason for that. In many cases we'll have a catalog snapshot > registered, which is enough for init_toast_snapshot(). But in Miles' example, > the object dropped just prior ends with catalog invalidations. > > Proposed bugfix and test attached. > > I think it's ok to backpatch the test. There might be a slight change in > output due to 618c16707a6d6e8f5c83ede2092975e4670201ad not being backpatched, > but that's OK I think. > > > I think it is dangerous that we return a cached catalog snapshot for things > like GetOldestSnapshot() unless they're also registered or active - we can't > rely on catalog snapshots to be present. Indeed, if we didn't, this bug would > have been found before, as some added assertions confirm. > > I don't think we can just ignore the catalog snapshot though, it can be > registered in the future, so it actually is the oldest snapshot. But at least > we should assert that there's some snapshot registered/active. In the attached > patch I've added HaveRegisteredOrActiveSnapshot() and used that in > init_toast_snapshot(). Reading your message and HaveRegisteredOrActiveSnapshot's body, I can't get its logic: - if it is dangerous to have CatalogSnapshot alone in RegisteredSnapshots, then why we return 'false' if RegisteredSnapshots is NOT singular? I believe, body of HaveRegisteredOrActiveSnapshot should look like: if (ActiveSnapshot != NULL) return true; if (pairingheap_is_empty(&RegisteredSnapshots)) return false; /* * The catalog snapshot is in RegisteredSnapshots when valid, but can be * removed at any time due to invalidation processing. If explicitly * registered more than one snapshot has to be in RegisteredSnapshots. */ if (pairingheap_is_singular(&RegisteredSnapshots)) return CatalogSnapshot == NULL; return true; Am I wrong? regards, Yura