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 1loC98-0007yO-Eb for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Jun 2021 21:41:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1loC96-0007U3-N4 for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Jun 2021 21:41:56 +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 1loC96-0007Tv-GW for pgsql-bugs@lists.postgresql.org; Tue, 01 Jun 2021 21:41:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1loC94-0000fV-Fb for pgsql-bugs@lists.postgresql.org; Tue, 01 Jun 2021 21:41:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 151LfeQ92855402; Tue, 1 Jun 2021 17:41:40 -0400 From: Tom Lane To: kim.brodowski@iserv.eu cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17042: Concurrent Modifications of PostgreSQL Function Can Corrupt Database In-reply-to: <17042-cfa218be6e24a03d@postgresql.org> References: <17042-cfa218be6e24a03d@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 01 Jun 2021 20:45:06 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2855400.1622583700.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 01 Jun 2021 17:41:40 -0400 Message-ID: <2855401.1622583700@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > My co-worker Martin von Wittich came up with a set of minimal SQL statements > to trigger the issue: > bug.sql: > DROP TYPE foo CASCADE; > CREATE TYPE foo AS (foo INTEGER); > CREATE OR REPLACE FUNCTION foobar() RETURNS foo AS $$ > BEGIN >   RETURN ROW(1)::foo; > END > $$ > LANGUAGE plpgsql; > SELECT foobar(); > In order to trigger the issue, we need to run our statements in parallel: > psql -f test.sql & psql -f test.sql This doesn't seem terribly surprising. Occasionally one session's foobar() will run at an instant where type foo doesn't exist, thanks to the other session's script having dropped the type and not yet recreated it. The "cache lookup failed" messages are a bit scary, but they arise in situations where the type did exist a moment ago but now it's gone. There's been occasional proposals to prevent this sort of thing by obtaining a lock on every type name mentioned in a function and holding it till (probably) end of transaction. The cost of that, compared to the value, has dissuaded us from doing it. regards, tom lane