1

If we are trying to host corda node database in a SQL server can we host all of them in a single database? If yes how to do it and what will be its impact.

Can the built in H2 database which gets generated while a node is deployed be stored locally in a system such that data becomes permanent and is not lost in the next build?

1
  • Good morning. Your question is more about server database configuration, while StackOverflow is more especially about programming. I'll forward your question to the ServerFault forum. Commented Oct 1, 2018 at 7:48

1 Answer 1

2

Sharing an H2 database

As of Corda 3, each node spins up its own H2 database by default.

However, you can point multiple nodes to a single, stand-alone H2 database as follows:

  • Start a standalone H2 instance (e.g. java -jar ./h2/bin/h2-1.4.196.jar -webAllowOthers -tcpAllowOthers)
  • In the node.conf node configuration file, set dataSource.url = "jdbc:h2:tcp://localhost:9092/~/nodeUniqueDatabaseName", where nodeUniqueDatabaseName is unique to that node

For each nodeUniqueDatabaseName, H2 will create a file nodeUniqueDatabaseName.mv.db in the user's home directory.

You can also set a specific absolute path as well (e.g. dataSource.url = "jdbc:h2:tcp://localhost:9092/~/Users/szymonsztuka/IdeaProjects/corda3/nodeUniqueDatabaseName"). This will create a database file under Users/szymonsztuka/IdeaProjects/corda3/.

Note that this approach is not secure since the h2 server is started with -webAllowOthers -tcpAllowOthers, meaning that anyone can log in and modify the database.

Maintaining data across node builds

The H2 database is discarded when re-running deployNodes, because you are considered to be creating an entirely new set of nodes. If you only want to make changes to the installed CorDapps, you can shut down the node, update its CorDapps (by creating the new CorDapp JARs as described here and copying the CorDapp JARs into its cordapps folder) and restart the node. The new CorDapps will be installed, but the old node data will still be present.

Sign up to request clarification or add additional context in comments.

2 Comments

@Joel..The node configuration has "database" property, which allows mentioning the schema name. So if we create separate schema and pointed each node to separate schema, I think it might be possible to host all node databases in single SQL server. I mean, technically it looks possible. They may not overwrite each others' tables. Use-case wise it may not make sense. Is my understanding correct?
Apologies, I was in error. You can use a single standalone H2 database for multiple nodes. Instructions above :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.