使用 PostgreSQL 而不是 H2 作为 Corda 节点的数据库

Using PostgreSQL instead of H2 as the Corda node's database

我想使用 PostgreSQL 而不是 H2 作为我节点的数据库。是否可以将 PostgreSQL 用于 Corda 节点?我将如何配置我的节点以使用 PostgreSQL 数据库?

请指定您正在使用的版本,据我了解,如果您从 master 构建 Corda v3.0,则可以执行此操作。 实际上,您可以指定要在 Corda 中加载的 Jars 和您自定义的 jdbc 连接字符串,请参阅有关节点配置的更新文档: https://docs.corda.net/head/corda-configuration-file.html

Corda 2 和 Corda 3 都允许使用 PostgreSQL 9.6,使用 PostgreSQL JDBC Driver 42.1.4。请注意,这是一个实验性的社区贡献,目前未经测试。

这是 PostgreSQL 的示例节点配置块:

dataSourceProperties = {
    dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
    dataSource.url = "jdbc:postgresql://[HOST]:[PORT]/postgres"
    dataSource.user = [USER]
    dataSource.password = [PASSWORD]
}

database = {
    transactionIsolationLevel = READ_COMMITTED
    schema = [SCHEMA]
}

您需要将此块添加到节点的 node.conf 文件中,该文件位于节点文件夹的根目录中。

注意:

  • database.schema 属性 是可选的。它代表数据库的命名空间
  • database.schema 的值没有用双引号引起来,Postgres 始终将其视为 lower-case 值(例如 AliceCorp 变为 alicecorp

您可以使用 extraConfig=[ ... ] 块将 Postgresql 数据库属性添加到 build.gradle 脚本中的节点配置,如下所示。

node {

    ...

    extraConfig = [
        dataSourceProperties: [
                dataSourceClassName : "org.postgresql.ds.PGSimpleDataSource",
                'dataSource.url' : "jdbc:postgresql://localhost:5432/nodedb",
                'dataSource.user' : "postgres",
                'dataSource.password' : "pa$$w0rd"
        ],
        database: [
                transactionIsolationLevel : "READ_COMMITTED"
        ]
    ]
}