J-Deq87
J-Deq87

Reputation: 101

How to start H2 database command line without PG server and Web Console?

I have the H2 database v1.4.199 on an AWS EC2 machine that I want to start in TCP mode via the command line, but it looks like by default the PG server and Web Console also start, which I don't want.

I'm using a very basic command to set the port. Here's the command and output:

$ java -cp h2*.jar org.h2.tools.Server -tcpPort 9092
TCP server running at tcp://10.1.64.202:9092 (only local connections)
PG server running at pg://10.1.64.202:5435 (only local connections)
Web Console server running at http://10.1.64.202:8082 (others can connect)
Failed to start a browser to open the URL http://10.1.64.202:8082: Browser detection failed, and java property 'h2.browser' and environment variable BROWSER are not set to a browser executable.

You can see the PG Server and Console Server are up, but I thought the PG Server and Web Console were something you had to explicitly enable? I also do not want outside connections to this H2 (my Java app is on the same EC2), so seeing that the console is configured so "others can connect" in the output is a bit concerning.

What's the right way to startup H2 to make this more restricted and safer?

edit: For more context a Java app on the localhost will connect with this code:

    String url = "jdbc:h2:tcp://localhost:9092/" + filePath + ";MODE=MYSQL;AUTO_RECONNECT=TRUE;DB_CLOSE_ON_EXIT=FALSE";

    return DataSourceBuilder.create()
        .username("sa")
        .url(url)
        .driverClassName(org.h2.Driver.class.getName()).build();

The Java app connects just fine, but it shouldn't need the PG server and web console to make it work.

Upvotes: 2

Views: 2693

Answers (1)

trashgod
trashgod

Reputation: 205785

The server's help option may offer some guidance:

 java -cp h2.jar org.h2.tools.Server -?

The output includes this:

Starts the H2 Console (web-) server, TCP, and PG server.
Usage: java org.h2.tools.Server <options>
When running without options, -tcp, -web, -browser and -pg are started.
…

The solution is to start the TCP server explicitly:

java -cp h2.jar org.h2.tools.Server -tcp -tcpPort 9092

Upvotes: 2

Related Questions