ruby-pg icon indicating copy to clipboard operation
ruby-pg copied to clipboard

Handle multiple hosts in the connection string, where only one host h…

Open guynaor opened this issue 3 years ago • 1 comments

…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

guynaor avatar Aug 21 '22 17:08 guynaor

Thank you for working on this issue!

larskanis avatar Aug 24 '22 05:08 larskanis

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.

larskanis avatar Oct 10 '22 07:10 larskanis

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.

guynaor avatar Oct 10 '22 12:10 guynaor