PG_DEPEND

PG_DEPEND records the dependency relationships between database objects. This information allows DROP commands to find which other objects must be dropped by DROP CASCADE or prevent dropping in the DROP RESTRICT case.

See also PG_SHDEPEND, which provides a similar function for dependencies involving objects that are shared across a database cluster.

Table 1 PG_DEPEND columns

Name

Type

Reference

Description

classid

oid

PG_CLASS.oid

OID of the system catalog the dependent object is in

objid

oid

Any OID column

OID of the specific dependent object

objsubid

integer

-

For a table column, this is the column number (the objid and classid refer to the table itself). For all other object types, this column is 0.

refclassid

oid

PG_CLASS.oid

OID of the system catalog the referenced object is in

refobjid

oid

Any OID column

OID of the specific referenced object

refobjsubid

integer

-

For a table column, this is the column number (the refobjid and refclassid refer to the table itself). For all other object types, this column is 0.

deptype

"char"

-

A code defining the specific semantics of this dependency relationship

In all cases, a pg_depend entry indicates that the referenced object cannot be dropped without also dropping the dependent object. However, there are several subflavors defined by deptype:

Examples

Query the table that depends on the database object sequence serial1.

  1. Query the OID of the sequence serial1 in the system catalog PG_CLASS.
    1
    2
    3
    4
    5
    SELECT oid FROM pg_class WHERE relname ='serial1';
      oid
    -------
     17815
    (1 row)
    
  2. Use the system catalog PG_DEPEND and the OID of serial1 to obtain the objects that depend on serial1.
    1
    2
    3
    4
    5
    6
    SELECT * FROM pg_depend WHERE objid ='17815';
     classid | objid | objsubid | refclassid | refobjid | refobjsubid | deptype
    ---------+-------+----------+------------+----------+-------------+---------
        1259 | 17815 |        0 |       2615 |     2200 |           0 | n
        1259 | 17815 |        0 |       1259 |    17812 |           1 | a
    (2 rows)
    
  3. Obtain the OID of the table that depends on the serial1 sequence based on the refobjid field and query the table name. The result indicates that the table customer_address depends on serial1.
    1
    2
    3
    4
    5
    SELECT relname FROM pg_class where oid='17812';
         relname
    ------------------
     customer_address
    (1 row)