Updated on 2024-05-07 GMT+08:00

PG_CLASS

PG_CLASS records database objects and their relationship.

Table 1 PG_CLASS columns

Name

Type

Description

oid

oid

Row identifier (hidden attribute, which must be specified).

relname

name

Name of an object, such as a table, index, or view.

relnamespace

oid

OID of the namespace that contains the relationship.

reltype

oid

Data type that corresponds to the table's row type. The index is 0 because the index does not have PG_TYPE records.

reloftype

oid

OID of the composite type (0 for other types).

relowner

oid

Owner of the relationship.

relam

oid

Access method used, such as B-tree, if the row is an index.

relfilenode

oid

Name of the on-disk file of this relationship (0 if such file does not exist).

reltablespace

oid

Tablespace in which this relationship is stored. If the value is 0, the default tablespace in this database is used. This column is meaningless if the relationship has no on-disk file.

relpages

double precision

Size of the on-disk representation of the table in pages (of size BLCKSZ). This is only an estimate used by the optimizer.

reltuples

double precision

Number of rows in the table. This is only an estimate used by the optimizer.

relallvisible

integer

Number of pages marked as all visible in the table. This column is used by the optimizer for optimizing SQL execution. It is updated by VACUUM, ANALYZE, and a few DDL statements such as CREATE INDEX.

reltoastrelid

oid

OID of the TOAST table associated with the table (0 if no TOAST table exists).

The TOAST table stores large columns "offline" in a secondary table.

reltoastidxid

oid

OID of the index for a TOAST table (0 for a table other than a TOAST table).

relhasindex

Boolean

Its value is true if this column is a table and has (or recently had) at least one index.

It is set by CREATE INDEX but is not immediately cleared by DROP INDEX. If the VACUUM process detects that a table has no index, it clears the relhasindex column and sets the value to false.

relisshared

Boolean

Its value is true if the table is shared across all database nodes in the database. Only certain system catalogs (such as PG_DATABASE) are shared.

relpersistence

"char"

  • p: permanent table
  • u: non-log table
  • t: temporary table
  • g: global temporary table.

relkind

"char"

  • r: ordinary table
  • i: index
  • I: global index of a partitioned table
  • s: sequence
  • L: long sequence
  • v: view
  • c: composite type
  • t: TOAST table
  • f: foreign table
  • m: materialized view

relnatts

smallint

Number of user columns in the relationship (excluding system columns). 13.2.48 PG_ATTRIBUTE has the same number of rows as the user columns.

relchecks

smallint

Number of check constraints in the table. For details, see the system catalog 13.2.55 PG_CONSTRAINT.

relhasoids

Boolean

Its value is true if an OID is generated for each row of the relationship. Otherwise, the value is false.

relhaspkey

Boolean

Its value is true if the table has (or once had) a primary key. Otherwise, the value is false.

relhasrules

Boolean

Its value is true if the table has rules. For details, see the system catalog 13.2.90 PG_REWRITE.

relhastriggers

Boolean

The value is true if the table has (or once had) triggers. Triggers of the table and view are recorded in the system catalog 13.2.102 PG_TRIGGER.

relhassubclass

Boolean

Its value is true if the table has (or once had) any inheritance child table. Otherwise, the value is false.

relcmprs

tinyint

Specifies whether the compression feature is enabled for the table. Note that only batch insertion triggers compression, so ordinary CRUD does not trigger compression.
  • 0: Tables that do not support compression (primarily system catalogs, on which the compression attribute cannot be modified).
  • 1: The compression feature of the table data is NOCOMPRESS or has no specified keyword.
  • 2: The compression feature of the table data is COMPRESS.

relhasclusterkey

Boolean

Specifies whether the local cluster storage is used.

  • true: yes
  • false: no

relrowmovement

Boolean

Whether row migration is allowed when the partitioned table is updated.
  • true: Row migration is allowed.
  • false: Row migration is not allowed.

parttype

"char"

Whether the table or index has the property of a partitioned table.
  • p: The table or index has the property of a partitioned table.
  • n: The table or index does not have the property of a partitioned table.
  • s: The table is a level-2 partitioned table.

relfrozenxid

xid32

All transaction IDs before this one have been replaced with a permanent ("frozen") transaction ID in the table. This column is used to track whether the table needs to be vacuumed to prevent transaction ID wraparound (or to allow PG_CLOG to be shrunk). The value is 0 (InvalidTransactionId) if the relationship is not a table.

To ensure forward compatibility, this column is reserved. The relfrozenxid64 column is added to record the information.

relacl

aclitem[]

Access permissions. For details about the ACLItem type, see ACLItem.

The command output of the query is as follows:

1
user1=privs/user2 indicates that the permission granted by user 2 to user 1 is privs.
1
=privs/user3 indicates that the permission granted to the public role by user 3 is privs.

In the preceding command, user 1, user 2, and user 3 are the existing users or roles in the database, and privs indicates the permissions supported by the database. For details on permission descriptions, see Table 2.

reloptions

text[]

Table or index access method, using character strings in the format of "keyword=value"

relreplident

"char"

Identifier of a decoding column in logical decoding.
  • d: default (primary key, if any)
  • n: none
  • f: all columns
  • i: The indisreplident of the index is specified or the default index is used.

relfrozenxid64

xid

All transaction IDs before this one have been replaced with a permanent ("frozen") transaction ID in the table. This column is used to track whether the table needs to be vacuumed to prevent transaction ID wraparound (or to allow PG_CLOG to be shrunk). The value is 0 (InvalidTransactionId) if the relationship is not a table.

For a global temporary table, this field is meaningless. You can view relfrozenxid64 of the global temporary table of each session in the pg_catalog.pg_gtt_relstats view.

relbucket

oid

Specifies whether the current catalog contains hash bucket shards. A valid OID points to the specific shard information recorded in the PG_HASHBUCKET system catalog. NULL indicates that hash bucket shards are not included.

relbucketkey

int2vector

Hash partition column information. NULL indicates that the column information is not included.

relminmxid

xid

All multi-transaction IDs before this one have been replaced with a transaction ID in the table. This is used to track whether the table needs to be vacuumed in order to prevent multi-transaction IDs wraparound or to allow PG_CLOG to be shrunk. The value is 0 (InvalidTransactionId) if the relationship is not a table.

Table 2 Description of permissions

Parameter

Description

r

SELECT (read)

w

UPDATE (write)

a

INSERT (insert)

d

DELETE

D

TRUNCATE

x

REFERENCES

t

TRIGGER

X

EXECUTE

U

USAGE

C

CREATE

c

CONNECT

T

TEMPORARY

A

ALTER

P

DROP

m

COMMENT

i

INDEX

v

VACUUM

*

Authorization options for preceding permissions