anchor.diff:      summary="An overview about how to configure relational databases"
       includedOptions="db db-* transaction-xa-enabled">
   
  -In this guide, you are going to understand how to configure the server to store data using different relational databases.
  -You will also learn what databases are supported by the server.
  +This guide explains how to configure the Keycloak server to store data in a relational database.
   
  -== Querying the list of supported databases
  +== Supported databases
   
  -The server has built-in support for different databases. You should be able to query the available databases by looking at the expected values
  -for the `db` configuration option.
  -
  -The list of supported databases and their corresponding versions are:
  +The server has built-in support for different databases. You can query the available databases by viewing the expected values for the `db` configuration option. The following table lists the supported databases and their tested versions.
   
   |===
   |Database | Tested Version
  
positive.code: 
  == Configuring a database
  
  For each supported database, the server provides some opinionated defaults to make it simpler to configure a database. The defaults allow
  you to easily configure a database by just providing some key settings like the database host and credentials.
  
  To configure the database vendor, run the `build` command to build a server image using the `db` build option to configure the server for specific database:
  
  .Configuring a database vendor
  <@kc.build parameters="--db postgres"/>
  
  Once the database vendor is set, you can start the server and set the configuration options to configure the database host and credentials:
  
  .Starting the server
  <@kc.start parameters="--db-url-host mypostgres --db-username myuser --db-password change_me"/>
  
  These are the bare minimum settings that you need to set in order to successfully connect to a database.
  
  By default, the default schema is set to `keycloak`. You can change that by using the `db-schema` configuration option.
  
  == Overriding the default connection settings
  
  The server uses JDBC as the underlying technology to communicate with the relational database. In case the default connection settings are not enough, you are able to specify your own JDBC URL using the `db-url` configuration option.
  
  .Starting the server
  <@kc.start parameters="--db-url jdbc:postgresql://mypostgres/mydatabase"/>
  Be aware that you need to escape characters when invoking commands containing special shell characters such as `;` using the CLI, so you might want to set it in the configuration file instead.
  
  == Configuring the database for Unicode
  
  Database schema only accounts for Unicode strings in the following special fields:
  
  * *Realms*: display name, HTML display name, localization texts (keys and values)
  
  
negative.code: 
  * Descriptions of objects
  
  Otherwise, characters are limited to those contained in database encoding, which is often 8-bit. However, for some database systems, you can enable UTF-8 encoding of Unicode characters and use the full Unicode character set in all text fields. For a given database, this choice might result in a shorter maximum string length than the maximum string length supported by 8-bit encodings.
  
  === Configuring Unicode support for an Oracle database
  
  Unicode characters are supported in an Oracle database if the database was created with Unicode support in the VARCHAR and CHAR fields. For example, you configured AL32UTF8 as the database character set. In this case, the JDBC driver requires no special settings.
  
  If the database was not created with Unicode support, you need to configure the JDBC driver to support Unicode characters in the special fields. You configure two properties. Note that you can configure these properties as system properties or as connection properties.
  
  . Set `oracle.jdbc.defaultNChar` to `true`.
  
  . Optionally, set `oracle.jdbc.convertNcharLiterals` to `true`.
  +
  [NOTE]
  ====
  For details on these properties and any performance implications, see the Oracle JDBC driver configuration documentation.
  ====
  
  === Unicode support for a Microsoft SQL Server database
  
  Unicode characters are supported only for the special fields for a Microsoft SQL Server database. The JDBC driver and database require no special settings.
  
  === Configuring Unicode support for a MySQL database
  
  Unicode characters are supported in a MySQL database if the database was created with Unicode support in the VARCHAR and CHAR fields when using the CREATE DATABASE command.
  
  Note that the utf8mb4 character set is not supported due to different storage requirements for the utf8 character set. See MySQL documentation for details. In that situation, the length restriction on non-special fields does not apply because columns are created to accommodate the number of characters, not bytes.  If the database default character set does not allow Unicode storage, only the special fields allow storing Unicode values.
  
  . Start MySQL Server.
  . Under JDBC driver settings, locate the *JDBC connection settings*.
  . Add this connection property: `characterEncoding=UTF-8`
  
  === Configuring Unicode support for a PostgreSQL database
  
  Unicode is supported for a PostgreSQL database when the database character set is UTF8. Unicode characters can be used in any field with no reduction of field length for non-special fields. The JDBC driver requires no special settings. The character set is determined when the PostgreSQL database is created.
  
  . Check the default character set for a PostgreSQL cluster by entering the following SQL command.
  +
  ```
  show server_encoding;
  ```
  
  . If the default character set is not UTF 8, create the database with the UTF8 as the default character set using a command such as:
  
  +
  ```
  create database keycloak with encoding 'UTF8';
  ```
  
  == Changing database locking timeout in a cluster configuration
  
  Because cluster nodes can boot concurrently, they take extra time for database actions. For example, a booting server instance may perform some database migration, importing, or first time initializations. A database lock prevents start actions from conflicting with each other when cluster nodes boot up concurrently.
  
  The maximum timeout for this lock is 900 seconds. If a node waits on this lock for more than the timeout, the boot fails. The need to change the default value is unlikely, but you can change it by entering this command:
  
  <@kc.start parameters="--spi-dblock-jpa-lock-wait-timeout 900"/>
  
  == Using Database Vendors without XA transaction support
  Keycloak uses XA transactions and the appropriate database drivers by default. Certain vendors, such as Azure SQL and MariaDB Galera, do not support or rely on the XA transaction mechanism. To use Keycloak without XA transaction support using the appropriate JDBC driver, enter the following command:
  
  <@kc.build parameters="--db=<vendor> --transaction-xa-enabled=false"/>
  
  Keycloak automatically chooses the appropriate JDBC driver for your vendor.
  
  </@tmpl.guide>
  