Shrinking an H2 Database
If you use an H2 database for Altus Director's data, the database should not be larger than a few megabytes. The H2 database grows when Altus Director runs over a long period of time because the database is not able to reclaim disk space when entries are deleted. As the database file grows larger, the risk of database corruption increases.
You can reduce the size of the H2 database by exporting and importing all the data using H2’s Script and RunScript commands.
- Back up the existing H2 database file.
- Stop Altus Director.
- Make a backup script using H2's Script command:
# Make a backup script (backup.zip) # NOTE: Do not include ‘.h2.db’ when specifying the db file $ java -cp <h2 jar file> org.h2.tools.Script -url \ "jdbc:h2:/var/lib/cloudera-director-server/state;MV_STORE=false; \ MVCC=true;DB_CLOSE_ON_EXIT=TRUE;AUTO_SERVER=TRUE;TRACE_LEVEL_FILE=4;TRACE_LEVEL_SYSTEM_OUT=0" \ -user sa -password sa -script backup.zip -options compression zip
- Delete the old database.
- Create a new, smaller database from the script using H2's RunScript command:
# Create a new database from the script (backup.zip) # NOTE: Do not include ‘.h2.db’ when specifying the db file $ java -cp <h2 jar file> org.h2.tools.RunScript -url \ "jdbc:h2:/var/lib/cloudera-director-server/state;MV_STORE=false; \ MVCC=true;DB_CLOSE_ON_EXIT=TRUE;AUTO_SERVER=TRUE;TRACE_LEVEL_FILE=4;TRACE_LEVEL_SYSTEM_OUT=0" \ -user sa -password sa -script backup.zip -options compression zip
- Start Altus Director.
For more information on H2 databases, see the H2 documentation at H2 Database Engine.