Summary
The catalog pg_constraint stores check, not-null, primary key, unique, foreign key, and exclusion constraints on tables. (Column constraints are not treated specially. Every column constraint is equivalent to some table constraint.)
(Description quoted from the official PostgreSQL documentation.)
Columns
The pg_constraint system catalog exposes the following columns (names, types and descriptions are taken verbatim from the PostgreSQL documentation):
oidoid
Row identifierconnamename
Constraint name (not necessarily unique!)connamespaceoidreferencespg_namespace.oid
The OID of the namespace that contains this constraintcontypechar
c = check constraint, f = foreign key constraint, n = not-null constraint, p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraintcondeferrablebool
Is the constraint deferrable?condeferredbool
Is the constraint deferred by default?conenforcedbool
Is the constraint enforced?convalidatedbool
Has the constraint been validated?conrelidoidreferencespg_class.oid
The table this constraint is on; zero if not a table constraintcontypidoidreferencespg_type.oid
The domain this constraint is on; zero if not a domain constraintconindidoidreferencespg_class.oid
The index supporting this constraint, if it’s a unique, primary key, foreign key, or exclusion constraint; else zeroconparentidoidreferencespg_constraint.oid
The corresponding constraint of the parent partitioned table, if this is a constraint on a partition; else zeroconfrelidoidreferencespg_class.oid
If a foreign key, the referenced table; else zeroconfupdtypechar
Foreign key update action code: a = no action, r = restrict, c = cascade, n = set null, d = set defaultconfdeltypechar
Foreign key deletion action code: a = no action, r = restrict, c = cascade, n = set null, d = set defaultconfmatchtypechar
Foreign key match type: f = full, p = partial, s = simpleconislocalbool
This constraint is defined locally for the relation. Note that a constraint can be locally defined and inherited simultaneously.coninhcountint2
The number of direct inheritance ancestors this constraint has. A constraint with a nonzero number of ancestors cannot be dropped nor renamed.connoinheritbool
This constraint is defined locally for the relation. It is a non-inheritable constraint.conperiodbool
This constraint is defined with WITHOUT OVERLAPS (for primary keys and unique constraints) or PERIOD (for foreign keys).conkeyint2[]referencespg_attribute.attnum
If a table constraint (including foreign keys, but not constraint triggers), list of the constrained columnsconfkeyint2[]referencespg_attribute.attnum
If a foreign key, list of the referenced columnsconpfeqopoid[]referencespg_operator.oid
If a foreign key, list of the equality operators for PK = FK comparisonsconppeqopoid[]referencespg_operator.oid
If a foreign key, list of the equality operators for PK = PK comparisonsconffeqopoid[]referencespg_operator.oid
If a foreign key, list of the equality operators for FK = FK comparisonsconfdelsetcolsint2[]referencespg_attribute.attnum
If a foreign key with a SET NULL or SET DEFAULT delete action, the columns that will be updated. If null, all of the referencing columns will be updated.conexclopoid[]referencespg_operator.oid
If an exclusion constraint or WITHOUT OVERLAPS primary key/unique constraint, list of the per-column exclusion operators.conbinpg_node_tree
If a check constraint, an internal representation of the expression. (It’s recommended to use pg_get_constraintdef() to extract the definition of a check constraint.)
Related catalogs
This object references the following other system catalogs:
connamespace→pg_namespaceconrelid→pg_classcontypid→pg_typeconkey→pg_attributeconpfeqop→pg_operator
Version applicability
Present in PostgreSQL 17, 18, 19 (verified against each release’s documentation). This is a long-standing system object that also exists in earlier PostgreSQL releases.
Related & references
Reference: PostgreSQL documentation — pg_constraint.