8000 Please reduce number of executed queries on PostgreSQL · Issue #54788 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Please reduce number of executed queries on PostgreSQL #54788

Description

@mkarg

Description

By default, Keycloak executes DFE8 many SQL statements every three minutes to cleanup expired sessions. With lots of realms, this easily piles up to considerable squandering of resources - even if zero sessions exist!

My proposal would be to first check if there are any sessions in the table at all, and if not, do not rund lots of queries.

Alternatively, check the time of the first session the expire and wait until then, but do not execute SQL when it simply is not needed.

(On my PostgreSQL 18, a rather unused Keycloak produces 8% CPU load every three minutes)

Value Proposition

Less resource consumption

Goals

Much less CPU load when keycloak is "silent"

Non-Goals

N/A

Discussion

No response

Notes

No response

Activity

  1. added theissue type on Nov 6, 2026
  2. added
    area/storageStorage layer — JPA entities, database schemas, Liquibase migrations, caching
    status/labeled-by-botIssue type or area was assigned automatically by the triage bot
    on Nov 6, 2026
  3. ahus1 commented on Nov 6, 2026

    @ahus1
    Member

    Sounds like a good improvement. The one thing we can't use is count the number of sessions (this is costly when there are a lot of sessions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/storageStorage layer — JPA entities, database schemas, Liquibase migrations, cachingkind/enhancementCategorizes a PR related to an enhancementstatus/labeled-by-botIssue type or area was assigned automatically by the triage botteam/core-shared

    Fields

    Value

    None yet

    Effort

    None yet

    Votes

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0