pg_relation_filenode()

A function for obtaining the filenode number of a relation

pg_relation_filenode() is a system function for obtaining the filenode number of a relation with the specified OID or name.

pg_relation_filenode() was added in PostgreSQL 9.0.

Usage

pg_relation_filenode ( relation regclass ) → oid

The returned oid corresponds to the value contained in relfilenode in pg_class, except for certain system catalog tables where the value is 0. It is therefpre necessary to use this function to reliably determine a relations's filenode.

NULL is returned if the relation is a type such as a view which is does not have on-disk storage.

Change history

Examples

postgres=# SELECT pg_relation_filenode('foo');
 pg_relation_filenode 
----------------------
                16499
(1 row)

Attempting to query the relation filenode of a non-existent relation:

postgres=# SELECT pg_relation_filenode('bar');
ERROR:  relation "bar" does not exist
LINE 1: SELECT pg_relation_filenode('bar');

Attempting to query the relation filenode of a relation which does not store data:

postgres=# CREATE VIEW bar AS SELECT * FROM foo;
CREATE VIEW

postgres=# SELECT pg_relation_filenode('bar') IS NULL;
 ?column? 
----------
 t
(1 row)

See filenode for further examples.

Categories

Data directory, System function

See also

filenode, pg_filenode_relation(), pg_relation_filepath()