Statistics
ResolveStatistics returns diagnostic data about the database files. Pass a Stats flags value to select which metrics to populate; unrequested properties are null on the returned MemDbStatistics. Each requested flag triggers its own pass over the pointer list under a shared lock, so cost scales with dataset size and flag count. Request only what you need.
| Category | Flag | Type | Description |
|---|---|---|---|
| Count | FreshCount | int? | Number of fresh records |
StaleCount | int? | Records superseded by updates | |
DeletedCount | int? | Records marked deleted but not yet purged | |
| Total size | FreshSize | long? | Total byte footprint of fresh records |
StaleSize | long? | Total byte footprint of stale records | |
DeletedSize | long? | Total byte footprint of deleted records | |
| Max size | MaxFreshSize | int? | Largest fresh record in bytes |
MaxStaleSize | int? | Largest stale record in bytes | |
MaxDeletedSize | int? | Largest deleted record in bytes | |
| Min size | MinFreshSize | int? | Smallest fresh record in bytes |
MinStaleSize | int? | Smallest stale record in bytes | |
MinDeletedSize | int? | Smallest deleted record in bytes | |
| Avg size | AvgFreshSize | double? | Average fresh record size in bytes |
AvgStaleSize | double? | Average stale record size in bytes | |
AvgDeletedSize | double? | Average deleted record size in bytes | |
| Identity | LastId | long? | Last auto-increment id assigned |
Stats resolve = Stats.FreshCount | Stats.StaleCount | Stats.DeletedCount
| Stats.FreshSize | Stats.StaleSize | Stats.DeletedSize
| Stats.LastId;
using (var db = MemDb.Open<Person>("people"))
{
MemDbStatistics stats = db.ResolveStatistics(resolve);
}ResolveStatistics is only available on persisted databases — calling it on a volatile (no-path) instance throws.
Common patterns
Detecting write amplification. The ratio of StaleSize + DeletedSize to FreshSize is a useful proxy for how much disk space is being held by superseded record versions. When this ratio exceeds a chosen threshold, schedule a defrag.
var s = db.ResolveStatistics(Stats.FreshSize | Stats.StaleSize | Stats.DeletedSize);
// Requested flags guarantee non-null — .Value is safe here.
double waste = (double)(s.StaleSize!.Value + s.DeletedSize!.Value) / s.FreshSize!.Value;Deciding when to purge the cache. In long-running instances, monitor StaleCount + DeletedCount and call PurgeCache when accumulation exceeds a threshold proportional to your fresh record count.
Capacity planning. The .map file overhead is 12 + (39 × total record count) bytes regardless of record size or content. Combined with FreshSize + StaleSize + DeletedSize for the .db file, this gives an exact on-disk footprint.