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.

Was this article helpful? We need your support to keep MasterTheBoss alive!