Quantcast
Channel: database – Tech ABC to XYZ
Viewing all articles
Browse latest Browse all 31

Why is an empty H2 database 2 MB in size? [ANSWERED]

$
0
0

Why is an empty H2 database 2 MB in size?

Asked By: Mike Flynn
Originally Asked On: 2014-01-06 02:35:07
Asked Via: stackoverflow

I’m building an application that uses an embedded H2 database. I used the tutorial to test it out and everything seemed to work fine:

import java.sql.*;
public class Test {
    public static void main(String[] a)
            throws Exception {
        Class.forName("org.h2.Driver");
        Connection conn = DriverManager.
            getConnection("jdbc:h2:~/test", "sa", "");
        // add application code here
        conn.close();
    }
}

I am curious however, in my home directory I now have a “test.h2” file along with a “test.lock” file. Why does an empty database end up being 2 MB? It seems kind of large, I would expect something in KB at most, given that all that is in it would be some default empty memory and some instructions for storing data in it. Is 2 MB the default memory allocated?

He received 1 answers
eventually accepting:

Thomas Mueller’s answer to

Why is an empty H2 database 2 MB in size?

The database file size of an empty (or almost empty) database is only 2 MB while the database is open. If it is closed, the file shrinks.

On some file systems, resizing files is relatively slow. Because of that, H2 allocates more space than it needs: to reduce the number of resize operations.

The exact algorithm to expand the file size may change in the future. Currently, the minimum file size is about 2 MB. The file grows at 35%, but at most 256 MB at a time.

When you close the database, the file shrinks to the real size needed.

If the selected answer did not help you out, the other answers might!

All Answers For: Why is an empty H2 database 2 MB in size?

Thomas Mueller’s answer to

Why is an empty H2 database 2 MB in size?

The database file size of an empty (or almost empty) database is only 2 MB while the database is open. If it is closed, the file shrinks.

On some file systems, resizing files is relatively slow. Because of that, H2 allocates more space than it needs: to reduce the number of resize operations.

The exact algorithm to expand the file size may change in the future. Currently, the minimum file size is about 2 MB. The file grows at 35%, but at most 256 MB at a time.

When you close the database, the file shrinks to the real size needed.

Of course, you should really check out the original question.

The post Why is an empty H2 database 2 MB in size? [ANSWERED] appeared first on Tech ABC to XYZ.


Viewing all articles
Browse latest Browse all 31

Trending Articles