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

Catalog and Metadata

AngaraBase stores metadata for all database objects in a central registry — the SysCatalog. For users, access to metadata is provided via the sys.* system views and introspection functions.

Object Hierarchy

Database objects are organized in a strict hierarchy:

Instance → Database → Schema → Table → Column

Each level has a unique identifier in the SysCatalog. Tables belong to schemas, schemas to databases, and databases to the instance.

SysCatalog

SysCatalog is the central metadata registry. It stores information about:

  • tables, columns, and their data types
  • indexes and constraints
  • users, roles, and privileges
  • functions and aggregates
  • security policies (RLS)
  • statistics for the query optimizer

The SysCatalog is updated during DDL operations (CREATE, ALTER, DROP) and when statistics are gathered.

System Views (sys.*)

System views are read-only and do not require special privileges (with the exception of security-related views).

Instance Identification and State

ViewDescription
sys.identityInstance identity: version, instance_id
sys.healthServer health status
sys.settingsEffective configuration (name, value). Secrets are not exposed

Data Structure

ViewDescription
sys.tablesAll tables with metadata (schema, name, type, row count)
sys.columnsColumns for each table: column_name, data_type, nullable, etc.

Statistics

ViewDescription
sys.table_statsTable-level statistics: stats_level_max, last_committed_rowid, mutation epochs
sys.column_statsColumn-level statistics: ndv_approx, min/max, null_count, histograms, MCV

Security and Access

ViewDescription
sys.usersUser accounts
sys.rolesRoles
sys.user_rolesAssignments of users to roles
sys.role_privilegesRole privileges
sys.object_grantsObject-level grants
sys.my_privilegesCurrent user’s privileges
sys.security_policiesRLS policies
sys.audit_logAudit log

Introspection Functions

AngaraBase provides a set of built-in functions for programmatic access to metadata.

Roles and Privileges

FunctionPurpose
angara_user_roles()Current user’s roles
angara_role_privileges()Privileges of a given role
angara_user_privileges()Effective user privileges
angara_object_privileges()Privileges on a specific object
angara_has_privilege()Check for a specific privilege

Security (RLS, audit, break-glass)

FunctionPurpose
angara_table_policies()RLS policies for a table
angara_is_rls_active()Whether RLS is active for a table
angara_effective_rls_predicate()The final RLS predicate for the current user
angara_break_glass_status()Status of the break-glass session
angara_audit_verify_chain()Verify the integrity of the audit chain

Diagnostics and Performance

Function / ViewPurpose
angara_stat_activityActive sessions and running queries
angara_stat_statementsAggregated statistics for executed queries
angara_top_queries()Top queries by resource consumption
angara_stat_statements_reset()Reset query statistics

Practical Examples

Instance Information

SELECT * FROM sys.identity;

Checking Server Health

SELECT * FROM sys.health;

List All Tables

SELECT * FROM sys.tables;

Checking Security Settings

SELECT name, value FROM sys.settings WHERE name LIKE 'security.%';

Viewing Table Column Statistics

SELECT column_name, ndv_approx, null_count
FROM sys.column_stats
WHERE table_name = 'orders';

Checking Current User Privileges

SELECT * FROM sys.my_privileges;
SELECT angara_has_privilege('orders', 'SELECT');