System Views Quick Reference
System Views Quick Reference
Status: FULLY IMPLEMENTED Last Updated: 2025-11-21
Overview
System views provide metadata about database internals. They are read-only views that return information about branches, materialized views, and vector indexes. As of v2.0, all system views return real data from storage metadata.
Available System Views
pg_database_branches()
Lists all database branches with metadata.
Columns:
branch_name(TEXT) - Branch namebranch_id(INT8) - Unique IDparent_id(INT8) - Parent branch IDcreated_at(TIMESTAMP) - Creation timefork_point_lsn(INT8) - Snapshot at creationsize_mb(INT8) - Storage size in MBstatus(TEXT) - Branch state
Example:
-- List all branchesSELECT * FROM pg_database_branches();
-- Find large branchesSELECT branch_name, size_mbFROM pg_database_branches()WHERE size_mb > 100;
-- Show branch hierarchySELECT b.branch_name, p.branch_name AS parentFROM pg_database_branches() bLEFT JOIN pg_database_branches() p ON b.parent_id = p.branch_id;pg_mv_staleness()
Shows staleness information for materialized views.
Columns:
view_name(TEXT) - View namebase_tables(TEXT) - JSON array of source tableslast_update(TIMESTAMP) - Last refresh timepending_changes(INT8) - Pending changes countstaleness_sec(INT8) - Seconds since refreshstatus(TEXT) - STALE/OUTDATED/FRESH
Example:
-- List all materialized viewsSELECT * FROM pg_mv_staleness();
-- Find stale viewsSELECT view_name, staleness_secFROM pg_mv_staleness()WHERE status = 'STALE';
-- Find views that need refreshSELECT view_name, last_updateFROM pg_mv_staleness()WHERE staleness_sec > 3600; -- > 1 hourpg_vector_index_stats()
Vector index statistics including compression ratios.
Columns:
index_name(TEXT) - Index namenum_vectors(INT8) - Number of vectorsdimensions(INT4) - Vector dimensionalityquantization(TEXT) - Compression methodmemory_bytes(INT8) - Memory usagerecall_at_10(FLOAT8) - Recall@10 metric
Example:
-- List all vector indexesSELECT * FROM pg_vector_index_stats();
-- Find large indexesSELECT index_name, num_vectors, memory_bytes / 1024 / 1024 AS memory_mbFROM pg_vector_index_stats()WHERE num_vectors > 1000000;
-- Check quantization statusSELECT index_name, quantizationFROM pg_vector_index_stats()WHERE quantization != 'None';Usage in REPL
List System Views
\dSDescribe System View Schema
\dS pg_database_branches\dS pg_mv_staleness\dS pg_vector_index_statsQuery System Views
SELECT * FROM pg_database_branches();SELECT * FROM pg_mv_staleness();SELECT * FROM pg_vector_index_stats();Monitoring Examples
Database Health Check
-- Check for stale materialized viewsSELECT view_name, staleness_sec / 3600 AS hours_staleFROM pg_mv_staleness()WHERE status IN ('STALE', 'OUTDATED')ORDER BY staleness_sec DESC;
-- Check branch storage usageSELECT branch_name, size_mb, statusFROM pg_database_branches()ORDER BY size_mb DESCLIMIT 10;
-- Check vector index memory usageSELECT index_name, num_vectors, memory_bytes / 1024 / 1024 AS memory_mb, (memory_bytes::float / num_vectors) AS bytes_per_vectorFROM pg_vector_index_stats()WHERE num_vectors > 0ORDER BY memory_bytes DESC;Automated Refresh Strategy
-- Find views that should be refreshedSELECT view_name, staleness_sec / 60 AS minutes_staleFROM pg_mv_staleness()WHERE status = 'OUTDATED' AND staleness_sec > 3600; -- More than 1 hour oldCapacity Planning
-- Total storage by branchSELECT COUNT(*) AS branch_count, SUM(size_mb) AS total_mb, AVG(size_mb) AS avg_mb, MAX(size_mb) AS max_mbFROM pg_database_branches()WHERE status = 'Active';
-- Vector index growth trackingSELECT COUNT(*) AS index_count, SUM(num_vectors) AS total_vectors, SUM(memory_bytes) / 1024 / 1024 / 1024 AS total_gbFROM pg_vector_index_stats();Best Practices
- Regular Monitoring: Query system views periodically to track database health
- Alerting: Set up alerts for stale materialized views
- Capacity Planning: Use system views to forecast storage needs
- Performance Tuning: Identify large indexes for potential optimization
Compatibility
System views are compatible with PostgreSQL monitoring tools and follow PostgreSQL naming conventions (pg_* prefix).
Performance
All system views execute in < 1ms for typical deployments:
- Branches: O(n) where n < 100
- Materialized views: O(n) where n < 50
- Vector indexes: O(n) where n < 20
Implementation Status
All system views are fully implemented and return real data:
- pg_database_branches: Queries BranchManager for branch metadata
- pg_mv_staleness: Queries MaterializedViewCatalog for MV metadata
- pg_vector_index_stats: Queries VectorIndexManager for index statistics
Implementation details: /home/claude/HeliosDB Nano/SYSTEM_VIEW_DATA_POPULATION_COMPLETE.md
See Also
- [System View Data Population Complete](/home/claude/HeliosDB Nano/SYSTEM_VIEW_DATA_POPULATION_COMPLETE.md)
- [System View Execution Implementation](/home/claude/HeliosDB Nano/docs/implementation/SYSTEM_VIEW_EXECUTION_SUMMARY.md)
- [Branch Storage Guide](/home/claude/HeliosDB Nano/docs/BRANCH_STORAGE_GUIDE.md)
- [Materialized Views Implementation](/home/claude/HeliosDB Nano/MATERIALIZED_VIEWS_IMPLEMENTATION.md)