Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Physical catalog and sys.* relations

Amphi has two metadata layers: persisted physical sys.* tables and the public read-only sys.catalog_* views. The physical tables are useful for diagnostics and engine development; new applications should use the public views.

Persisted physical relations

Physical catalog relations use fixed OIDs. Their storage-order schemas are:

1 schema: (oid int4, name text)
2 relation: (oid int4, storage_oid int4, schema int4, name text, kind int2,
  engine int2, toast_rel int4, options bytea, comment text)
3 attribute: (rel int4, attno int2, name text, type int4, type_mod int4,
  not_null bool, dropped bool, comment text)
4 type: (oid int4, name text, len int2, schema int4, element_type int4, array_type int4)
5 function: (oid int4, name text, arg_types bytea, ret_type int4, native int4,
  aggregate bool, volatility int2, schema int4, security_definer bool)
6 operator: (oid int4, name text, left int4, right int4, ret_type int4,
  func int4, commutator int4, negator int4)
7 opclass: (oid int4, name text, am int2, type int4, is_default bool, compare int4)
8 opclass_operator: (opclass int4, strategy int2, operator int4)
9 cast: (source int4, target int4, func int4, context int2)
10 index: (index_rel int4, table_rel int4, am int2, unique bool, columns bytea, valid bool)
11 collection_dict: (rel int4, key_id int4, key text)
13 view_def: (rel int4, query text)
18 attr_def: (rel int4, attno int2, sequence int4)
19 sequence: (rel int4, high int8, start int8, increment int8, min int8, max int8, cycle bool, cache int8)
20 role: (oid int4, name text, can_login bool, enabled bool, is_admin bool,
  can_create_db bool, can_create_role bool, inherit bool, valid_until int8)
21 group: (oid int4, name text)
22 group_member: (group int4, member int4)
23 role_credential: (role int4, salt bytea, iterations int4, stored_key bytea, server_key bytea)
24 access_policy: (oid int4, name text, priority int4, subject_kind int2, subject int4,
  source text, database text, allow bool, rate_per_second int4, burst int4)
27 check_constraint: (oid int4, relation int4, name text, expression text)
28 foreign_key: (oid int4, relation int4, name text, columns bytea,
  referenced_relation int4, referenced_columns bytea, on_delete int2, on_update int2,
  deferrable bool, initially_deferred bool)
40 foreign_server: (name text, connection text, options bytea)
41 foreign_table: (relation int4, server text, options bytea)
46 column_default: (rel int4, attno int2, expression text)
47 column_missing: (rel int4, attno int2, expression text)
48 acl: (relation int4, grantee_kind int2, grantee int4, grantor int4, privilege int2,
  scope_kind int2, columns bytea, grant_option bool)
50 default_acl: (owner int4, object_kind int2, grantee_kind int2, grantee int4,
  privilege int2, scope_kind int2, columns bytea, grant_option bool)
74 object_comment: (object_oid int4, object_kind text, comment text)
76 named_object_identity: (object_oid int4, object_kind text, object_name text)
12 meta: (catalog_version int4, ddl_seq int8, next_oid int4)
14 stat_user_tables: (relid int4, schema text, name text, n_tup_ins int8,
  n_tup_upd int8, n_tup_del int8, n_live_tup int8, n_dead_tup int8,
  last_vacuum int8, last_analyze int8)
17 stat_column: (relid int4, attno int4, null_frac float8, n_distinct int8,
  correlation float8, mcv text, histogram text)
36 schedule, 37 schedule_run, 45 external_connection, 52 trigger,
54 partition, 59 system_alarm, 60 domain, 61 partition_policy,
65 tablespace, 68 stat_progress, 69 object_revision, 70 prepared_transactions,
72 extension (name text, schema int4, version text)

stat_activity and blocking_tree are virtual process relations and have no persistent heap.

Typmods, codes, and runtime OIDs

sys.attribute.type_mod currently uses -1 for no modifier, a positive value for varchar(n), and -(n + 1) for char(n). Packed bytea columns contain catalog position lists and numeric codes must be translated by the catalog layer.

Runtime-only relations use a separate range:

100 available_extensions
101 extension_lifecycle
102 extension_metrics
103 languages

They must never reuse a persisted sys.* OID. A collision can make a physical relation be decoded with the wrong RowCodec schema.

Public contract

Use sys.catalog_schemas, sys.catalog_objects, sys.catalog_columns, sys.catalog_indexes, sys.catalog_types, sys.catalog_functions, sys.catalog_checks, sys.catalog_foreign_keys, sys.catalog_roles, sys.catalog_groups, sys.catalog_group_members, sys.catalog_acls, sys.catalog_default_acls, sys.catalog_domains, and sys.catalog_partitions from applications and tools. Their columns and examples are documented in System views.

Changing a physical catalog column, type, or position requires incrementing CATALOG_VERSION and adding an explicit migration. Persistent OIDs must not be reused, and an OID must not be confused with the array position in the source definition.

Object metadata and tags

Tags are searchable catalog metadata, stored by stable object identity and exposed through sys.catalog_object_tags. Do not add a variable tag list to sys.catalog_objects. Supported objects must allow tags to be created, changed, removed, queried in filters/joins, and viewed in the Web Console. Comments remain free-form text with separate semantics.

Rule for new object types: when adding a persistent object type with a catalog identity, include it in the tagging contract (SQL, catalog/view, queries, permissions, dump/restore, and Console), or document why tagging does not apply. Do not consider a type complete until this decision is recorded. Internal objects without an administrable identity may be excluded, with the exclusion documented.

See Object tags for the initial inventory and current coverage.