Understanding database schema of Keycloak

We are looking for efficient way to cleanup user records from keycloak. We are using Aurora MySQL serverless , as data store of Keycloak. We are having a scenario where we may have to delete about 100K user records from Keycloak and this can be a periodic activity. We observed that using ADMIN REST API for deletion increases the CPU utilization a lot, is there a documentation that would state which are the DB tables in which user record is stored and we can write SQL query for the bulk deletion ?


However, I don’t know if there are correct foreign key constraints set up so that it will also delete all the rows in the related tables.

Thanks for you response. I did see USER_ENTITY table, but same like you mentioned, wanted to understand the dependencies if any.


I’m also interested in knowing why keycloak needs to persitently store anything about users when an external user database is used.
Is this has something related to offline sessions ?


The default user store in Keycloak is internal. It’s only stored externally when user federation is used.