Connect Keycloak with PostgreSQL DB
3 min readMay 22, 2023
Versions: keycloak 21.1.1 and postgreSQL 15.3
Note: first the database table should be created then connect the keycloak server to db.
To connect Keycloak with PostgreSQL, you need to perform the following steps:
- Ensure that you have PostgreSQL installed and running on your
Windows systems
- Create a new database for Keycloak in PostgreSQL or use the default
postgres
DB. You can do this using thecreatedb
command or a PostgreSQL administration tool. For example:
3. Now Go to the conf folder of the keycloak
4. change the keycloak.conf file as below
Configurations
# The database vendor.
db=postgres
# The username of the database user.for ex: ravi
db-username=postgres
# The password of the database user.
#the password that you used during the creation of the postgresql database.
db-password=password
# The full database JDBC URL. If not provided,
# a default URL is set based on the selected database vendor.
# add the port number that you used during installation of postgreSQL db
# here the db name=keycloakDB for example if you create a new db then use it
#for ex: db-url=jdbc:postgresql://localhost:5432/database_name_you_created
db-url=jdbc:postgresql://localhost:5432/keycloakDB
# Observability
# If the server should expose healthcheck endpoints.
health-enabled=true
# If the server should expose metrics endpoints.
metrics-enabled=true
5. Go to bin folder and build the keycloak by following the command
kc.sh build
6. Run the keycloak (Go to bin folder and run )
start-dev means run in development mode
kc.bat start-dev
incase if you want to change the port number then type the following code
kc.bat start-dev --http-port=8070
now check the db tables in the db used ,
7. create a new user (example:User10) in keycloak users tab and check in the postgresql user_entity
to download the schema of keycloak tables follow the below link.