I'm using a HSQLDB database in Java which stores files in a column defined as a BLOB.
When I add a table row with a file/BLOB to my table the .lobs file increases in size of the file/BLOB. When I add another file to my table it increases in size again (2 x BLOB size).
So, I implemented a test method which iterates 10 times and writes the same file to my table and deletes it right after the insert.
Now, my .lobs file is 10 x file size... even though I've deleted all the table rows which contained the file.
I've tried to execute CHECKPOINT DEFRAG but nothing happens. The .lobs file stay the same file size.
This worries me since my webapp I'm creating is going to write lots of files to my database and even if the table rows with the file (BLOB) will after a while get deleted the .lobs file will always increase or stay in the same size and eventually eat all my disk space.
Am I missing some setting or is this the expected behavior of HSQLDB and BLOBs?
Thanks a lot!
Kind regards, Andreas
This is normal.
All the deleted lob spaces are recorded. After a CHECKPOINT, the spaces are reused if you insert new lobs.
In a production database there are recurring cycles of insert and delete. In the log run, the .lobs file size will not exceed the actual size of the lobs in the database by a very large amount.
Update:
The reason for .lobs file to grow until a checkpoint is to allow data recovery in case there is a system crash.
HSQLDB version 2.3.0 and later versions truncate the .lobs file at CHECKPOINT if there is empty space at the end of the file after deleting the lobs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With