-
Notifications
You must be signed in to change notification settings - Fork 230
Description
Is your feature request related to a problem? Please describe.
Some frameworks (for example, Strapi) wrap every query in an explicit transaction block:
With the current implementation of pgcat, any explicit transaction is pinned to the primary, so these read‑only transactions cannot be balanced to replicas and replica capacity remains unused.
Describe the solution you'd like
Stop assuming that every transaction is likely a write query, and treat it as read‑only until the first write statement is detected.
Lines 490 to 494 in 5b03881
// All transactions go to the primary, probably a write. | |
StartTransaction { .. } => { | |
self.active_role = Some(Role::Primary); | |
break; | |
} |
This behavior needs not to be default, and could be enabled with a configuration.
Describe alternatives you've considered
Fixing the client implementation is ideal, but not always feasible when the codebase is proprietary or too large.
Additional context
pgpool-II (with statement_level_load_balance = on
) actually has this feature:
https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html
For a query to be load balanced, all the following requirements must be met:
...
- the query must not be in an explicitly declared transaction (i.e. not in a BEGIN ~ END block)
- However, if following conditions are met, load balance is possible even if in an explicit transaction
- ...
- transaction has not issued a write query yet