@@ -78,10 +78,12 @@ defmodule Postgrex do
7878
7979 * `:hostname` - Server hostname (default: PGHOST env variable, then localhost);
8080 * `:port` - Server port (default: PGPORT env variable, then 5432);
81- * `:endpoints` - A list of endpoints (host and port pairs); Postgrex will try
82- each endpoint in order, one by one, until the connection succeeds; The syntax
83- is `[{host1,port1},{host2,port2},{host3,port3}]`; This option takes precedence
84- over `:hostname+:port`;
81+ * `:endpoints` - A list of endpoints (host and port pairs, with an optional
82+ extra_opts keyword list);
83+ Postgrex will try each endpoint in order, one by one, until the connection succeeds;
84+ The syntax is `[{host1, port1},{host2, port2},{host3, port3}]` or
85+ `[{host1, port1, extra_opt1: value},{host2, port2, extra_opt2: value}}]`;
86+ This option takes precedence over `:hostname+:port`;
8587 * `:socket_dir` - Connect to PostgreSQL via UNIX sockets in the given directory;
8688 The socket name is derived based on the port. This is the preferred method
8789 for configuring sockets and it takes precedence over the hostname. If you are
@@ -154,21 +156,23 @@ defmodule Postgrex do
154156
155157 iex> {:ok, pid} = Postgrex.start_link(socket_dir: "/tmp", database: "postgres")
156158 {:ok, #PID<0.69.0>}
157-
158- ## SSL client authentication
159159
160- When connecting to CockroachDB instances running in secure mode it is idiomatic to use
161- client SSL certificate authentication.
160+ ## SSL client authentication
161+
162+ When connecting to CockroachDB instances running in secure mode it is idiomatic to use
163+ client SSL certificate authentication.
162164
163165 An example of Repository configuration:
164166
165167 config :app, App.Repo,
166168 ssl: String.to_existing_atom(System.get_env("DB_SSL_ENABLED", "true")),
167169 ssl_opts: [
168170 verify: :verify_peer,
171+ server_name_indication: System.get_env("DB_HOSTNAME")
169172 cacertfile: System.get_env("DB_CA_CERT_FILE"),
170- verify_fun: &:ssl_verify_hostname.verify_fun/3
171- ]
173+ customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)],
174+ depth: 3
175+ ]
172176
173177 ## PgBouncer
174178
@@ -215,6 +219,28 @@ defmodule Postgrex do
215219 (...),
216220 {"test-instance-N.xyz.eu-west-1.rds.amazonaws.com", 5432}
217221 ]
222+
223+ ### Failover with SSL support
224+
225+ As specified in Erlang [:ssl.connect](https://erlang.org/doc/man/ssl.html#connect-3),
226+ host verification using `:public_key.pkix_verify_hostname_match_fun(:https)`
227+ requires that the ssl_opt `server_name_indication` is set, and for this reason,
228+ the aforementioned `endpoints` list can become a three element tuple as:
229+
230+ endpoints: [
231+ {
232+ "test-instance-1.xyz.eu-west-1.rds.amazonaws.com",
233+ 5432,
234+ [ssl: [server_name_indication: String.to_charlist("test-instance-1.xyz.eu-west-1.rds.amazonaws.com")]]
235+ },
236+ (...),
237+ {
238+ "test-instance-2.xyz.eu-west-1.rds.amazonaws.com",
239+ 5432,
240+ [ssl: [server_name_indication: String.to_charlist("test-instance-2.xyz.eu-west-1.rds.amazonaws.com")]]
241+ }
242+ ]
243+
218244 """
219245 @ spec start_link ( [ start_option ] ) :: { :ok , pid } | { :error , Postgrex.Error . t ( ) | term }
220246 def start_link ( opts ) do
0 commit comments