System Info

SystemInfo is a utility class, providing system information about db4o database.

Currently SystemInfo includes the following methods:

Method

Functionality

freespaceSize

returns the freespace size in the database in bytes. When db4o stores modified objects, it allocates a new slot for it. During commit the old slot is freed. Free slots are collected in the freespace manager, so they can be reused for other objects.

This method returns a sum of the size of all free slots in the database file.

To reclaim freespace run Defragment.

freespaceEntryCount

returns the number of entries in the Freespace Manager.A high value for the number of freespace entries is an indication that the database is fragmented and that Defragment should be run. 

totalSize

Returns the total size of the database on disk.

In order to get SystemInfo instance you must issue the following call:

c#:

ISystemInfo info = container.Ext().SystemInfo();

VB:

Dim info As ISystemInfo = container.Ext().SystemInfo()

SystemInfo can be used for different maintenance services. The example below presents a simple program, which can be scheduled to run automatically at certain intervals for a database check up. (To download the complete example, please press "download" button in the right upper corner of the code block).

SystemInfoExample.cs: TestSystemInfo
01private static void TestSystemInfo() 02 { 03 long dbSize = _container.Ext().SystemInfo().TotalSize(); 04 long fsSize = _container.Ext().SystemInfo().FreespaceSize(); 05 if (dbSize > MaxDbSize) 06 { 07 System.Console.WriteLine("Attention! Database file size is over the limit. Maintenance required"); 08 } 09 _logWriter.WriteLine("Total database size: " + dbSize); 10 if (fsSize > MaxFsSize) 11 { 12 System.Console.WriteLine("Attention! Freespace size is over the limit. Maintenance required"); 13 } 14 _logWriter.WriteLine("Database freespace size: " + fsSize); 15 _logWriter.WriteLine("Database freespace entries: " + _container.Ext().SystemInfo().FreespaceEntryCount()); 16 }
SystemInfoExample.vb: TestSystemInfo
01Private Shared Sub TestSystemInfo() 02 Dim dbSize As Long = _container.Ext().SystemInfo().TotalSize() 03 Dim fsSize As Long = _container.Ext().SystemInfo().FreespaceSize() 04 If dbSize > MaxDbSize Then 05 System.Console.WriteLine("Attention! Database file size is over the limit. Maintenance required") 06 End If 07 _logWriter.WriteLine("Total database size: " + dbSize.ToString()) 08 If fsSize > MaxFsSize Then 09 System.Console.WriteLine("Attention! Freespace size is over the limit. Maintenance required") 10 End If 11 _logWriter.WriteLine("Database freespace size: " + fsSize.ToString()) 12 _logWriter.WriteLine("Database freespace entries: " + _container.Ext().SystemInfo().FreespaceEntryCount().ToString()) 13 End Sub