Re: pg_relation_size / could not open relation with OID # - Mailing list pgsql-general

From Tomas Vondra
Subject Re: pg_relation_size / could not open relation with OID #
Date
Msg-id 4C97E243.8030607@fuzzy.cz
Whole thread Raw
In response to Re: pg_relation_size / could not open relation with OID #  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: pg_relation_size / could not open relation with OID #  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Dne 20.9.2010 15:44, Tom Lane napsal(a):
> tv@fuzzy.cz writes:
>> I've run into a strange problem with system catalogs - we're collecting
>> database stats periodically (every 10 minutes), and from time to time we
>> get the following error:
>
>> --------------------------------------------------
>> ERROR:  could not open relation with OID 154873708
>> --------------------------------------------------
>
> I think you're probably hitting a problem with a table being deleted
> while you're scanning pg_class.  pg_relation_size() will fail if the
> given OID isn't valid "now" --- but the underlying query returns all
> OIDs that were valid when the transaction or statement snapshot was
> taken.  So you have a race condition.
>
> You might consider excluding temp tables from the query, if that's the
> most likely source of the problem.
>
>             regards, tom lane
>

OK, I'm a bit confused now. So it's not a race condition (i.e. a bug) in
a pg_relation_size but a feature?

I expected the whole query (including function calls etc.) will execute
on a consistent snapshot but as I understand the whole scenario is
something like this:

1) execute the SELECT statement (load the OIDs)
2) drop one of the tables (before the functions are evaluated)
3) execute pg_relation_size for all the OID (one of the tables does not
    exist anymore so the function call will fail)

I'll try to exclude the temp tables but I'm not sure if it will solve
the issue. It seems to me the very same scenario is possible with
regular tables, right?

Is there some other way to prevent this issue? E.g. locking the pg_class
table before executing the query or something like that?

regards
Tomas

pgsql-general by date:

Previous
From: Dmitriy Igrishin
Date:
Subject: Re: Data directory permissions.
Next
From: Tatsuo Ishii
Date:
Subject: Re: pgpool-II 3.0 + postgres 9rc1 + md5 authentication not working