home/docs/help/h2.md
⚠️ CRITICAL SECURITY WARNING: H2 Database is NOT suitable for production environments. It is provided for local testing and development purposes only. Using H2 in production exposes your server to serious security vulnerabilities. Please read this page carefully before using H2 with HertzBeat.
H2 is an open-source Java SQL database. HertzBeat ships with H2 as its default embedded database to enable quick testing and evaluation without requiring a separate database installation.
H2 has a built-in feature called CREATE ALIAS that allows arbitrary Java code execution within database queries. This means:
-- Example of EXTREMELY dangerous H2 capability:
CREATE ALIAS EXEC AS $$
String exec(String cmd) throws Exception {
Runtime.getRuntime().exec(cmd);
return null;
}
$$;
-- This can execute shell commands on the server:
CALL EXEC('rm -rf /important-data');
If your HertzBeat H2 database is accessible to malicious actors (or even unauthorized internal users), they can:
📖 For complete details, read the official H2 Security Documentation.
H2 can run in server mode, potentially exposing a database management interface on the network. By default, H2 uses ports 8082 (web console) and 9092 (TCP server). If these are accessible externally, any user can connect directly to your database.
For production use, migrate to one of these supported databases:
CREATE DATABASE hertzbeat;
CREATE USER 'hertzbeat'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON hertzbeat.* TO 'hertzbeat'@'localhost';
FLUSH PRIVILEGES;
application.yml:spring:
datasource:
url: jdbc:mysql://localhost:3306/hertzbeat?useUnicode=true&characterEncoding=utf-8
username: hertzbeat
password: strong_password_here
driver-class-name: com.mysql.cj.jdbc.Driver
ext-lib/📖 See the full MySQL monitoring guide for setup details.
CREATE USER hertzbeat WITH PASSWORD 'strong_password_here';
CREATE DATABASE hertzbeat OWNER hertzbeat;
GRANT ALL PRIVILEGES ON DATABASE hertzbeat TO hertzbeat;
application.yml:spring:
datasource:
url: jdbc:postgresql://localhost:5432/hertzbeat
username: hertzbeat
password: strong_password_here
driver-class-name: org.postgresql.Driver
ext-lib/📖 See the full PostgreSQL monitoring guide for setup details.
If you are using H2 for testing purposes in a sandboxed environment, the default HertzBeat configuration uses H2 with these settings:
| Configuration | Default Value | Description |
|---|---|---|
| Database type | H2 | Embedded Java database |
| Database file | ./data/hertzbeat | Local file storage |
| Web console | Port 8082 | H2 web management UI |
| Auto-create | Enabled | Creates schema automatically |
View your current database configuration in application.yml:
spring:
datasource:
# H2 configuration (testing only)
url: jdbc:h2:./data/hertzbeat
driver-class-name: org.h2.Driver
If you absolutely must use H2 while transitioning to a production database, take these precautions:
# Disable H2 web console in application.yml:
spring:
h2:
console:
enabled: false # IMPORTANT: Disable in any non-local environment
Before deploying HertzBeat in any non-testing environment, verify:
If you need help migrating from H2 to a production database:
Remember: The convenience of H2 for testing comes at the cost of security. Always plan to migrate to a production-grade database before deploying HertzBeat in any real environment.