Re: cache lookup failed in plpgsql - reason?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cache lookup failed in plpgsql - reason?
Date: 2012-03-21 16:54:52
Message-ID: CA+TgmobHVvO89F4OeGqbtge6tJN3u9xegpOSxOzDBC69Zd7jhg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Oct 26, 2011 at 10:37 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Oct 25 20:13:44  db-s-01 postgres: <local5.warning> -- postgres[29970]:
> [3-1] 2011-10-25 20:13:44 CEST adifd 29970 ERROR:  cache lookup failed
> for relation 319883311
> Oct 25 20:13:44  db-s-01 postgres: <local5.warning> -- postgres[29970]:
> [3-2] 2011-10-25 20:13:44 CEST adifd 29970 CONTEXT:  SQL statement
> "SELECT  NOT EXISTS( SELECT relname FROM pg_class WHERE relname =

This appears to be a race condition in pg_table_is_visible. It checks
whether the table exists; if it does not, it returns NULL. Having
verified that the relation exists, it then calls RelationIsVisible(),
which then does a new syscache lookup for the same tuple, throwing an
error if none is found. But there's no guarantee that things can't
change between the first test and the second one, so you get this
error.

Perhaps we could make RelationInVisible return a three-valued enum
type, rather than bool. VISIBLE_YES, VISIBLE_NO, and
VISIBLE_NOTFOUND, or something like that. I wouldn't want to
back-patch such a fix, since there could be third-party code calling
RelationIsVisible, but we could do it in master. Sadly it's not a
trivial patch, since there are a gazillion WhateverIsVisible()
functions and we'd have to fix them all, but at least it's mostly
mechanical.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2012-03-21 17:02:18 Re: [v9.2] Add GUC sepgsql.client_label
Previous Message Alex Shulgin 2012-03-21 16:42:58 Trivial libpq refactoring patch (was: Re: Another review of URI for libpq, v7 submission)