Storage Inspector
The Storage Inspector is a read-only diagnostics toolkit for understanding the physical state of a CSharpDB database (.db) and WAL (.db.wal) file.
It is CLI-first and deterministic:
- no data mutation
- machine-readable JSON output (
schemaVersion: "1.0") - fixed exit codes for automation
Scope (v1)
Diagnostics cover:
- database file header and page map
- B+tree page and cell structure checks
- WAL header/frame/checksum checks
- catalog and index-root reachability checks
Out of scope:
- repair/auto-fix
- compaction/vacuum
- on-disk format changes
Commands
Run commands through the CLI command mode:
csharpdb inspect <dbfile> [--json] [--out <file>] [--include-pages]
csharpdb inspect-page <dbfile> <pageId> [--json] [--hex]
csharpdb check-wal <dbfile> [--json]
csharpdb check-indexes <dbfile> [--index <name>] [--sample <n>] [--json]inspect supports --out to write JSON to a file.
Client/API/Admin
Client SDK methods (CSharpDB.Client):
InspectStorageAsync(path?, includePages?)CheckWalAsync(path?)InspectPageAsync(pageId, includeHex?, path?)CheckIndexesAsync(path?, indexName?, sampleSize?)
REST endpoints (CSharpDB.Api):
GET /api/inspectGET /api/inspect/walGET /api/inspect/page/{id}GET /api/inspect/indexes
Admin UI (CSharpDB.Admin):
- Sidebar
Storageaction opens the Storage tab - Displays header summary, page histogram, index checks, issue list, and page drill-down
- Also exposes maintenance actions plus backup/restore, with paths resolved on the connected host
Exit Codes
0: no warnings/errors1: warnings present, no errors2: one or more errors present64: invalid CLI usage/arguments
JSON Contract
All inspector JSON responses include:
schemaVersion(current:"1.0")
The top-level report object depends on the command:
inspect→DatabaseInspectReportinspect-page→PageInspectReportcheck-wal→WalInspectReportcheck-indexes→IndexInspectReport
issues entries use:
code(stable rule identifier)severity(Info,Warning,Error)message- optional
pageId - optional
offset
Integrity Rule IDs (v1)
Database/header/page checks
DB_HEADER_SHORTDB_HEADER_BAD_MAGICDB_HEADER_BAD_VERSIONDB_HEADER_BAD_PAGE_SIZEDB_PAGE_COUNT_MISMATCHDB_FILE_TRAILING_BYTESDB_PAGE_SHORT_READPAGE_HEADER_OUT_OF_RANGEPAGE_CELL_COUNT_OVERFLOWPAGE_CELL_CONTENT_START_OOBPAGE_CELL_CONTENT_OVERLAPPAGE_DUPLICATE_CELL_POINTERPAGE_CELL_POINTER_OOBCELL_VARINT_INVALIDCELL_HEADER_INVALIDCELL_TOTAL_SIZE_OOBLEAF_CELL_PAYLOAD_TOO_SMALLLEAF_CELL_KEY_OOBLEAF_CELL_PAYLOAD_OOBINTERIOR_CELL_PAYLOAD_TOO_SMALLINTERIOR_CELL_BYTES_OOBBTREE_LEAF_KEY_ORDERPAGE_TYPE_UNKNOWN
B+tree reachability/cross checks
SCHEMA_ROOT_MISSINGBTREE_CHILD_OUT_OF_RANGEBTREE_PAGE_MISSINGBTREE_PAGE_TYPE_INVALIDBTREE_NULL_CHILD_REFERENCECATALOG_ROOT_OUT_OF_RANGECATALOG_ROOT_MISSINGCATALOG_ROOT_BAD_PAGE_TYPECATALOG_ENTRY_PAYLOAD_SHORTCATALOG_TABLE_SCHEMA_DECODE_FAILEDCATALOG_INDEX_ENTRY_PAYLOAD_SHORTCATALOG_INDEX_SCHEMA_DECODE_FAILEDCATALOG_VIEW_SCHEMA_DECODE_FAILEDCATALOG_TRIGGER_SCHEMA_DECODE_FAILEDINDEX_NOT_FOUNDINDEX_ROOT_OUT_OF_RANGEINDEX_ROOT_MISSINGINDEX_ROOT_BAD_PAGE_TYPEINDEX_TABLE_MISSINGINDEX_COLUMN_MISSING
WAL checks
WAL_HEADER_SHORTWAL_HEADER_BAD_MAGICWAL_HEADER_BAD_VERSIONWAL_HEADER_BAD_PAGE_SIZEWAL_TRAILING_PARTIAL_FRAMEWAL_FRAME_HEADER_SHORTWAL_FRAME_PAGE_SHORTWAL_FRAME_SALT_MISMATCHWAL_FRAME_HEADER_CHECKSUM_MISMATCHWAL_FRAME_DATA_CHECKSUM_MISMATCHWAL_NO_COMMIT_MARKER
Examples
Human-readable summary:
csharpdb inspect mydata.dbMachine-readable JSON:
csharpdb inspect mydata.db --jsonWrite JSON report to file:
csharpdb inspect mydata.db --json --out inspect-report.jsonInspect one page including hex dump:
csharpdb inspect-page mydata.db 12 --hexCheck WAL state:
csharpdb check-wal mydata.dbCheck all indexes:
csharpdb check-indexes mydata.dbCheck one index:
csharpdb check-indexes mydata.db --index idx_users_name --jsonTroubleshooting
- If
check-walreports no WAL file, that is usually normal after clean close/checkpoint. - If DB checks report page-count mismatch with no errors, run
check-walto determine whether recent committed data still resides in WAL. - If checks run while a writer is active, warnings can appear due to concurrent file changes; rerun diagnostics after write activity stops.