Thread: pg_total_relation_size() could not open relation with OID X

pg_total_relation_size() could not open relation with OID X

From
Michael Fuhr
Date:
Here's a test case for a pg_total_relation_size() failure:

test=> CREATE TABLE foo (id integer);
CREATE TABLE
test=> SELECT oid, relfilenode FROM pg_class WHERE relname = 'foo'; oid  | relfilenode 
-------+-------------26235 |       26235
(1 row)

test=> SELECT pg_total_relation_size('foo');pg_total_relation_size 
------------------------                     0
(1 row)

test=> TRUNCATE foo;
TRUNCATE TABLE
test=> SELECT oid, relfilenode FROM pg_class WHERE relname = 'foo'; oid  | relfilenode 
-------+-------------26235 |       26237
(1 row)

test=> SELECT pg_total_relation_size('foo');
ERROR:  could not open relation with OID 26237
test=> SELECT pg_total_relation_size(26235);
ERROR:  could not open relation with OID 26237
test=> SELECT pg_relation_size('foo');pg_relation_size 
------------------               0
(1 row)

-- 
Michael Fuhr


Re: pg_total_relation_size() could not open relation with OID X

From
Alvaro Herrera
Date:
On Wed, Sep 28, 2005 at 10:25:16PM -0600, Michael Fuhr wrote:

> test=> TRUNCATE foo;
> TRUNCATE TABLE
> test=> SELECT oid, relfilenode FROM pg_class WHERE relname = 'foo';
>   oid  | relfilenode 
> -------+-------------
>  26235 |       26237
> (1 row)

The code is obviously confused between Oid and relfilenode.  The
calculate_total_relation_size() function gets a relfilenode parameter
and then tries to call relation_open() with it.  This is wrong.

I'll submit/commit a patch fixing this, later today.  Thanks for the
test case.

-- 
Alvaro Herrera       Valdivia, Chile   ICBM: S 39º 49' 17.7", W 73º 14' 26.8"
"Granting software the freedom to evolve guarantees only different results,
not better ones." (Zygo Blaxell)


Re: pg_total_relation_size() could not open relation with OID X

From
Alvaro Herrera
Date:
I wrote:

> The code is obviously confused between Oid and relfilenode.  The
> calculate_total_relation_size() function gets a relfilenode parameter
> and then tries to call relation_open() with it.  This is wrong.

This is the patch I'm about to apply.  Besides fixing this particular
problem, I made the code include the size of the index of the TOAST
table in pg_total_relation_size().

--
Alvaro Herrera                         Architect, http://www.EnterpriseDB.com
"En las profundidades de nuestro inconsciente hay una obsesiva necesidad
de un universo lógico y coherente. Pero el universo real se halla siempre
un paso más allá de la lógica" (Irulan)

Attachment