# Change to PostgreSQL By default, WSO2 Identity Server uses the embedded H2 database as the database for storing user management and registry data. Given below are the steps you need to follow in order to use PostgreSQL for this purpose. --- ## DatasourceĀ configurations {% include "../../../../includes/datasource-config.md" %} After setting up the PostgreSQL database, you can point the `WSO2_IDENTITY_DB` or `WSO2_SHARED_DB` or both to that PostgreSQL database by following the instructions given below. --- ## Change the default datasource ### Minimum configurations for changing the default datasource to PostgreSQL You can configure the datasource by editing the default configurations in `/repository/conf/deployment.toml`. Following are the basic configurations and their descriptions. {% include "../../../../includes/db-basic-config.md" %} A sample configuration is given below. 1. `WSO2_IDENTITY_DB` 1. Configure the `deployment.toml` file. ``` toml [database.identity_db] type = "postgre" hostname = "localhost" name = "testdb" username = "regadmin" password = "regadmin" port = "5432" ``` 2. Execute database scripts. Execute the scripts in the following files, against the database created. - `/dbscripts/identity/postgresql.sql` - `/dbscripts/consent/postgresql.sql` !!! info For stored procedures, use the scripts in the `/dbscripts/identity/stored-procedures/postgresql/postgre-11x` folder. The supported PostgreSQL versions (15.10, 16.6, 17.4) are compatible with the 11x stored procedures. 2. `WSO2_SHARED_DB` 1. Configure the `deployment.toml` file. ``` toml [database.shared_db] type = "postgre" hostname = "localhost" name = "testdb" username = "regadmin" password = "regadmin" port = "5432" ``` 2. Execute database scripts. Execute the scripts in the `/dbscripts/postgresql.sql` file against the database created. 3. Download the [PostgreSQL JDBC driver](https://mvnrepository.com/artifact/org.postgresql/postgresql) and copy the JAR (postgresql-x.x.x.jar) to the `/repository/components/lib` folder. --- ### Advanced database configurations Apart from the basic configurations specified above, WSO2 Identity Server supports some advanced database configurations as well. - `WSO2_IDENTITY_DB` related configurations that should be added to the `deployment.toml` file. ``` toml [database.identity_db.pool_options] maxActive = "80" maxWait = "60000" minIdle ="5" testOnBorrow = true validationQuery="SELECT 1; COMMIT" validationInterval="30000" defaultAutoCommit=false commitOnReturn=true ``` - `WSO2_SHARED_DB` `deployment.toml` related configurations that should be added to the `deployment.toml` file. ```toml [database.shared_db.pool_options] maxActive = "80" maxWait = "60000" minIdle ="5" testOnBorrow = true validationQuery="SELECT 1; COMMIT" validationInterval="30000" defaultAutoCommit=false commitOnReturn=true ``` {% include "../../../../includes/db-config-table.md" %} --- ## Configure the connection pool behavior on return {% include "../../../../includes/connection-pool-behavior.md" %} ### Configure the connection pool to commit pending transactions on connection return {% include "../../../../includes/commit-pending.md" %} ### Configure the connection pool to rollback pending transactions on connection return {% include "../../../../includes/rollback-pending.md" %} ## Driver-Level Timeouts (Recommended for Production) {% include "../../../../includes/driver-level-timeouts.md" %} ### Example: PostgreSQL database ```toml [database.identity_db] url = "jdbc:postgresql://DB_HOST:5432/WSO2_IDENTITY_DB?connectTimeout=10&socketTimeout=60&tcpKeepAlive=true" username = "..." password = "..." driver = "org.postgresql.Driver" ``` Learn more in [PostgreSQL JDBC connection parameters](https://jdbc.postgresql.org/documentation/use/#connection-parameters){: target="_blank"}.