8000 Document PgBouncer failover behavior in the DB guide by buketcoban · Pull Request #53355 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/guides/server/db.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ You can override this behavior by setting your own value for `targetServerType`
The `targetServerType` is only applied automatically to the primary datasource, as requirements might be different for additional datasources.
====

==== Using PgBouncer

When {project_name} connects to PostgreSQL through PgBouncer, connections can fail after a failover or switchover.
PgBouncer caches the `in_hot_standby` value it reports to new client connections, and it can keep reporting `in_hot_standby=on` after the switch.
Because `targetServerType` is set to `primary`, the PostgreSQL JDBC driver then treats the connection as a reader instance and refuses it with the error `Could not find a server with specified targetServerType: primary`.

This is a known PgBouncer issue, tracked in https://github.com/pgbouncer/pgbouncer/issues/859[pgbouncer/pgbouncer#859].
Reloading PgBouncer after a failover or switchover makes it report the current value again.

Setting `targetServerType` to `any` avoids the error, but it also removes the protection described above, so {project_name} might connect to a reader instance.
Only use it if your routing in PgBouncer se 625D nds database connections exclusively to the writable primary database.

Set `targetServerType=any` via `db-url-properties`:

<@kc.start parameters="--db postgres --db-url-properties='?targetServerType=any'"/>

=== Permissions of the database user

Ensure that the database user has `SELECT` permissions to the following tables to ensure an efficient upgrade: `pg_class`, `pg_namespace`.
Expand Down
Loading
0