Skip to content

Change the Default Datasource for Consent Management

WSO2 Identity Server is shipped with an embedded H2 database for storing data. These default databases are located in the <IS_HOME>/repository/database directory of the pack.

By default, consent management data is stored in the identity database (IDENTITY_DB) with Identity and UMA data. However, you can separate consent specific data into a separate datasource to any database type that is supported by WSO2 Identity Server.

Note

For more information about databases, see Work with Databases and Set Up Separate Databases for Clustering.

Following are the sample configuration for each database type.

PostgreSQL
  1. Configure the <IS-HOME>/repository/conf/deployment.toml file.

    [[datasource]]
    id="WSO2CONSENT_DB"
    url = "jdbc:postgresql://localhost:5432/gregdb"
    username = "regadmin"
    password = "regadmin"
    driver = "org.postgresql.Driver"
    jmx_enable=false
  2. Execute the database scripts.

    Execute the scripts in the <IS-HOME>/dbscripts/consent/postgresql.sql file against the created database.

MySQL
  1. Configure the <IS-HOME>/repository/conf/deployment.toml file.

    [[datasource]]
    id="WSO2CONSENT_DB"
    url = "jdbc:mysql://localhost:3306/IAMtest?useSSL=false"
    username = "root"
    password = "root"
    driver = "com.mysql.jdbc.Driver"
    jmx_enable=false
  2. Execute the database scripts.

    Execute the scripts in the <IS-HOME>/dbscripts/consent/mysql.sql file against the created database.

DB2
  1. Configure the <IS-HOME>/repository/conf/deployment.toml file.

    [[datasource]]
    id="WSO2CONSENT_DB"
    url = "jdbc:db2://192.168.108.31:50000/test"
    username = "db2inst1"
    password = "db2inst1"
    driver = "com.ibm.db2.jcc.DB2Driver"
    jmx_enable=false

  2. Execute the database scripts.

    Execute the scripts in the <IS-HOME>/dbscripts/consent/db2.sql file against the created database.

MSSQL
  1. Configure the <IS-HOME>/repository/conf/deployment.toml file.

    [[datasource]]
    id="WSO2CONSENT_DB"
    url = "jdbc:sqlserver://localhost:1433;databaseName=test;SendStringParametersAsUnicode=false"
    username = "sa"
    password = "pass#word2"
    driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jmx_enable=false

  2. Execute the database scripts.

    Execute the scripts in the <IS-HOME>/dbscripts/consent/mssql.sql file against the created database.

Oracle
  1. Configure the <IS-HOME>/repository/conf/deployment.toml file.

    [[datasource]]
    id="WSO2CONSENT_DB"
    url = "jdbc:oracle:thin:@localhost:1521/ORCLPDB"
    username = "IS590Test"
    password = "ora12c"
    driver = "oracle.jdbc.OracleDriver"
    jmx_enable=false

  2. Execute the database scripts.

    Execute the scripts in the <IS-HOME>/dbscripts/consent/oracle.sql file against the created database.


Advanced database configurations

Apart from above basic configurations, WSO2 Identity Server supports advanced database configurations. Add the following configurations to the <IS_HOME>/repository/conf/ deployment.toml file under the corresponding [[datasource]] tag.

pool_options.maxActive = "80"
pool_options.maxWait = "60000"
pool_options.minIdle = "5"
pool_options.testOnBorrow = true
pool_options.validationQuery="SELECT 1; COMMIT"
pool_options.validationInterval="30000"
pool_options.defaultAutoCommit=false
pool_options.maxActive = "80"
pool_options.maxWait = "60000"
pool_options.minIdle = "5"
pool_options.testOnBorrow = true
pool_options.validationQuery="SELECT 1"
pool_options.validationInterval="30000"
pool_options.defaultAutoCommit=false
pool_options.maxActive = "80"
pool_options.maxWait = "360000"
pool_options.minIdle = "5"
pool_options.testOnBorrow = true
pool_options.validationQuery="SELECT 1"
pool_options.validationInterval="30000"
pool_options.defaultAutoCommit=false
pool_options.maxActive = "80"
pool_options.maxWait = "60000"
pool_options.minIdle = "5"
pool_options.testOnBorrow = true
pool_options.validationQuery="SELECT 1"
pool_options.validationInterval="30000"
pool_options.defaultAutoCommit=false
pool_options.maxActive = "80"
pool_options.maxWait = "60000"
pool_options.minIdle = "5"
pool_options.testOnBorrow = true
pool_options.validationQuery="SELECT 1 FROM DUAL"
pool_options.validationInterval="30000"
pool_options.defaultAutoCommit=false

The elements in the above configuration are described below:

maxActive This is the maximum number of active connections that can be allocated at the same time from this pool. Enter any negative value to denote an unlimited number of active connections.
maxWait This is the maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception. You can enter zero or a negative value to wait indefinitely.
minIdle The minimum number of active connections that can remain idle in the pool without extra ones being created. Enter zero to create none.

testOnBorrow

This indicates whether objects will be validated before being borrowed from the pool. If the object fails to be validated, it will be dropped from the pool and another attempt will be made to borrow another.

defaultAutoCommit

Indicates whether to commit database changes automatically or not
validationInterval This is the indication to avoid excess validation and only run validation after the specified frequency (time in milliseconds). If a connection is due for validation, but has been validated previously within this interval, it will not be validated again.
defaultAutoCommit

This property is not applicable to the carbon database in WSO2 Identity Server because auto committing is usually handled at the code level, i.e., the default auto commit configuration specified for the RDBMS driver will be effective instead of this property element. Typically, auto committing is enabled for RDBMS drivers by default.

When auto committing is enabled, each SQL statement will be committed to the database as an individual transaction, as opposed to committing multiple statements as a single transaction.

Info

For more information on other parameters that can be defined in the <IS_HOME>/repository/conf/deployment.toml file, see Tomcat JDBC Connection Pool.

Once when we separate out the consent database from WSO2IdentityDB, we need to add the following configuration to the deployment.toml file to specify WSO2 Identity Server to use a separate datasource instead of the default IDENTITY_DB.

[authentication.consent]
data_source="jdbc/WSO2CONSENT_DB"

Sample Config

If you have correctly configured, the deployment.toml file should have an entry similar to the following config.

The following sample configuration is for a separate PostgreSQL consent management database.

[[datasource]]
id="WSO2CONSENT_DB"
url = "jdbc:postgresql://localhost:5432/gregdb"
username = "regadmin"
password = "regadmin"
driver = "org.postgresql.Driver"
jmx_enable=false
pool_options.maxActive = "80"
pool_options.maxWait = "60000"
pool_options.minIdle = "5"
pool_options.testOnBorrow = true
pool_options.validationQuery="SELECT 1"
pool_options.validationInterval="30000"
pool_options.defaultAutoCommit=false

[authentication.consent]
data_source="jdbc/WSO2CONSENT_DB"
Top