How to remove the H2 Database in WildFly

WildFly application server ships with a default in-Memory Database, the H2 DB. In this short article we will learn how to remove the H2 Database from WildFly / JBoss configuration correctly.

By default, WildFly ships with a Datasource which connects to an In-Memory H2 Database. You can see it from the following snippet:

<subsystem xmlns="urn:jboss:domain:datasources:7.1">
            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="false" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=${wildfly.h2.compatibility.mode:REGULAR}</connection-url>
                    <driver>h2</driver>
                    <security user-name="sa" password="sa"/>
                </datasource>
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>
 </subsystem>

You can learn more about H2 Database from this article: H2 Database Tutorial and expert Tips

In production environment, however, you should not include this subsystem as part of your configuration. Let’s see how to remove it.

Removing H2 from WildFly

The correct way to remove H2 is to remove it both from the Datasource/Drivers and from the default bindings of the ee subsystem:

/subsystem=ee/service=default-bindings/:undefine-attribute(name=datasource) 
/subsystem=datasources/data-source=ExampleDS/:remove
/subsystem=datasources/jdbc-driver=h2/:remove
reload

Finally, if you are using WildFly Bootable JAR to provision a WildFly Server, make sure that you are not including any of these layers in your configuration:

  • h2-datasource
  • h2-default-datasource
  • h2-driver

Conclusion

This article provided a quick overview on how to remove the H2 Database from a WildFly Server installation which is a recommended action when you are moving your applications to a production environment.


Recommended Articles

Effortlessly Export and Verify Data in Your In-Memory H2 Database Using Java

Discover how to export data from your in-memory H2 database using JPA and Spring Boot. Learn the SCRIPT command method for generating SQL scripts.

Configure MS SQL Server Datasource on WildFly Application Server

Learn how to configure Microsoft SQLServer Datasource on WildFly application server with step-by-step instructions and examples.

Visualize Database Connection Pool Performance with JDBC Performance Logger in WildFly and JBoss AS

Monitor database connections graphically and gain insights into your application's database activity using the free JDBC Performance Logger tool. Learn how to integrate it with WildFly and JBoss AS.

H2 Database Tutorial and Expert Tips

H2 Database tutorial: embedded, server and mixed mode explained, WildFly/JBoss EAP datasource setup, monitoring via the H2 Console, and fixes for the most common H2 errors (2.4.240).