ruby-pg
ruby-pg copied to clipboard
Handle multiple hosts in the connection string, where only one host h…
…as writable session. Will skip read-only hosts
This small change adds a test to see if the failure of the connection is because the host is read-only, and the session has a read-write requirement.
With this change a connection string of the format: postgres://192.168.1.20:5432,192.168.2.30:5432/liba_app?target_session_attrs=read-write&sslmode=require will work correctly, even if the first host (192.168.1.20) is the read only host in a primary/secondary style cluster
Thank you for working on this issue!
Hi @guynaor! After thinking a bit more about this issue, I propose to solve it per #485. That means to rely on the connection startup handling of libpq instead of reinventing more of it's logic in ruby.
The connect_timeout parameter was the reason for switching to host-by-host iteration in ruby (introduced in pg-1.4), but I think timeout handling is good enough how it's implemented in #485 now.
Hi @larskanis,
Thanks for looking at it thoroughly! I agree that the solution of letting pqlib handle it is best. I think this will solve the issues I had, and will let the Ruby gem, follow changes in libpq automatically.
THanks again,
Guy.