You need to enable JavaScript to run this app.
RDS for PostgreSQL

RDS for PostgreSQL

Copy page
Download PDF
Managing connection endpoints
Read/Write separation strategy
Copy page
Download PDF
Read/Write separation strategy
Once read/write separation is enabled, users' queries will be sent to the primary node or its read-only nodes. If you do not want an SQL query that meets the load balancing conditions to be sent to the primary node rather than through load balancing after read/write separation is enabled, you can add a hint before the SQL query. /*NO LOAD BALANCE*/ is usually used as the hint.​
Queries sent to the primary node​
Standard SQL queries​
  • INSERT,UPDATE,DELETE,COPY FROM,TRUNCATE,CREATE,DROP,ALTER,COMMENT​
  • SELECT ... FOR SHARE | UPDATE​
  • DECLARE,FETCH,CLOSE​
  • SHOW​
  • Lock commands stricter than ROW EXCLUSIVE MODE​
  • SELECT under transaction isolation SERIALIZABLE level​
  • Part of the transactional commands:​
  • BEGIN READ WRITE,START TRANSACTION READ WRITE​
  • SET TRANSACTION READ WRITE,SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE​
  • SET transaction_read_only = off​
  • Two-phase commit commands: PREPARE TRANSACTION, COMMIT PREPARED, ROLLBACK PREPARED​
  • LISTEN,UNLISTEN,NOTIFY​
  • VACUUM​
  • Commands for creating large objects​
  • Multiple SQL commands on a single line​
  • Some sequence manipulation functions (nextval and setval)​
Custom SQL queries​
The current RDS for PostgreSQL version defines some functions and SQL templates. Queries containing these functions or matching an SQL template will be forwarded to the primary node.​
  • Queries containing the functions nextval, setval, lastval, currval, txid_current, gin_clean_pending_list​
  • Queries containing functions prefixed with pg_catalog, pg_, current_, cursor_​
  • Queries matching the template .*for update.*​
Queries sent to read-only nodes​
  • SELECT queries not included in the above​
  • COPY TO STDOUT​
  • EXPLAIN​
  • EXPLAIN ANALYZE and the query is SELECT not including writing functions​
Sent to the primary node and read-only node​
  • SET​
  • DISCARD​
  • DEALLOCATE ALL​
Explicit transaction forwarding policy​
  • In an explicit transaction, BEGIN is forwarded to both the primary node and read-only nodes simultaneously.​
  • In an explicit transaction, the query statements preceding any query statements that cannot be executed on the read-only nodes (such as INSERT) will be sent to read-only nodes.​
  • In an explicit transaction, any query statements that cannot be executed on read-only nodes (such as INSERT) will be sent to the primary node. All subsequent query statements will be sent to the primary node to ensure that SELECT immediately sees the results of INSERT. This action continues until the transaction is disabled or terminated.​
​
Last updated: 2025.11.17 16:15:03