Skip to main content

About the H2 Database

H2 is the default relational database that Mango uses for storing system configuration, user accounts, data source and data point definitions, events, and other structured data. It is an embedded Java database that requires no external installation or configuration, making it ideal for getting started quickly.

When to Use H2

H2 is well suited for:

  • Evaluation and development -- Zero-configuration setup lets you start using Mango immediately.
  • Small deployments -- Systems with fewer than a few hundred data points and modest event volumes.
  • Embedded devices -- MangoES appliances where installing a separate database server is impractical.

For production systems with thousands of data points, high event volumes, or requirements for concurrent external database access, consider migrating to MySQL or PostgreSQL. See Database Conversions for migration instructions.

Database File Location

The H2 database file is stored at MA_HOME/databases/mah2.h2.db by default. The JDBC connection URL used by Mango is:

jdbc:h2:./databases/mah2

The database version number may appear in the filename (e.g., mah2.200.mv.db for H2 version 1.4.200). If you need to reference the file directly, check the databases/ directory for the actual filename.

H2 Built-In Features

H2 provides a number of useful built-in functions and tools. Full documentation is available at: http://www.h2database.com/html/functions.html

Exporting to CSV

You can export the contents of any table to a CSV file using the SQL console. The file will be created in the Mango root directory:

CALL CSVWRITE('h2export.csv', 'SELECT * FROM DATAPOINTS')

H2 Web Console

The H2 database includes its own web-based management tool. To enable it, add the following to your mango.properties file and restart Mango:

db.web.start=true

You can also start the H2 web console independently of Mango by running the provided scripts:

  • Windows: h2-web-console.bat
  • Linux/Mac: h2-web-console.sh

When connecting through the H2 console, use the JDBC URL that matches your database file:

jdbc:h2:./databases/mah2

Important Limitations

  • Single-process access -- H2 in embedded mode allows only one process to access the database at a time. If you try to start a second Mango instance pointing to the same database file, it will fail.
  • Backup requirements -- You must stop Mango before backing up the H2 database file directly. Use the built-in backup feature instead, which creates a consistent snapshot. See How to Restore an H2 Database Backup.
  • No remote connections -- The embedded H2 database does not accept network connections from external tools unless the H2 web console is enabled.
  • Performance at scale -- H2 can become a bottleneck on systems with very large event tables or frequent queries. Monitor database size under Administration > System Status > Server Info.

Common Issues

Wrong Username/Password After Upgrade

Some users upgrading from Mango 2.4.2 or earlier may encounter an authentication error for the H2 database. To resolve this, edit your mango.properties file and set the H2 database username and password to blank values.

Database Corruption

If Mango fails to start due to H2 database corruption, you can recover by:

  1. Renaming or moving the existing database file from MA_HOME/databases/.
  2. Starting Mango, which will create a fresh database.
  3. Logging in with the default credentials (admin / admin).
  4. Restoring from a backup using the system settings restore feature.

See How to Restore an H2 Database Backup for detailed recovery instructions.