Question

I am using HSQLDB 2.3.0. I have a database that the following schema:

CREATE TABLE MEASUREMENT (ID INTEGER NOT NULL PRIMARY KEY IDENTITY, OBJ CLOB);

When I fill this table with test data, the LOBS file in my database grows:

ls -lath

-rw-rw-r-- 1 hsqldb hsqldb   35 May  6 16:37 msdb.log
-rw-rw-r-- 1 hsqldb hsqldb   85 May  6 16:37 msdb.properties
-rw-rw-r-- 1 hsqldb hsqldb   16 May  6 16:37 msdb.lck
drwxrwxr-x 2 hsqldb hsqldb 4.0K May  6 16:37 msdb.tmp
-rw-rw-r-- 1 hsqldb hsqldb 1.6M May  6 16:37 msdb.script
-rw-rw-r-- 1 hsqldb hsqldb 625M May  6 16:35 msdb.lobs

After running the following command:

TRUNCATE SCHEMA public AND COMMIT;
CHECKPOINT DEFRAG;
SHUTDOWN COMPACT;

The lobs file is still the same size:

-rw-rw-r-- 1 hsqldb hsqldb   84 May  6 16:44 msdb.properties
-rw-rw-r-- 1 hsqldb hsqldb 1.6M May  6 16:44 msdb.script
-rw-rw-r-- 1 hsqldb hsqldb 625M May  6 16:35 msdb.lobs

What is the best way to truncate the schema and get all the disk space back?

Was it helpful?

Solution 2

The database engine is designed for continuous use in real applications. If you have an application that uses lobs and deletes some of them, the space will be reused for future lobs after each checkpoint.

In normal application use, the DELETE statement is used to delete rows. This statement deallocates the lob space for reuse after each checkpoint.

You can design your tests in a way that recreates the database, rather than reuse the old database after removing the data.

OTHER TIPS

I have an application with the same problem using hsqldb 2.3.3. The .lobs file seems to be growing indefinatly even after calling "checkpoint defrag". My scenario is that I'm inserting a 1000 blobs of 300 bytes each. I'm periodically deleting them all and inserting a 1000 new blobs about the same size. After a number of rounds of this my .lobs file is now 1,3GB in size but it is really just storing around 300kB of data. Inspite of calling checkpoint defrag the .lobs file just grows and grows. Is this behavoiur a bug?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top