Storage Accounting
DB9 provides built-in storage accounting through virtual tables that show how much space your data, indexes, and metadata consume. Storage stats are filled in by a background scan.
Virtual Tables
Section titled “Virtual Tables”_DB9_SYS_STORAGE_STATS
Section titled “_DB9_SYS_STORAGE_STATS”Database-level storage breakdown.
SELECT database_name, data_bytes, index_bytes, metadata_bytes, total_bytes, scanned_atFROM _DB9_SYS_STORAGE_STATS;| Column | Type | Description |
|---|---|---|
database_id | TEXT | Database identifier. |
database_name | TEXT | Database name. |
data_bytes | BIGINT | Bytes used by table data. |
index_bytes | BIGINT | Bytes used by indexes. |
metadata_bytes | BIGINT | Bytes used by system metadata. |
total_bytes | BIGINT | Sum of data + index + metadata bytes. |
scanned_at | TIMESTAMP | When the last scan completed. |
scan_duration_ms | BIGINT | Duration of the last scan in milliseconds. |
_DB9_SYS_TABLE_STORAGE_STATS
Section titled “_DB9_SYS_TABLE_STORAGE_STATS”Per-table storage breakdown.
SELECT table_name, data_bytes, index_bytes, total_bytesFROM _DB9_SYS_TABLE_STORAGE_STATSORDER BY total_bytes DESC;| Column | Type | Description |
|---|---|---|
database_id | TEXT | Database identifier. |
table_id | TEXT | Internal table identifier. |
table_name | TEXT | Table name. |
data_bytes | BIGINT | Bytes used by this table’s data. |
index_bytes | BIGINT | Bytes used by this table’s indexes. |
total_bytes | BIGINT | Sum of data + index bytes. |
scanned_at | TIMESTAMP | When the last scan completed. |
Manual Refresh
Section titled “Manual Refresh”PostgreSQL-style manual scans are requested with:
SELECT db9_refresh_storage_stats();Automatic Reconciliation
Section titled “Automatic Reconciliation”Storage stats are refreshed by a background worker on a 30-minute cycle. No configuration is required — where the worker is running, the system keeps stats reasonably up-to-date without manual intervention. Where it is not, the tables stay empty.
Practical Examples
Section titled “Practical Examples”Check total database size:
SELECT database_name, total_bytes, round(total_bytes::numeric / 1024 / 1024, 2) AS total_mb, scanned_atFROM _DB9_SYS_STORAGE_STATS;Find the largest tables:
SELECT table_name, round(data_bytes::numeric / 1024 / 1024, 2) AS data_mb, round(index_bytes::numeric / 1024 / 1024, 2) AS index_mb, round(total_bytes::numeric / 1024 / 1024, 2) AS total_mbFROM _DB9_SYS_TABLE_STORAGE_STATSORDER BY total_bytes DESCLIMIT 10;Monitor index-to-data ratio:
SELECT table_name, CASE WHEN data_bytes > 0 THEN round(index_bytes::numeric / data_bytes, 2) ELSE 0 END AS index_ratioFROM _DB9_SYS_TABLE_STORAGE_STATSWHERE total_bytes > 0ORDER BY index_ratio DESC;Next Steps
Section titled “Next Steps”- Observability — Query metrics and live inspection
- Limits & Quotas — Storage limits per tenant
- Built-in Functions — db9_refresh_storage_stats() reference