Which database should Keycloak use in production?
PostgreSQL is the usual choice for a production Keycloak, and it is the database most teams should plan around unless their organization already runs another supported engine well. The Keycloak database guide lists MariaDB, Microsoft SQL Server, MySQL, Oracle Database, PostgreSQL 14 to 18, EnterpriseDB Advanced, Amazon Aurora PostgreSQL and Azure SQL as supported production databases. Keycloak stores realms, users, clients, credentials, role mappings and persistent sessions in that database, so the engine you pick determines how you back it up, how you upgrade it, and how you build high availability. The default dev-file database is for development only and cannot take its place. Your first decision is therefore not the product but the engine, and the version of that engine, that your database team can operate for the life of the Keycloak deployment.
Make that choice against four questions. First, does your database team have a supported, tested backup and restore process for the engine, including point-in-time recovery? Second, can they keep the engine on a version Keycloak supports? The guide currently names PostgreSQL 14 through 18, so confirm the exact versions against the current guide before you commit, because the supported range changes over time. Third, what high availability design will you use? Keycloak's supported multi-site and single-cluster designs both need a synchronously replicated database, so check that your candidate engine and hosting platform can provide that. Fourth, is the engine licensed in a way your procurement accepts, and does a managed offering such as Amazon Aurora PostgreSQL or Azure SQL fit your hosting and data residency rules? Ask your vendor or cloud provider to confirm these capabilities for the exact version you plan to run.
Oracle Database is supported by Keycloak, but the Keycloak database guide notes that the Oracle JDBC driver is not bundled with the distribution, so you must add it to your image or deployment yourself and track its licensing. Plan this as a build task and a recurring maintenance item rather than a configuration setting. For any engine, test the driver and the schema migration in a staging environment that matches production before you go live. Whichever engine you choose, record the decision, the version and the owner in your Keycloak runbook, because the database choice drives the work described in the backup, upgrade and high availability sections that follow.
Supported database options and when each fits
This table compares the production databases listed in the Keycloak database guide by licensing, whether a driver ships with Keycloak, whether your team already runs the engine, and who supports it. Use it to shortlist options, then confirm the exact supported versions for your Keycloak release in the guide.
| Database | Licensing and driver | When it fits | Who supports it |
|---|---|---|---|
| PostgreSQL (14 to 18) | Open source under the PostgreSQL License; JDBC driver is bundled with Keycloak | Default choice for most self-managed deployments and teams already running PostgreSQL | PostgreSQL community, plus any commercial vendor or service you contract |
| EnterpriseDB Advanced | Commercial PostgreSQL-compatible distribution; confirm driver and version support in the guide | Organizations that already license EnterpriseDB and want vendor support on the same engine family | EnterpriseDB under its own agreement |
| Amazon Aurora PostgreSQL | Managed AWS service with PostgreSQL compatibility; confirm the exact Keycloak version support | Teams hosting Keycloak in AWS that want a managed database and its replication features | AWS for the service; Keycloak support follows the Keycloak database guide |
| Azure SQL | Managed Microsoft service; confirm the exact Keycloak version support and driver handling | Teams standardized on Microsoft cloud and SQL Server skills | Microsoft for the service; confirm Keycloak support scope in the guide |
| Microsoft SQL Server | Commercial engine; check your license terms and driver version | Windows-centric shops with existing SQL Server operations and backup practices | Microsoft under your existing license |
| MySQL | Dual-licensed by Oracle; confirm the edition and license that applies to your use | Teams already running MySQL with tested backup and replication practices | Oracle or your MySQL support provider |
| MariaDB | Open source; confirm the driver and version in the guide | Teams standardized on MariaDB operations | MariaDB community or a commercial provider |
| Oracle Database | Commercial; the JDBC driver is not bundled with Keycloak, so you must add it to your build | Organizations with existing Oracle licenses and DBA skills | Oracle under your existing agreement |
Why the dev-file database cannot run in production
Keycloak's default dev-file database is for development only, so a production deployment must point at an external, supported database. The default embedded store is convenient for a laptop or a test node, but it is not a design a production identity provider can run on. Every decision in this topic, from the database product to the connection pool and replication, assumes the database is a shared, external service that every Keycloak node reads and writes. Start with that requirement before choosing a version or a driver.
When teams skip this step, the failures show up after go-live rather than during testing. Nodes that do not share a database do not share state, so sessions, realm configuration and user changes made on one node may not be seen by another. A clustered setup then behaves inconsistently under load or during a rolling restart. The dev-file store also gives you no replication, so losing the host means losing identity data with no standby to promote. Backup and recovery are weak too: there is no tested procedure for restoring a consistent copy to a known point in time, and that gap becomes urgent the first time an admin account is deleted or a realm is misconfigured.
Before you build, confirm the current behavior and the supported list in the Keycloak database guide. Check the database versions that the release you plan to run supports, and record the production database choice in your architecture document. Then plan a backup and restore test against that database as part of the build, so the first real recovery does not happen during an incident.
How Keycloak nodes, the connection pool and PostgreSQL fit together
Requests start at the Keycloak nodes inside the Keycloak network. Each node reaches the primary PostgreSQL server either directly or through an optional pooler such as PgBouncer, which reuses a limited set of database connections. The primary streams changes to a synchronous standby, a commit waits for that standby, and a failover tool outside PostgreSQL must detect a primary failure and promote the standby. Check that every hop is encrypted, that the pooler and standby sit on the database network, and that backups go to a separate location.
Keycloak nodes reach PostgreSQL through an optional pooler, with a synchronous standby and an external failover tool.
Configuring PostgreSQL for Keycloak, step by step
This sequence takes a PostgreSQL server from a supported version to a Keycloak deployment that runs on it, with a dedicated role, SCRAM authentication, pooled connections and a verified startup across more than one node.
Confirm a supported PostgreSQL major version
Check the Keycloak database guide for the PostgreSQL range it supports, then match that range against the PostgreSQL versioning policy to confirm the major version is still receiving fixes for the whole life of your deployment. Keycloak's supported range is PostgreSQL 14 to 18, and the versioning policy lists end-of-support dates for each major version, so pick one that will outlast your planned upgrade window. Your database administrator or the platform owner signs off on the choice. Done means you have a written version number, its end-of-support date and a link to the Keycloak database guide in the change record.
Create the database and a limited role
Create an empty database for Keycloak and a dedicated login role that owns or fully controls only that database. Do not reuse the postgres superuser or a shared application role. The Keycloak role needs rights to create and alter tables in its own schema, because Keycloak migrates its schema at startup by default, and no rights on other databases. Keep the role's password in your secrets store, not in a shell history or a committed file. Check the result by connecting as the new role with psql and confirming it can list its database but cannot connect to any other database on the server.
Set password authentication to SCRAM
In postgresql.conf, set password_encryption to scram-sha-256, then set up pg_hba.conf so that connections from the Keycloak hosts use scram-sha-256 and are limited to the database and role you created, with the database network address stated explicitly. Re-set the Keycloak role's password after changing password_encryption so the stored verifier is SCRAM. Reload the configuration. PostgreSQL 18 deprecates MD5 password authentication in favor of SCRAM, so avoid md5 rules entirely. Verify with SELECT rolname, rolpassword FROM pg_authid for the Keycloak role, where the stored value should begin with SCRAM-SHA-256, and confirm that a connection from a host outside the allowed list is rejected.
Set the JDBC driver and database settings in Keycloak
Set the database vendor to postgres in the Keycloak configuration, along with the JDBC URL, username and password, using the settings your deployment method uses (for example, environment variables or the configuration file). Use the PostgreSQL JDBC driver that ships with the Keycloak distribution, and do not add Oracle or other vendor drivers, which Keycloak does not bundle. For a production server, add TLS parameters to the JDBC URL so credentials and data are encrypted in transit. Confirm the settings by starting Keycloak and reviewing the startup log for the database connection line, which should name PostgreSQL and the host you configured, not the development file database.
Configure connection pooling
Decide where pooling happens. Keycloak keeps its own JDBC connection pool, and you can add PgBouncer between Keycloak and PostgreSQL if many nodes or short-lived connections make the server's connection count hard to manage. Set Keycloak's pool size so that the total across all nodes stays below the server's max_connections with headroom for administrators and backups. If PgBouncer is used, decide its pool mode with care, since some session-level features do not work in transaction pooling, and confirm that against Keycloak's current database requirements. Check the result by counting open connections in pg_stat_activity during a login test and confirming the count stays within the planned total.
Run the startup test and confirm schema migration
Start a single Keycloak node against the new database and watch the log until startup completes. Then query the database to confirm the Keycloak schema exists and that the tables were created by the migration rather than left partly built. Log in to the admin console, create a test realm and a test user, and confirm the records appear in the database. Keycloak applies schema migrations automatically at startup by default, and the upgrading guide describes manual migration for large deployments, so record which method your team uses. Done means the schema is present, the test records are written and the migration log shows no errors.
Verify a second node sees the same data
Start a second Keycloak node pointed at the same database and confirm it joins without attempting a conflicting schema change. Log in to the first node, create a session, and check that the second node reads the same realm, user and client configuration. This shows the nodes share state through the database, which is the foundation for any high availability design. Check the result by comparing the realm listing from both nodes' admin endpoints and confirming the same user record. Clustering for failover is a separate design step that depends on a synchronously replicated database, so do not treat this test as proof of high availability.
How the database changes across Keycloak high availability designs
A single Keycloak cluster is the design most teams start with for high availability. Several Keycloak nodes share one database and act as one cluster, which can optionally be spread across availability zones. Every node depends on that shared database, so its replication and failover behavior sets the availability ceiling for the whole deployment. The Keycloak high availability overview describes this architecture.
- Synchronous replication: The database must be synchronously replicated, so a commit waits for standbys before Keycloak treats the change as saved. PostgreSQL supports this mode alongside asynchronous replication.
- Zone placement: When nodes span availability zones, place database copies so that losing one zone does not leave you without the copies the design needs. Confirm the layout against the overview.
- Failover tooling: PostgreSQL does not detect a primary failure or notify a standby on its own, so an external failover tool must be selected, configured and tested.
- Hot standby reads: Hot standbys serve read-only queries, but confirm which database endpoint each Keycloak connection uses so writes always reach the primary.
Check that replication, failover and zone layout have been tested together, with a planned primary failure exercised end to end.
The multi-cluster v2 design runs Keycloak across sites without an external Infinispan cluster. It is one of the two supported high availability designs, and both supported designs require a synchronously replicated database. Each site's database connection therefore becomes part of the cross-site failure model, not just a local setting. The database still holds the durable state that the sites share.
- Cross-site write latency: Synchronous replication means every committed write waits on the standby, so the network distance between sites adds directly to write time. Measure that latency before choosing site locations.
- Database topology: Confirm from the high availability overview whether each site connects to a local database copy or a shared endpoint, and how writes are routed during a site outage.
- Site failover steps: Promoting a database standby during a site failure is a manual or tool-driven step that PostgreSQL leaves to external software, so write the promotion runbook with the Keycloak team.
- Connection pool sizing: Size connection pools per site so that traffic moved to a surviving site does not overload the promoted primary. A pooler such as PgBouncer can enforce those limits.
Ask for a written statement of the database replication mode, failover owner and recovery time expectation for each site before the topology is approved.
The multi-cluster v1 design used a separate Infinispan cluster at each site. Keycloak documents it as deprecated, and it should not be the starting point for a new deployment. The database requirements for the two supported designs are stated explicitly, while v1 is documented only as a deprecated option, so confirm its database expectations directly with the project before relying on them. Existing v1 deployments need a migration plan.
- Deprecated status: Because v1 is deprecated, new work should target a supported design, and existing deployments should schedule a move off it.
- Additional stateful layer: Each site runs its own Infinispan cluster, so operators must back up and monitor that state alongside the database.
- Replication assumptions: Do not assume the synchronous replication requirement from the supported designs applies unchanged to v1. Verify it in the current documentation.
- Move to the stateless feature: The 26.8 upgrade notes recommend moving from the deprecated multi-site feature to the stateless feature, so plan a database backup, a rollback point and a change window for that move.
Before any topology change, review the Keycloak upgrading guide and record the replication mode, backup point and owner of each site's database.
Security controls for the Keycloak database connection
The database holds Keycloak's realms, users, client secrets and login history, so the connection between the two needs the same care as the admin console. The six controls below work together: encryption in transit, strong authentication, narrow permissions, restricted network paths, protected credentials and traceable administrative access.
TLS on the database connection
Encrypt every connection from Keycloak to PostgreSQL so credentials and user data never cross the network in clear text. In the Keycloak database settings, confirm that the JDBC URL requests TLS (for example with sslmode=verify-full and a trusted root certificate) and that the PostgreSQL server presents a certificate whose name matches the host Keycloak connects to. Test by forcing a plaintext attempt in a non-production environment and confirming it is refused.
SCRAM password authentication
Set the PostgreSQL server to store and check passwords with SCRAM-SHA-256 rather than MD5. PostgreSQL 18 deprecates MD5 password authentication, so a database that still relies on it needs a migration plan before any upgrade. Confirm password_encryption is set to scram-sha-256 and that the pg_hba.conf entries for the Keycloak user use scram-sha-256 rather than md5, then reset the Keycloak password so the stored hash is regenerated.
Least-privilege database roles
Create a dedicated login role for Keycloak that owns only its own database and schema. Keycloak needs to create and alter tables during startup migration, so decide in advance whether the role owns the schema or whether a separate migration role runs schema changes and the runtime role only reads and writes data. Confirm the role has no superuser rights, cannot read other application databases, and that administrators use separate named accounts for manual work.
Network restriction to Keycloak nodes
Allow inbound connections to PostgreSQL only from the addresses of Keycloak nodes and any approved administration hosts. Set listen_addresses to the database interface, then restrict pg_hba.conf by host address and database name, and enforce the same rule in firewalls or security groups. Check the rule from a host that is not a Keycloak node and confirm the connection fails. In clustered designs, update the allowlist whenever nodes are added or replaced.
Secrets handling for database credentials
Keep the database password out of realm exports, container images, shell history and source control. Provide it through a secrets store or a mounted file that the Keycloak process reads at startup, and confirm that Keycloak's configuration uses the secret source rather than a literal value. Plan rotation: confirm who can change the password, how the new value reaches every node, and whether a restart is needed for the change to take effect.
Audit logging of administrative database access
Record who connects to PostgreSQL with administrative rights and what they change. Turn on connection and statement logging for privileged roles, send logs to a central store that the security team can read, and confirm that schema changes made outside Keycloak's startup migration are reviewed. Keycloak's own admin events are a separate record, so check that both sources are retained for the period your compliance team requires.
Keeping PostgreSQL upgrades and replication in step with Keycloak
Plan PostgreSQL maintenance and Keycloak upgrades as one change, not two. PostgreSQL minor releases do not change the internal storage format, so applying one means replacing the executables and restarting the server. Keycloak does not need to be touched for that step beyond confirming the driver and supported PostgreSQL range still match. Major PostgreSQL upgrades are different. The documented routes are a dump and restore with pg_dumpall, pg_upgrade, or logical replication into a new major version. Logical replication works across major versions and, according to the PostgreSQL upgrading documentation, can cut the switchover to only several seconds of downtime. Confirm which route your team will use and rehearse it against a copy of production before the window is booked.
Keycloak migrates its own schema automatically at startup by default. That default is convenient for small installations but couples the two upgrades: a new Keycloak node can change tables while an old node is still serving traffic. For large deployments, the upgrading guide suggests manual migration, where the team generates and reviews the SQL and applies it before rolling out nodes. Decide the sequence in writing: confirm the Keycloak version against the PostgreSQL versions it supports, take a verified backup, apply the schema change, then roll the Keycloak nodes. Check the Keycloak upgrading guide for the release you are moving to, because minor upgrades can carry opt-in breaking changes and 26.8 includes behavior changes such as enforced SMTP StartTLS.
PostgreSQL does not detect a primary failure or promote a standby on its own. Synchronous replication, which Keycloak's high availability designs require, protects committed data, but failover still depends on external tooling that notices the outage, promotes the standby and redirects Keycloak's connection. Choose that tooling deliberately, and test it with the same failure you expect in production, including the period when a Keycloak node is mid-transaction. Also confirm how your chosen tool handles split-brain, how the JDBC connection string or proxy is updated, and who is paged when promotion fails. A failover that has never been exercised is not a plan, so schedule a controlled primary shutdown and record the time Keycloak takes to resume logins.
Limits to confirm before you commit to a database design
Several database limits shape the design more than any feature list does. Each item below is a question to put to Keycloak's supported-database list, your managed database vendor or your own test results before the design is signed off. Together they decide whether the database you pick can carry the availability, recovery and connection load you plan for.
Exact PostgreSQL version support
Keycloak's database guide lists PostgreSQL 14 to 18 as supported, but the exact version your Keycloak release accepts should be confirmed against the guide for that release. Ask whether the version you intend to run is covered by the Keycloak release you plan to deploy, and whether your managed service offers that exact major version. Record the answer in the design document so the next upgrade starts from a verified baseline.
Keycloak database guidePostgreSQL 14 end of support
PostgreSQL 14 reaches end of support on November 12, 2026, so a database deployed on it today has a short remaining support window. Ask your team whether the first production go-live would fall after that date, and if so, whether the design should start on PostgreSQL 15 or later. Plan the major upgrade path up front, since a major upgrade is a separate project from a Keycloak upgrade.
- PostgreSQL 14 end of support
- Nov 12, 2026
Replication and failover in managed services
Keycloak's high availability designs require a synchronously replicated database, and PostgreSQL does not detect a failed primary or promote a standby on its own. Ask your managed service provider whether it offers synchronous replication across the zones you need, how failover is triggered, how long it takes, and whether you can see the failover event in your logs. A service that offers only asynchronous replication does not meet the design requirement.
Keycloak high availability overviewOracle driver licensing and distribution
Oracle Database is listed as a supported production database, but Keycloak does not bundle the Oracle JDBC driver. Before you choose Oracle, confirm with your legal and procurement teams which Oracle driver version you may download, store in your image and redistribute inside your own container or appliance. Confirm also that your Oracle license covers the database edition and options your design relies on. Ask the Keycloak project or your vendor how the driver is supplied in your build pipeline.
Keycloak database guideConnection pool sizing against node count
Each Keycloak node opens its own pool of database connections, so the total connection count grows with every node you add. Multiply your planned pool size by the node count and compare the result with the connection limit on your database or managed instance, leaving room for administrators, backups and replication. If you place PgBouncer in front of PostgreSQL, confirm that its pooling mode works with the transaction behavior you test. Verify the figures in a load test, not on paper.
PgBouncer projectRecovery time and recovery point targets
Your recovery time objective (how long the service may be down) and recovery point objective (how much committed data you can lose) set the replication mode, backup frequency and failover tooling. Ask your database provider for the recovery point they guarantee under synchronous replication and for the restore time they have demonstrated for your data size. Then run a point-in-time recovery test into a separate environment and record the measured times. Do not accept a target that the restore test has not shown you can meet.
Continuous archiving docsWhat does a Keycloak database setup involve, and what drives its effort?
What does a Keycloak database setup cost, and what drives the price up or down?
The cost is set by the written scope, not by a published rate, because DeployOpen does not publish a price list and a quote follows from the agreed scope. The main cost drivers are the database platform (PostgreSQL is the usual choice, while Oracle Database and Microsoft SQL Server add licensing and driver work), the number of Keycloak nodes, the high availability design, how much backup and recovery testing is required, and whether a managed service such as Amazon Aurora PostgreSQL or Azure SQL is used. Ask for the quote to separate one-time work (design, build, migration and initial testing) from recurring work (patching, PostgreSQL minor updates and periodic restore tests), and to state which items your own team will perform.
How long does it take to set up the Keycloak database?
The duration depends on the database design you choose and on your environment, so it is scoped in writing before work starts rather than estimated in advance. A single database on a dedicated server is a smaller job than a synchronously replicated database serving a high availability Keycloak cluster, and an existing change process, network approvals and access requests all add time. Ask for the schedule to list each phase, the change windows it depends on, and the test environment you will be given before production cutover.
What does our team need to provide for a database engagement?
Plan to provide administrative access to the target database platform and to the Keycloak hosts, a description of the current architecture including Keycloak version and hostnames, the backup targets and retention rules you already use, and change windows for cutover. You should also name the people who approve production changes and the people who will own the database after handover. Missing any of these usually moves work from the agreed phases into rework, so confirm the list in the written scope.
Can our own team set up the Keycloak database without a partner?
Yes, a capable team can do it alone, provided it works from the Keycloak database guide, uses a supported PostgreSQL version, and tests the full configuration in a non-production environment first. The guide covers the supported database list, driver requirements and the fact that the default dev-file database is for development only. Where teams usually struggle is in replication, failover tooling and restore testing, because PostgreSQL does not detect a failed primary or promote a standby on its own. Decide early which of those areas your team can own and which it will hand to a partner.
Which parts of the database work are one-time and which recur?
The initial design, driver and connection pool configuration, replication build, failover design and first restore test are one-time work. Recurring work includes applying PostgreSQL minor releases, which PostgreSQL ships at least once every three months and which replace executables and require a restart, rerunning restore tests, reviewing connection and capacity settings, and planning major upgrades before a version leaves support. PostgreSQL 14 is listed as supported until November 12, 2026, so teams on that version should schedule the move now. Ask for the recurring tasks to be written into the handover runbook with an owner for each.
What are the main risks if the database is set up poorly?
The most common risks are running the dev-file database in production, choosing an unsupported PostgreSQL version, using asynchronous replication for a design that needs synchronous replication, and treating backups as done without a tested restore. Keycloak's high availability designs require a synchronously replicated database, so a mismatch here can cause failures during a node or site outage. Confirm the backup approach with point-in-time recovery against a timed restore before go-live, and document who runs each recovery step.
How DeployOpen scopes and delivers the Keycloak database work
DeployOpen plans, implements and documents the database layer under a Keycloak deployment inside your own infrastructure, including the production database choice, driver setup, connection pooling and replication for high availability. Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
How we scope
- We confirm the Keycloak version and the production database engine your standards already support.
- The written scope lists the database versions, drivers, pooling and replication design in your environment.
- We record which environments, backup targets and network paths the database work must cover before quoting.
How we build
- We configure the database, driver and connection pool on non-production environments first, then promote the settings.
- We choose between automatic and manual schema migration and document the steps for your upgrade process.
- We test failover behavior of the chosen replication design and confirm Keycloak reconnects cleanly after a database switch.
How we hand over
- You receive a written record of the database version, driver, pool and replication settings with reasons for each choice.
- Runbooks cover startup, schema migration, backup and restore, and failover steps your operators can follow.
- We walk your platform and database teams through the configuration so they can review and maintain it.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after handover.
- Retainer work can include planned database major version upgrades and retesting of failover after changes.
- We help you confirm vendor support windows and plan upgrades before a database version leaves support.

