The simplest way to defragment a db4o file would be:
.NET:
Defragment.defrag("filename")
The file must not be opened by another process during defragmentation!
This will move the file filename to filename.backup, then create a defragmented version of this file in the original position. If the backup file already exists, this will throw an IOException and no action will be taken.
You can also specify the backup filename manually:
.NET:
Defragment.Defrag(filename, backupfile);
For more detailed configuration of the defragmentation process, you can use a DefragmentConfig instance within the following methods:
.NET:
Defragment.Defrag(configuration);
Defragment.Defrag(configuration, listener);
You can use listener parameter to track problems during defragmentation process. For more information see Tracking Defragmentation Errors.
Defragmentation can throw IOException in the following situations: