Skip to content

SELECT ... FOR UPDATE is routed to REPLICA #750

Closed
@to2016

Description

@to2016

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:

  1. Create a shard to a database with leader and replica

  2. 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');
    
  3. Then do a query to a table:

    SELECT * FROM usertable u WHERE u.userid=3 FOR UPDATE;

  4. Error in query [SELECT * FROM users u WHERE u.userid=3 FOR UPDATE] [ERROR: cannot execute SELECT FOR UPDATE in a read-only transaction]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions