---
title: "Get Connected to SQL Data Sources"
description: "Integrate with SQL data sources like PostgreSQL, Microsoft SQL Server and Oracle."
url: "https://curity.io/resources/learn/using-sql-data-sources/"
date: "2026-06-01"
area: "tutorials"
topic: "howtos"
pagegroup: "data-management"
---

# Get Connected to SQL Data Sources

This tutorial explains the basic steps to connect the Curity Identity Server to a SQL database. The content includes some demo local deployments for development computers. Once connected, you can plan your real database deployments.

## Create a Default Configuration

First, follow these getting started tutorials.

-   Get a license file, run an [Install using Docker](https://curity.io/resources/learn/run-curity-docker/) and sign into the Admin UI.
-   Run the [First Configuration](https://curity.io/resources/learn/first-config/), select `All Options` and accept all default settings.
-   [Export Configuration](https://curity.io/resources/learn/import-export-config/) so that you have a `curity-config.xml` file.

## Get Schema Creation Scripts

Get the schema initialization script from the `$IDSVR_HOME/etc` folder of the Curity Identity Server. For example, you can run the following Docker commands.

```bash
docker pull curity.azurecr.io/curity/idsvr
docker run --name curity -d -e PASSWORD=Password1 curity.azurecr.io/curity/idsvr
docker cp curity:/opt/idsvr/etc/ ./etc/
docker rm --force curity
```

Study the resources and view the SQL schema creation script for your preferred provider, to understand details like tables and columns. In some deployments you may need to provide this script to a database administrator (DBA).

```text
postgres-create_database.sql
mssql-create_database.sql
mysql-create_database.sql
oracle-create_database.sql
```

## Create the Database Schema

Instead of running SQL scripts, you can automate schema creation with the [Liquibase](https://www.liquibase.com/) tool, which you can read more about in the [Upgrade Data Sources](https://curity.io/resources/learn/upgrade-data-sources/) tutorial. On every deployment of the Curity Identity Server, run another instance of the Curity Identity Server as a job container. The job container uses high privilege database credentials to run commands that install or upgrade the database schema if required, after which the job container terminates.

You can save the following content to a bash script named `init.sh` to run in a job container. Run `chmod +x init.sh` to make the script executable. The example script first uses a sleep statement, for cases where the database server takes a long time to start up. The `idsvr -I` command creates the schema if required and upgrades it to the product version of the job container.

```bash
#!/bin/bash

echo '*** Waiting until the database server is ready ...'
sleep 30

echo '*** Creating and upgrading the schema for the Curity Identity Server ...'
idsvr -I
```

## Configure the Curity Identity Server

You can configure data source details in the Admin UI by navigating to **Facilities** → **Data Sources**. The following sections instead demonstrate the XML configuration settings, so that you can plan rollouts to deployment pipelines.

**PostgreSQL**

Edit the `curity-config.xml` file and change the data source to configure a JDBC connection to your PostgreSQL server instance.

```xml
<facilities xmlns="https://curity.se/ns/conf/base">
  <data-sources>
    <data-source>
      <id>default-datasource</id>
      <jdbc xmlns="https://curity.se/ns/ext-conf/jdbc">
        <connection-string>jdbc:postgresql://dbserver/idsvr</connection-string>
        <standard-credentials-mode>
        </standard-credentials-mode>
        <driver>org.postgresql.Driver</driver>
        <password>Password1</password>
        <username>idsvruser</username>
      </jdbc>
    </data-source>
  </data-sources>
...    
</facilities>
```

**MySQL / MariaDB**

Edit the `curity-config.xml` file and change the data source to configure a JDBC connection to your MySQL server instance.

```xml
<facilities xmlns="https://curity.se/ns/conf/base">
  <data-sources>
    <data-source>
      <id>default-datasource</id>
      <jdbc xmlns="https://curity.se/ns/ext-conf/jdbc">
        <connection-string>jdbc:mysql://dbserver:3306/idsvr</connection-string>
        <standard-credentials-mode>
        </standard-credentials-mode>
        <driver>com.mysql.jdbc.Driver</driver>
        <password>Password1</password>
        <username>idsvruser</username>
      </jdbc>
    </data-source>
  </data-sources>
...    
</facilities>
```

**Microsoft SQL Server**

Edit the `curity-config.xml` file and change the data source to configure a JDBC connection to your Microsoft SQL Server instance.

```xml
<facilities xmlns="https://curity.se/ns/conf/base">
  <data-sources>
    <data-source>
      <id>default-datasource</id>
      <jdbc xmlns="https://curity.se/ns/ext-conf/jdbc">
        <connection-string>jdbc:sqlserver://dbserver:1433;databaseName=idsvr;encrypt=false;sendStringParametersAsUnicode=false</connection-string>
        <standard-credentials-mode>
        </standard-credentials-mode>
        <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
        <password>Password1</password>
        <username>idsvruser</username>
      </jdbc>
    </data-source>
  </data-sources>
...    
</facilities>
```

**Oracle**

Edit the `curity-config.xml` file and change the data source to configure a JDBC connection to your database. The following example uses the default pluggable database that the free Oracle docker image provides.

```xml
<facilities xmlns="https://curity.se/ns/conf/base">
  <data-sources>
    <data-source>
      <id>default-datasource</id>
      <jdbc xmlns="https://curity.se/ns/ext-conf/jdbc">
        <connection-string>jdbc:oracle:thin:@dbserver:1521/FREEPDB1</connection-string>
        <standard-credentials-mode>
        </standard-credentials-mode>
        <driver>oracle.jdbc.OracleDriver</driver>
        <password>Password1</password>
        <username>idsvruser</username>
      </jdbc>
    </data-source>
  </data-sources>
...    
</facilities>
```

## Run Example Deployments

The following examples provide getting started Docker deployments for a local computer, with working connections to the main JDBC database servers.

**PostgreSQL**

To initialize a local PostgreSQL database, save the following content to a `docker-compose.yml` file. Then run `docker compose up` to deploy the system.

```yaml
services:
  curity-data:
    image: postgres:latest
    hostname: dbserver
    container_name: dbserver
    environment:
      POSTGRES_USER: 'idsvruser'
      POSTGRES_PASSWORD: 'Password1'
      POSTGRES_DB: 'idsvr'

  curity-data-init:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: dbserverinitializer
    volumes:
      - ./init.sh:/tmp/init.sh    
    command: ["/tmp/init.sh"]
    environment:
      JDBC_URL: jdbc:postgresql://dbserver:5432/idsvr
      JDBC_USERNAME: 'idsvruser'
      JDBC_PASSWORD: 'Password1'

  curity-idsvr:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: idsvr
    ports:
      - 6749:6749
      - 8443:8443
    volumes:
      - ./license.json:/opt/idsvr/etc/init/license/license.json
      - ./curity-config.xml:/opt/idsvr/etc/init/config.xml
    environment:
      ADMIN: 'true'
```

Later, once you run flows that populate identity data, you can get a shell to the Docker container for the database server.

```bash
docker exec -it dbserver bash
```

Then connect to the database.

```bash
export PGPASSWORD=Password1 && psql -p 5432 -d idsvr -U idsvruser
```

Then run database queries to view the data.

```sql
SELECT * FROM accounts;
```

**MySQL / MariaDB**

To initialize a local MySQL database, first download the JDBC driver from either [MySQL](https://dev.mysql.com/downloads/connector/j/) or [MariaDB](https://mariadb.com/kb/en/about-mariadb-connector-j/). Then, save the following content to a `docker-compose.yml` file. Run `docker compose up` to deploy the system.

```yaml
services:
  curity-data:
    image: mysql:latest
    hostname: dbserver
    container_name: dbserver
    environment:
      MYSQL_ROOT_PASSWORD: Password1
      MYSQL_DATABASE: idsvr
      MYSQL_USER: idsvruser
      MYSQL_PASSWORD: Password1

  curity-data-init:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: dbserverinitializer
    volumes:
      - ./mysql-connector-j-9.7.0.jar:/opt/idsvr/lib/plugins/data.access.jdbc/mysql-connector-j-9.7.0.jar
      - ./init.sh:/tmp/init.sh
    command: ["/tmp/init.sh"]
    environment:
      JDBC_URL: jdbc:mysql://dbserver:3306/idsvr
      JDBC_USERNAME: 'idsvruser'
      JDBC_PASSWORD: 'Password1'

  curity-idsvr:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: idsvr
    ports:
     - 6749:6749
     - 8443:8443
    volumes:
      - ./license.json:/opt/idsvr/etc/init/license/license.json
      - ./curity-config.xml:/opt/idsvr/etc/init/config.xml
      - ./mysql-connector-j-9.7.0.jar:/opt/idsvr/lib/plugins/data.access.jdbc/mysql-connector-j-9.7.0.jar
    environment:
      ADMIN: 'true'
```

Later, once you run flows that populate identity data, you can get a shell to the Docker container for the database server.

```bash
docker exec -it dbserver bash
```

Then connect to the database.

```bash
mysql -h dbserver -u idsvruser -pPassword1 idsvr
```

Then run database queries to view the data.

```sql
SELECT * FROM accounts;
```

**Microsoft SQL Server**

To deploy a local development instance of Microsoft SQL Server, create a script named `createdatabaseanduser.sql` with the following content.

```sql
USE master;
GO

CREATE LOGIN idsvruser WITH PASSWORD = 'Password1';
GO

CREATE DATABASE idsvr;
GO

USE idsvr;
GO

CREATE USER idsvruser FOR LOGIN idsvruser;
GO

EXEC sp_addrolemember 'db_datareader', 'idsvruser';
GO

EXEC sp_addrolemember 'db_datawriter', 'idsvruser';
GO
```

To initialize a local Microsoft SQL Server database, save the following content to a `docker-compose.yml` file. Then run `docker compose up` to deploy the system.

```yaml
services:
  curity-data:
    image: mcr.microsoft.com/mssql/server:2025-latest
    hostname: dbserver
    container_name: dbserver
    volumes:
      - ./createdatabaseanduser.sql:/tmp/createdatabaseanduser.sql
    environment:
      ACCEPT_EULA: Y
      MSSQL_PID: Developer
      MSSQL_SA_PASSWORD: Password1
    command: |
      bash -c '
      /opt/mssql/bin/sqlservr &

      sleep 20
      echo "*** Creating database and user ..."
      /opt/mssql-tools18/bin/sqlcmd -U sa -P Password1 -d idsvr -C -I -i /tmp/createdatabaseanduser.sql
      wait
      '

  curity-data-init:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: dbserverinitializer
    volumes:
      - ./init.sh:/tmp/init.sh
    command: ["/tmp/init.sh"]
    environment:
      JDBC_URL: jdbc:sqlserver://dbserver:1433;databaseName=idsvr;encrypt=false;sendStringParametersAsUnicode=false
      JDBC_USERNAME: 'sa'
      JDBC_PASSWORD: 'Password1'

  curity-idsvr:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: idsvr
    ports:
      - 6749:6749
      - 8443:8443
    volumes:
      - ./license.json:/opt/idsvr/etc/init/license/license.json
      - ./curity-config.xml:/opt/idsvr/etc/init/config.xml
    environment:
      ADMIN: 'true'
```

Later, once you run flows that populate identity data, you can get a shell to the Docker container for the database server.

```bash
docker exec -it dbserver bash
```

Next, get an interactive shell as the Curity Identity Server user.

```bash
/opt/mssql-tools18/bin/sqlcmd -U idsvruser -P Password1 -d idsvr -I -C
```

Then, run database queries on identity data.

```sql
SELECT * FROM accounts;
GO
```

**Oracle**

To initialize a local Oracle database, first download the [Oracle JDBC Driver](https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html). Then create a script named `createuser.sql` that creates the database user for the Curity Identity Server. The following script provides a quick example for a demo deployment on a local computer.

```sql
ALTER SESSION SET container=FREEPDB1;

CREATE USER idsvruser IDENTIFIED BY Password1;
GRANT DBA TO idsvruser;
```

You could then create the following `docker-compose.yml` file, which uses bash commands to start Oracle and create the user. Make sure you update the `JAVA_OPTS` environment variable to enable the correct serialization. Then run `docker compose up` to deploy the system and wait a few minutes for database initialization to complete.

```yaml
services:
  curity-data:
    image: container-registry.oracle.com/database/free:latest-lite
    hostname: dbserver
    container_name: dbserver
    volumes:
      - ./createuser.sql:/tmp/createuser.sql
    environment:
      ORACLE_PWD: Password1
    command: |
      bash -c '
      /opt/oracle/runOracle_lite.sh &

      sleep 20
      echo "*** Creating database users ..."
      sqlplus / as sysdba @/tmp/createuser.sql
      wait
      '

  curity-data-init:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: dbserverinitializer
    volumes:
      - ./ojdbc17.jar:/opt/idsvr/lib/plugins/data.access.jdbc/ojdbc17.jar
      - ./init.sh:/tmp/init.sh
    command: ["/tmp/init.sh"]
    environment:
      JDBC_URL: jdbc:oracle:thin:@dbserver:1521/FREEPDB1
      JDBC_USERNAME: 'idsvruser'
      JDBC_PASSWORD: 'Password1'
      JAVA_OPTS: -Dse.curity:identity-server:serialFilter=oracle.jdbc.**
  
  curity-idsvr:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: idsvr
    ports:
      - 6749:6749
      - 8443:8443
    volumes:
      - ./license.json:/opt/idsvr/etc/init/license/license.json
      - ./curity-config.xml:/opt/idsvr/etc/init/config.xml
      - ./ojdbc17.jar:/opt/idsvr/lib/plugins/data.access.jdbc/ojdbc17.jar
    environment:
      ADMIN: 'true'
      JAVA_OPTS: -Dse.curity:identity-server:serialFilter=oracle.jdbc.**
```

Later, once you run flows that populate identity data, you can get a shell to the Docker container for the database server.

```bash
docker exec -it dbserver bash
```

Next, connect to an Oracle shell as the Curity Identity Server user.

```bash
sqlplus idsvruser/Password1@FREEPDB1
```

Then, run database queries on identity data.

```sql
SELECT * FROM "accounts";
```

## Finalize Deployments

Once connected, plan deployments to real environments that follow the provider's database best practices. Configure a high privilege database user with which to make schema changes, and run the Curity Identity Server as a separate low privilege database user. Use strong database credentials and encrypt data at rest. See the product documentation for details on the [Database System Requirements](https://curity.io/docs/identity-server/system-and-operation/deployment/system-requirements/#database) and the finer details for each [JDBC Data Source](https://curity.io/docs/identity-server/facilities/data-sources/jdbc/).

Finally, use the techniques in the [Configuration as Code](https://curity.io/resources/learn/gitops-configuration-management/) tutorial to finalize the database configuration for deployed systems. Use parameterized configuration and cryptographically protect sensitive database values.

```xml
<facilities xmlns="https://curity.se/ns/conf/base">
    <data-sources>
      <data-source>
        <id>default-datasource</id>
        <jdbc xmlns="https://curity.se/ns/ext-conf/jdbc">
          <connection-string>#{DB_CONNECTION}</connection-string>
          <standard-credentials-mode>
          </standard-credentials-mode>
          <driver>#{DB_DRIVER}</driver>
          <password>#{DB_PASSWORD}</password>
          <username>#{DB_USER}</username>
          <use-for-audit>true</use-for-audit>
        </jdbc>
      </data-source>
    </data-sources>
...    
</facilities>
```

## Summary

The Curity Identity Server supports the main transactional databases that organizations use for their business data. You can deploy identity data anywhere and follow the same processes and techniques for both business data and identity data. For example, you can use the same database administration standards, for operations like encrypting data at rest, clustering and snapshotting.
