@@ -78,10 +78,12 @@ defmodule Postgrex do
78
78
79
79
* `:hostname` - Server hostname (default: PGHOST env variable, then localhost);
80
80
* `: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`;
85
87
* `:socket_dir` - Connect to PostgreSQL via UNIX sockets in the given directory;
86
88
The socket name is derived based on the port. This is the preferred method
87
89
for configuring sockets and it takes precedence over the hostname. If you are
@@ -154,21 +156,23 @@ defmodule Postgrex do
154
156
155
157
iex> {:ok, pid} = Postgrex.start_link(socket_dir: "/tmp", database: "postgres")
156
158
{:ok, #PID<0.69.0>}
157
-
158
- ## SSL client authentication
159
159
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.
162
164
163
165
An example of Repository configuration:
164
166
165
167
config :app, App.Repo,
166
168
ssl: String.to_existing_atom(System.get_env("DB_SSL_ENABLED", "true")),
167
169
ssl_opts: [
168
170
verify: :verify_peer,
171
+ server_name_indication: System.get_env("DB_HOSTNAME")
169
172
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
+ ]
172
176
173
177
## PgBouncer
174
178
@@ -215,6 +219,28 @@ defmodule Postgrex do
215
219
(...),
216
220
{"test-instance-N.xyz.eu-west-1.rds.amazonaws.com", 5432}
217
221
]
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
+
218
244
"""
219
245
@ spec start_link ( [ start_option ] ) :: { :ok , pid } | { :error , Postgrex.Error . t ( ) | term }
220
246
def start_link ( opts ) do
0 commit comments