On Tuesday, January 3, 2017 at 8:46:26 AM UTC-8, melody wrote:
>
> I set up my postgresql database, master for write, the other for read 
> using the following:
>
> DB=Sequel.postgres('postgres://master_server/database',   
>  :servers=>{:read_only=>{:host=>'slave_server'}})
>
> now when i execute sqls within a transaction, it didn't behave correct.
>
> DB.transaction do
>    DB["update XX set age = 22 where id = 3"].update
>    DB["select age from XX where id = 3"].first
> end
>
> the second sql didn't return age: 22, So i guess the update sql and select 
> sql been executed on different databases, maybe update on master and query 
> on slave, is it possible?
>

This is not only possible, this is the expected behavior.  SELECT queries 
go to read_only shard, other queries to the default shard.  If you want to 
force the select query to the default shard:

 DB.transaction do
   DB["update XX set age = 22 where id = 3"].update
   DB["select age from XX where id = 3"].server(:default).first
end

Alternatively, you may want to look at the server_block extension, which 
allows setting a default shard for a given block.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to