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 1j4qdE-0004fL-27 for pgsql-general@arkaria.postgresql.org; Thu, 20 Feb 2020 18:33:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j4qdC-0002OQ-BR for pgsql-general@arkaria.postgresql.org; Thu, 20 Feb 2020 18:33:02 +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 1j4qdC-0002Md-1s for pgsql-general@lists.postgresql.org; Thu, 20 Feb 2020 18:33:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j4qd9-0007sT-SP for pgsql-general@lists.postgresql.org; Thu, 20 Feb 2020 18:33:01 +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 01KIWrYs016785; Thu, 20 Feb 2020 13:32:53 -0500 From: Tom Lane To: Albrecht =?iso-8859-1?b?RHJl3w==?= cc: pgsql-general@lists.postgresql.org Subject: Re: Error =?UTF-8?Q?=E2=80=9Ccache_lookup_failed_for_function=E2=80=9D?= In-reply-to: References: Comments: In-reply-to Albrecht =?iso-8859-1?b?RHJl3w==?= message dated "Thu, 20 Feb 2020 19:24:14 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <16783.1582223573.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 20 Feb 2020 13:32:53 -0500 Message-ID: <16784.1582223573@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Albrecht =3D?iso-8859-1?b?RHJl3w=3D=3D?=3D write= s: > I tried to update the running server by executing the following SQL upda= te script using psql: > ---8<----------------------------------------------- > BEGIN; > -- add a column to an existing table > -- add a new table > -- add several db functions > -- replace a DB function: > DROP FUNCTION public.get_result2(mytaskid bigint, OUT data bytea, OUT me= tadata jsonb, OUT errortext text, OUT vanished boolean); > CREATE FUNCTION public.get_result2(mytaskid bigint, OUT data bytea, OUT = metadata jsonb, OUT errortext text, OUT vanished boolean) RETURNS record > [=E2=80=A6] > COMMIT; > ---8<----------------------------------------------- > About ~350 clients were connected to the server when I ran the above scr= ipt, a few of them using, inter alia, the function get_result2() which oug= ht to be replaced. > Immediately after running the script, the log was filled with errors > ---8<----------------------------------------------- > ERROR: cache lookup failed for function 1821571 > CONTEXT: PL/pgSQL function get_result2(bigint) while casting return val= ue to function's return type > STATEMENT: SELECT data, metadata, errortext, vanished FROM get_result2(= 26671107) > ---8<----------------------------------------------- This is, actually, not very surprising. You dropped the old function while clients were using it. The new function is a completely unrelated object, even if it happens to have the same name. What you should have done was CREATE OR REPLACE FUNCTION, which would have preserved the object's identity. It does seem a bit annoying that something in plpgsql is apparently doing a fresh catalog lookup to find information that likely was already cached at the start of function execution. But I think that's a performance deficiency, not a bug per se. regards, tom lane