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
Multihost support for High Availability setups (#158)
* Allow multiple hosts
* Add support for target_session_attrs = 'read-write'
* Support multi host in all host/port parameters
Co-authored-by: Minigugus <43109623+Minigugus@users.noreply.github.com>
target_session_attrs :null// Use 'read-write' with multiple hosts to
73
+
// ensure only connecting to primary
72
74
})
73
75
```
74
76
77
+
### SSL
78
+
More info for the `ssl` option can be found in the [Node.js docs for tls connect options](https://nodejs.org/dist/latest-v10.x/docs/api/tls.html#tls_new_tls_tlssocket_socket_options).
79
+
75
80
Although it is [vulnerable to MITM attacks](https://security.stackexchange.com/a/229297/174913), a common configuration for the `ssl` option for some cloud providers like Heroku is to set `rejectUnauthorized` to `false` (if `NODE_ENV` is `production`):
76
81
77
82
```js
@@ -83,23 +88,31 @@ const sql =
83
88
:postgres();
84
89
```
85
90
86
-
More info for the `ssl` option can be found in the [Node.js docs for tls connect options](https://nodejs.org/dist/latest-v10.x/docs/api/tls.html#tls_new_tls_tlssocket_socket_options).
91
+
### Multi host connections - High Availability (HA)
92
+
93
+
Connection uri strings with multiple hosts works like in [`psql multiple host uris`](https://www.postgresql.org/docs/13/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS)
94
+
95
+
Connecting to the specified hosts/ports will be tried in order, and on a successfull connection retries will be reset. This ensures that hosts can come up and down seamless to your application.
96
+
97
+
If you specify `target_session_attrs: 'read-write'` or `PGTARGETSESSIONATTRS=read-write` Postgres.js will only connect to a writeable host allowing for zero down time failovers.
87
98
88
99
### Environment Variables for Options
89
100
90
-
It is also possible to connect to the database without a connection string or options, which will read the options from the environment variables in the table below:
101
+
It is also possible to connect to the database without a connection string or any options. Postgres.js will fall back to the common environment variables used by `psql` as in the table below:
0 commit comments