You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/pg/connection.rb
+27-6Lines changed: 27 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -673,7 +673,16 @@ def cancel
673
673
aliasasync_cancelcancel
674
674
675
675
modulePollable
676
-
# Track the progress of the connection, waiting for the socket to become readable/writable before polling it
676
+
# Track the progress of the connection, waiting for the socket to become readable/writable before polling it.
677
+
#
678
+
# Connecting to multiple hosts is done like so:
679
+
# - All hosts are passed to PG::Connection.connect_start
680
+
# - As soon as the host is tried to connect the related host is removed from the hosts list
681
+
# - When the polling status changes to `PG::PGRES_POLLING_OK` the connection is returned and ready to use.
682
+
# - When the polling status changes to `PG::PGRES_POLLING_FAILED` connecting is aborted and a PG::ConnectionBad is raised with details to all connection attepts.
683
+
# - When a timeout occurs, connecting is restarted with the remaining hosts.
684
+
#
685
+
# The downside is that this connects only once to hosts which are listed twice when they timeout.
# If the Ruby default internal encoding is set (i.e., <code>Encoding.default_internal != nil</code>), the
844
-
# connection will have its +client_encoding+ set accordingly.
858
+
# === Specifying Multiple Hosts
859
+
#
860
+
# It is possible to specify multiple hosts to connect to, so that they are tried in the given order or optionally in random order.
861
+
# In the Keyword/Value format, the host, hostaddr, and port options accept comma-separated lists of values.
862
+
# The {details to libpq}[https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS] describe how it works, but there are two small differences how ruby-pg handles multiple hosts:
863
+
# - All hosts are resolved before the first connection is tried.
864
+
# This means that when +load_balance_hosts+ is set to +random+, then all resolved addresses are tried randomly in one level.
865
+
# When a host resolves to more than one address, it is therefore tried more often than a host that has only one address.
866
+
# - When a timeout occurs due to the value of +connect_timeout+, then the given +host+, +hostaddr+ and +port+ combination is not tried a second time, even if it is specified several times.
0 commit comments