SELECT ... FOR UPDATE is routed to REPLICA
to2016 opened this issue · 2 comments
to2016 commented
If you have a PostgreSQL cluster with one leader and replicas the SELECT ... FOR UPDATE is routed to REPLICAS.
This is a problem because it is not possible to set the LOCKS for it on a REPLICA.
SELECT ... FOR UPDATE statements must be routed to the PRIMARY/LEADER
To Reproduce
Steps to reproduce the behavior:
-
Create a shard to a database with leader and replica
-
Create sample table and insert data:
CREATE TABLE usertable ( userid INT, groupid INT, name VARCHAR(55) ); INSERT INTO usertable (userid, groupid, name) VALUES ( 1, 1, 'bob'), (2, 1, 'Alex'), (3, 2, 'Alice');
-
Then do a query to a table:
SELECT * FROM usertable u WHERE u.userid=3 FOR UPDATE;
-
Error in query [SELECT * FROM users u WHERE u.userid=3 FOR UPDATE] [ERROR: cannot execute SELECT FOR UPDATE in a read-only transaction]
jgoday commented