H2 Database

active

by H2 Group (Thomas Mueller, Evgenij Ryazanov and contributors) · since 2005 · also known as H2, H2 Database Engine

Fast pure-Java SQL engine for embedded, in-memory and test databases, with compatibility modes.

relationalspatialdatabase engineopen source (copyleft)mature

Overview

H2 is a compact relational database written in Java that runs embedded in the JVM, in pure in-memory mode, or as a TCP/PG server. It is the default test database for Spring Boot and many Java frameworks because it starts in milliseconds and offers compatibility modes that imitate PostgreSQL, MySQL, Oracle, SQL Server and others closely enough for most ORM-level tests. The MVStore engine gives MVCC transactions and file persistence, and the 2.x line has steadily improved SQL standard coverage. It remains actively maintained with regular releases, but it is not a production server for high concurrency or large data.

Strengths & trade-offs

Strengths

  • +Starts in milliseconds; ideal for unit and integration tests
  • +Compatibility modes for PostgreSQL, MySQL, Oracle, SQL Server, DB2 dialects
  • +Single small JAR with built-in web console
  • +In-memory and file-backed modes share the same SQL
  • +Java functions and triggers run in-process

Trade-offs

  • −Compatibility modes are approximations; tests can pass on H2 and fail on the real database
  • −Major versions change the file format, requiring export/import
  • −Not designed for concurrent multi-user production workloads
  • −Java-only client access in practice

Great for

  • +Integration tests for Spring/JPA applications
  • +Embedded storage in Java desktop tools
  • +Prototyping before choosing a production database
  • +In-memory scratch databases in batch jobs

Think twice for

  • −Production multi-user servers
  • −Non-JVM applications
  • −Validating database-specific SQL behavior

Capabilities

Native or official first-party support · 13 of 25 tracked

✓Transactions
✓Joins
✓Secondary indexes
✓Full-text search
✓Geospatial
✓JSON
✓Triggers
✓Stored procedures
✓In-memory
✓Durable persistence
✓Compression
✓Encryption at rest
✓Role-based access
–Vector search
–Change data capture
–Materialized views
–TTL / expiry
–Pub/Sub
–Columnar storage
–Time travel
–Branching
–Online schema changes
–Streaming ingest
–Offline sync
–Runs in WebAssembly

Scale & consistency

Comfortable data size
Small · ≤ 100 GB
Horizontal scaling
None
Multi-region
No
Transactions
Full ACID
Consistency
Strong
Schema
Strict
Architecture
Embedded, In memory, Client server, Single node
Query languages
SQL

Designed for a single JVM; databases of a few GB are comfortable.

Deployment

Self-hosted Vendor-managed cloud Serverless Embedded Edge Kubernetes operator

Ecosystem

apis & protocolsJDBC, PostgreSQL wire protocol (partial), ODBC via PG protocol
client languagesJava

Alternatives to H2 Database

Compare all→
HyperSQL (HSQLDB)Relational9.4

Long-running pure-Java SQL database with strong SQL:2023 coverage, used embedded and in LibreOffice.

h2 vs hsqldb →
SQLiteRelational75.5

The in-process SQL engine that ships in every phone, browser and OS: one file, zero servers.

h2 vs sqlite →
Apache DerbyRelational9.6

Pure-Java embedded SQL database from the Cloudscape lineage, retired by Apache in 2025.

h2 vs apache-derby →
DuckDBColumnar / OLAP63.7

In-process columnar SQL database: the SQLite of analytics, running inside your app or notebook.

h2 vs duckdb →
PostgreSQLRelational93.2

The extensible, standards-first open-source relational database.

h2 vs postgresql →
Microsoft AccessRelational45.8

Desktop database and forms builder bundled with Microsoft 365; still everywhere in back offices.

h2 vs microsoft-access →

H2 Database FAQ

What is H2 Database?

H2 Database is a relational database by H2 Group (Thomas Mueller, Evgenij Ryazanov and contributors), first released in 2005. H2 is a compact relational database written in Java that runs embedded in the JVM, in pure in-memory mode, or as a TCP/PG server. It is the default test database for Spring Boot and many Java frameworks because it starts in milliseconds and offers compatibility modes that imitate PostgreSQL, MySQL, Oracle, SQL Server and others closely enough for most ORM-level tests. The MVStore engine gives MVCC transactions and file persistence, and the 2.x line has steadily improved SQL standard coverage. It remains actively maintained with regular releases, but it is not a production server for high concurrency or large data.

Is H2 Database open source?

Yes. H2 Database is open source. License: MPL 2.0 or EPL 1.0 (dual).

Does H2 Database support ACID transactions?

Yes. H2 Database supports full ACID transactions, with strong consistency.

Does H2 Database scale horizontally?

H2 Database does not scale horizontally; it runs on a single node, so you scale it up rather than out. It is comfortable at small scale (≤ 100 GB).

How can I run H2 Database?

You can self-host it and embed it in your application.

What is H2 Database best for?

H2 Database is a strong fit for integration tests for Spring/JPA applications, embedded storage in Java desktop tools and prototyping before choosing a production database. Think twice for production multi-user servers.

What are the best alternatives to H2 Database?

Common alternatives to H2 Database include HyperSQL (HSQLDB), SQLite, Apache Derby, DuckDB and PostgreSQL. The right choice depends on your workload, scale and hosting; WhichDB's smart match ranks them against your requirements.

How popular is H2 Database?

H2 Database ranks #128 of 844 databases on the WhichDB Score (23.5/100), and #41 among relational databases. The score combines public adoption signals such as package downloads, GitHub activity, job posts and developer discussion.