Transaction splitting offloads read requests inside non-auto-committed transactions from the primary instance to read-only instances—without application code changes. When all queries run inside transactions with autocommit disabled, the primary instance handles every request even though reads don't require write access. Transaction splitting routes those reads to read-only instances before any write begins, reducing load on the primary instance and improving its stability.
Prerequisites
Before you begin, ensure that you have:
The database proxy feature enabled on your ApsaraDB RDS for PostgreSQL instance. See Enable the database proxy feature
How it works
By default, the database proxy sends all requests inside a transaction to the primary instance to preserve read/write consistency. This is necessary for write operations, but read requests that precede any write are also sent to the primary—even when read-only instances could serve them safely.
Transaction splitting changes this behavior when two conditions are met:
The transaction isolation level is READ COMMITTED (the PostgreSQL default).
Autocommit is disabled (
autocommit = off).
Under these conditions, the proxy delays opening a transaction on the primary until the first write operation. All read requests issued before that write are routed to read-only instances via the load balancer.
Transaction splitting is enabled automatically when you enable the database proxy. It cannot be disabled.
Limitations
Not all transactions can be split. Make sure that transaction splitting is suitable for your workloads before you enable the database proxy.
| Constraint | Detail |
|---|---|
| Explicit transactions | Transactions started with BEGIN or START TRANSACTION are never split. All requests in an explicit transaction go to the primary. |
| Global consistency | Transaction splitting cannot guarantee global consistency across requests. Evaluate this tradeoff before enabling the database proxy. |
| Cannot be disabled | Once the database proxy is enabled, transaction splitting is always active. There is no option to turn it off independently. |
When to use transaction splitting
Transaction splitting works best when your application wraps read-heavy queries in non-auto-committed transactions without using explicit BEGIN or START TRANSACTION statements.
| Scenario | Suitable? |
|---|---|
| Applications with autocommit disabled, mostly reads before writes | Yes |
Explicit transactions using BEGIN or START TRANSACTION | No — reads stay on the primary |
| Workloads requiring strict global consistency across all reads | No — global consistency cannot be ensured |
API reference
| Operation | Description |
|---|---|
| DescribeDBProxy | Query the details of a database proxy |
| DescribeDBProxyEndpoint | Query the information about a database proxy endpoint |