Keycloak Configuring PostgreSQL Database
The new version of Keycloak comes with its own embedded dev-file database to persist data. This default database is designed to run instantly and so is suitable only for use in a test environment. In a production environment, more mature relational database must be used.
In this tutorial, you will learn how to configure Keycloak (powered by Quarkus) to use with PostgreSQL database instead of its default dev-file database.
What You Need
Complete the steps below to set up Keycloak with MySQL:
Create New PostgreSQL Database with a New User for Keycloak
Let's starts by creating a new PostgreSQL database for Keycloak:
- Sign-in to your PostgreSQL Server using your root PostgreSQL credentials.
- Next, run the following PostgreSQL commands one by one. The first command creates a new database keycloak, the second command creates a new user keycloak, and the third command grants all privileges to user keycloak:
CREATE DATABASE keycloak; CREATE USER 'keycloak'@'localhost' IDENTIFIED BY 'Keycloak123$'; GRANT ALL PRIVILEGES ON keycloak.* TO 'keycloak'@'localhost';
Configure Keycloak to use PostgresSQL Database
- Go to conf directory of Keycloak Server.
- Open the keycloak.conf file with a text editor, such as Notepad.
- Uncomment and update the following properties in conf/keycloak.conf file:
- Next, go to bin directory:
- Start the Keycloak Server:
- Go to browser and open http://localhost:8080. You should see the Keycloak Admin Console.
db=postgresql db-username=keycloak db-password=Keycloak123$ #db-url=protocol//[host][/database] db-url=jdbc:postgresql://localhost:3306/keycloak
In Linux / Ubuntu / Unix
$ ./kc.sh start-dev
It should start normally without any error if it was configured correctly.
Learn what to do next here.