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

System views

System views are the read-only SQL contract for Amphi metadata. They live in the sys schema, are created during catalog bootstrap, and can be queried by tools such as amphi-console.

The public contract is formed by sys.catalog_* views. Physical catalog relations remain implementation details and should not be queried directly by new applications.

SELECT schema, name, kind, engine
FROM sys.catalog_objects
ORDER BY schema, name;

sys.catalog_object_comments

Lists comments for entities with catalog OID identities. Relations and columns are also available through sys.catalog_objects and sys.catalog_columns; this view covers relations and other commentable families, including schemas, types, domains, routines, roles, groups, tablespaces, policies, constraints, triggers, and installed extensions.

ColumnTypeDescription
object_oidint4Stable object identity
object_kindtextObject family
schema_nametextSchema, when applicable
object_nametextObject name
owner_nametextOwning relation for constraints/triggers
commenttextStored comment
SELECT object_kind, schema_name, object_name, comment
FROM sys.catalog_object_comments
ORDER BY object_kind, schema_name, object_name;

sys.catalog_object_tags

Lists tags for relations and catalog object families with OIDs (schemas, types, domains, functions/aggregates, roles/groups, tablespaces, policies, constraints, triggers, and named OID-backed objects), with one row per key. Filter by key/value. Not all these families appear in sys.catalog_objects, which continues to represent relations.

ColumnTypeDescription
object_oidint4Stable object identity
object_kindtextRelation kind
schema_nametextObject schema
object_nametextObject name
owner_nametextParent relation for constraints/triggers; NULL otherwise
keytextTag key
valuetextTag value
SELECT schema_name, object_name, object_kind
FROM sys.catalog_object_tags
WHERE key = 'env' AND value = 'prod'
ORDER BY schema_name, object_name;

ALTER TABLE ... ADD TAG key = 'value' creates or replaces a key; ALTER TABLE ... DROP TAG key removes it. ALTER OBJECT manages non-relation families; end-to-end validated coverage is listed in Object tags.

Use the catalog views to inspect schemas, objects, columns, indexes, functions, and extensions. Changes must be made through the corresponding DDL commands.

sys.language

Lists procedural languages installed and active in the current process. A language is registered by the extension that provides it; for example, CREATE EXTENSION plamphi adds plamphi to this view.

ColumnTypeDescription
nametextLanguage name used by LANGUAGE
extensiontextExtension providing the handler
statustextCurrent handler state
SELECT name, extension, status
FROM sys.language
ORDER BY name;

This is a virtual view of the current runtime. It is empty for a language that is available but has not been installed with CREATE EXTENSION.

sys.catalog_functions.schema identifies the owning schema. arg_types remains encoded as bytea; use the function history page for complete SQL definitions. security_definer records the SECURITY DEFINER declaration; the owner is used as current_user during execution.

sys.object_revision

Read-only history for versioned objects. For functions, source contains the complete DDL for the revision and created_by identifies the role that made the change.

ColumnTypeDescription
object_oidint4Stable object identity
object_kindtextObject type, currently function
versionint8Revision number
sourcetextComplete DDL
arg_namesbyteaEncoded argument names
created_atint8Timestamp in microseconds
created_byint4Author role OID
ddl_seqint8DDL sequence, when available

sys.catalog_domains

Lists domains defined outside the sys schema. The checks column keeps the catalog’s bytea representation so the public view can expose the complete metadata without changing its one-row-per-domain shape; DDL and ampdump decode that value when they need the named checks.

ColumnTypeDescription
oidint4Domain identifier
schematextDomain schema
nametextDomain name
base_typetextBase type
default_expressiontextDomain default, when defined
not_nullboolWhether null values are rejected
checksbyteaEncoded named domain checks
SELECT schema, name, base_type, default_expression, not_null
FROM sys.catalog_domains
ORDER BY schema, name;

sys.catalog_triggers

Exposes trigger descriptors stored in the catalog. This is the metadata contract of Epic 1; SQL creation and execution belong to later epics.

ColumnTypeDescription
oidint4Trigger identifier
relint4Relation owning the trigger
nametextTrigger name
functionint4Function executed by the trigger
timingtextBEFORE, AFTER, or INSTEAD OF
leveltextROW or STATEMENT
eventsint2Mask of INSERT, UPDATE, DELETE, and TRUNCATE
scopetextLOGICAL or PHYSICAL
argumentsbyteaPersisted trigger arguments
enabledboolWhether the trigger is enabled

scope = LOGICAL is reserved for a trigger that follows the logical operation of a partitioned table; PHYSICAL follows a specific physical relation. This is distinct from relation inheritance.

sys.catalog_partitions

Lists physical relations attached to a partitioned table.

ColumnTypeDescription
relationint4Child relation
parentint4Parent partitioned table
boundtextPersisted canonical bound; typed semantics are still evolving

sys.catalog_acls

Exposes persisted object privilege grants.

ColumnTypeDescription
relationint4Protected relation OID
grantee_kindtextPUBLIC, ROLE, or GROUP
granteeint4Grantee OID; null for PUBLIC
grantorint4Granting role OID
privilegetextGranted privilege
scope_kindtextALL, COLUMNS, or ALL_EXCEPT
columnsbyteaEncoded attno list when applicable
grant_optionboolWhether the grantee can regrant it

sys.catalog_default_acls

Exposes default privileges configured by a role for new tables, schemas, and sequences. They are applied when the object is created. It has the same scope and grantee columns as sys.catalog_acls; owner identifies the role that owns the default rule and object identifies TABLES, SCHEMAS, or SEQUENCES.

sys.stat_activity

Shows active sessions and workers. SQL sessions use backend_type = 'client'; the internal worker uses backend_type = 'worker', worker_kind = 'partition', and its alarm_id.

SELECT id, backend_type, worker_kind, alarm_id, state, query, relation
FROM sys.stat_activity
WHERE state = 'active';

Rows are ephemeral and disappear when the session or worker finishes.

sys.stat_progress

Shows current and recent progress for internal operations. It is an in-memory view; durable outcome and errors remain in sys.system_alarm_status.

SELECT kind, state, phase, rows_done, rows_total, error
FROM sys.stat_progress;

Columns include operation_id, kind, state, phase, alarm_id, relation, rows_done, rows_total, bytes_done, bytes_total, started_at, updated_at, and error.

sys.system_alarms

Shows occurrences of core-owned internal alarms. Users, extensions, and plugins cannot register new alarm kinds or handlers.

ColumnTypeDescription
idint8Occurrence identifier
kindtextInternal kind, initially partition
ownerint4Associated core object, such as the parent relation
scheduled_atint8Scheduled Unix time in microseconds
statetextwaiting, running, success, or failed
attemptint4Current attempt
started_atint8Execution start, when started
finished_atint8Execution finish, when completed
errortextLast attempt error
affected_objectsint4Objects created or changed
lease_ownerint8Worker holding the lease, when running
lease_untilint8Lease expiry as Unix microseconds

sys.system_alarm_status exposes the same operational contract for health checks and monitoring; users cannot create or alter system alarms. A minimal monitoring query is:

SELECT kind, state, attempt, scheduled_at, lease_owner, lease_until, error
FROM sys.system_alarm_status
WHERE state IN ('waiting', 'running', 'failed')
ORDER BY scheduled_at;

Alarm occurrences are durable and survive restart. A running row with an expired lease is eligible for worker reclaim; failed retains the last error and may produce a new occurrence with bounded backoff.

sys.partition_policies

Shows declarative partition policies persisted in the catalog. scope = database represents the database policy; other values identify the schema where the policy applies.

ColumnTypeDescription
oidint4Policy identifier
nametextPolicy name
scopetextdatabase or schema scope
relation_kindtexttable or collection
match_columntextColumn used for matching
match_typetextResolved column type
strategytextrange, hash, or list
keytextPartition key
everytextAutomatic interval
retentiontextDeclared retention
sub_strategytextSubpartition strategy
sub_keytextSubpartition key
subpartitionsint2Number of subpartitions
retention_actiontextdetach or export_then_detach
retention_servertextSERVER used by export, when applicable

sys.prepared_transactions

Shows transactions retained by two-phase commit in the current cluster, including after recovery.

ColumnTypeDescription
gidtextGlobal identifier of the prepared transaction
xidint8Transaction ID
prepared_atint8Preparation time in microseconds since the Unix epoch
ownertextUser that executed PREPARE TRANSACTION

2PC must be enabled with max_prepared_transactions greater than zero. Logical backup neither exports nor recreates prepared transactions: ampdump refuses a dump while the view has rows.

sys.function_cache_stats

Shows counters for the process-local cache of bound SQL-function bodies:

hits | misses | entries | capacity

hits and misses count reused and newly bound queries; entries shows the current number of entries and capacity the LRU limit. Counters reset when the server process restarts.