Jira Data Center is not starting due to corruption in H2 database
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The Jira application is unable to start due to corrupted h2 database.
Environment
All Jira versions on Server and Data Center.
Diagnosis
Jira is not starting and the following records are present in the logs:
1
2
com.atlassian.cache.CacheException: com.atlassian.jira.exception.DataAccessException: org.ofbiz.core.entity.GenericDataSourceException: SQL Exception while executing the following:SELECT attribute_name, attribute_value FROM PUBLIC.cwd_user_attributes WHERE user_id=\? AND directory_id=\? \(General error: "java.lang.IllegalStateException: Reading from cache:nio:/path/to/the/file/h2db.mv.db failed; file length \-1 read length 151 at 1262358528 \[1.4.185/1]"; SQL statement:
SELECT attribute_name, attribute_value FROM PUBLIC.cwd_user_attributes WHERE user_id=\? AND directory_id=\? \[50000-185]\)
Cause
The H2 database is provided for evaluation purposes only. As it is a flat file in memory type database, it is prone to data corruption, hence it must not be used in Production Environments.
Solution
Notice that in most cases it is not possible to recover the actual h2 database file as it's a flat file and if corruption occurred internally, the only way to recover is to restore from a backup (if it exists). Ultimately Jira should be connected to a production level database as explained in Connecting Jira applications to a database.
In critical situations, customers may wish to recover quickly and stay on H2 while planning to migrate to production level database. While H2 is unsupported, the following 2 options can be tried to restore Jira to its previous state in such a scenario:
Option 1: Restore from file level backup (i.e. if the referenced files were backed up regularly to another location)
Stop Jira
Move away the content of the $JIRA_HOME/database (referenced in the error) as a backup to another location
Restore the files from backup
Start Jira and perform full locked re-index
Option 2: Restore from xml backup
By default, automated backups are enabled in Jira (https://confluence.atlassian.com/adminjiraserver/automating-jira-application-backups-938847675.html), if the backup files exist, one can attempt recovering Jira from such a backup. First of all, check $JIRA_HOME/export for presence of .zip files. If automated backups are on, there will be a most recent .zip file, named for example 2021-Jan-23–1955.zip. These are your backup files and it should be possible to use one of them to restore Jira to last known good working state.
Stop Jira
Make a backup of the file {{dbconfig.xml}} located in {{$JIRA_HOME/}} i.e make a copy and rename it {{dbconfig.xmlbackup}}.
Move away the content of the $JIRA_HOME/database (referenced in the error) as a backup to another location - this will configure Jira to start fresh
Start Jira
Jira will start up and will show the configuration Wizard. Select H2 and continue setting up as though you're starting from scratch.
Once you're able to log into Jira, verify Jira works fine, i.e. you can create projects, issues, can comment etc.
Go to folder {{$JIRA_HOME/export}} folder, copy the most recent backup (e.g. 2021-Jan-23--1955.zip) to {{$JIRA_HOME/import}} folder.
Now in Jira go to Jira Administration -> System -> Restore System
Type the file name 2021-Jan-23–1955.zip
And click on *Restore* - if the restore works without any issues - problem solved at least temporarily. To resolve permanently to avoid a repetitive corruptions in future, please migrate to production level database as soon as possible
Was this helpful?