tags:

views:

25

answers:

1

Does anyone know of a way to shrink/compact a db4o database?

Thanks, John

+3  A: 

What do you mean by compact/shrink? Make an existing database smaller? Or do you want to compress the database?

One of roles for this is defragmentation. This frees up unused space in the database. When you delete objects, the database doesn't shrink. Instead the space is marked as free for new objects. However overtime with a the manipulation of the database the file get fragmented. So defragmentation brings back unused space in the database.

When you store a lot of strings, you should consider using UTF8 encoding instead of default full unicode. This saves a lot of space, because a now a character uses only one byte.

EmbeddedConfiguration config = Db4oEmbedded.newConfiguration();
config.common().stringEncoding(StringEncodings.utf8());
ObjectContainer database = Db4oEmbedded.openFile(config,"database.db4o");

Note that you cannot change this setting for existing databases! You need to defragment the database in order to change the string encoding.

To compress the database you could use a compressing storage-implementation. However I don't know any available implementation which does this.

Gamlor
well the reason I ask is because I am using a program called RSSOwl (off of sourceforge). The database for the program is now up to almost 2GB and I was told on their forums that it's possible to delete news items from the program, but that the db will never get smaller. SO if objects are being deleted from the database but the size is not shrinking I was assuming there must be some way to perfrom a compact or shrink operation. Just I can't find it...
John
db4o Defragment will do what you want. You should run it with the RSSOwl sources in the CLASSPATH. You may like to ask the RSSOwl guys to include Defragment in their product. It's really easy for them. It's just 3 lines that they have to add to their code and one more menu item for their app.
Carl Rosenberger
Wow... is there a utility to do this, or do I need to write up a small app?
John
What I meant was, is there a way to run the defrag on a standalone DB?
John
Afaik there's no standalone db4o deframentation-tool. Normally the application which uses db4o should take care of defragmenting the database. So basically you need to write a small application =/. I would ask the RSSOwl-guy if they've have a defrage-tool / option.
Gamlor