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 1oBYUA-0000vk-1o for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Jul 2022 09:16:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oBYU8-0007r5-Q6 for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Jul 2022 09:16:44 +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 1oBYU8-0007qw-CE for pgsql-bugs@lists.postgresql.org; Wed, 13 Jul 2022 09:16:44 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oBYU6-0002pc-7k for pgsql-bugs@lists.postgresql.org; Wed, 13 Jul 2022 09:16:44 +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 C67EE21C07E5; Wed, 13 Jul 2022 12:16:39 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1657703799; bh=NWPrtRWKNQrb9nIi4yjMc14bk5pHnQqWX/QPnbvFMcg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=kIHodxfCnv1XTisH8CbUmuLfm9Ec2ERHmg+2P+Q0ysB2D8SurKmy7RHbwQDdwNy86 F4caYgOe93nxyn97CRtVuVKUgvDWdBaBlMTg7RiAgJB9fIv8hD1s/lM49aHUMhpeIP RvGZoxEtGYgXzWvdsWQJNKsAKnH81ww4NjuB6YP8= Message-ID: <2ac628a335ed13b77904f8dd6e5a4e5bee2fbec6.camel@postgrespro.ru> Subject: Re: can't drop table due to reference from orphaned temp function From: Yura Sokolov To: Andres Freund Cc: Miles Delahunty , Tom Lane , pgsql-bugs@lists.postgresql.org, Robert Haas Date: Wed, 13 Jul 2022 12:16:38 +0300 In-Reply-To: <20220712192454.3p42auoul4lniyys@awork3.anarazel.de> References: <20220219180002.6tubjq7iw7m52bgd@alap3.anarazel.de> <20220219213139.2gpsrqwp7hlmn634@alap3.anarazel.de> <24a26615b66d84abf2083a10ff1ca59933a7b4e2.camel@postgrespro.ru> <20220712192454.3p42auoul4lniyys@awork3.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 В Вт, 12/07/2022 в 12:24 -0700, Andres Freund пишет: > Hi, > > On 2022-07-12 17:13:28 +0300, Yura Sokolov wrote: > > В Сб, 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? > > IIRC that was a bug that since was fixed. Did you check the current > definition? Ah, sorry. I really looked at old definition. New one is correct.