Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
unreleased
----------

This release changes the default `sslmode` from `require` to `prefer`, which is
the default used by libpq and the rest of the PostgreSQL ecosystem. See [#1271]
for some background.

### Features

- Support protocol 3.2, and the `min_protocol_version` and
Expand All @@ -15,6 +19,7 @@ unreleased
[#1258]: https://github.com/lib/pq/pull/1258
[#1265]: https://github.com/lib/pq/pull/1265
[#1270]: https://github.com/lib/pq/pull/1270
[#1271]: https://github.com/lib/pq/pull/1271

v1.11.2 (2026-02-10)
--------------------
Expand Down
3 changes: 2 additions & 1 deletion connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ func newConfig(dsn string, env []string) (Config, error) {
Host: "localhost",
Port: 5432,
SSLSNI: true,
SSLMode: SSLModePrefer,
MinProtocolVersion: "3.0",
MaxProtocolVersion: "3.0",
}
Expand Down Expand Up @@ -902,7 +903,7 @@ func (cfg Config) string() string {
switch k {
case "datestyle", "client_encoding":
continue
case "host", "port", "user", "sslsni", "min_protocol_version", "max_protocol_version":
case "host", "port", "user", "sslsni", "sslmode", "min_protocol_version", "max_protocol_version":
if !cfg.isset(k) {
continue
}
Expand Down
12 changes: 6 additions & 6 deletions connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,14 @@ func TestNewConfig(t *testing.T) {
}{
// Override defaults
{"", nil, "", ""},
{"user=u port=1 host=example.com", nil,
"host=example.com port=1 user=u", ""},
{"", []string{"PGUSER=u", "PGPORT=1", "PGHOST=example.com"},
"host=example.com port=1 user=u", ""},
{"user=u port=1 host=example.com sslmode=verify-ca", nil,
"host=example.com port=1 sslmode=verify-ca user=u", ""},
{"", []string{"PGUSER=u", "PGPORT=1", "PGHOST=example.com", "PGSSLMODE=verify-ca"},
"host=example.com port=1 sslmode=verify-ca user=u", ""},

// Socket
{"host=/var/run/psql", nil, "host=/var/run/psql sslmode=disable", ""},
{"host=@/var/run/psql", nil, "host=@/var/run/psql sslmode=disable", ""},
{"host=/var/run/psql", nil, "host=/var/run/psql", ""},
{"host=@/var/run/psql", nil, "host=@/var/run/psql", ""},
{"host=/var/run/psql sslmode=require", nil, "host=/var/run/psql sslmode=disable", ""},

// Empty value, value with space, and value with escaped \'
Expand Down
2 changes: 1 addition & 1 deletion error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func TestRetryError(t *testing.T) {
}

func TestNetworkError(t *testing.T) {
c, err := NewConnector("")
c, err := NewConnector("sslmode=disable")
if err != nil {
t.Fatal(err)
}
Expand Down
1 change: 0 additions & 1 deletion internal/pqtest/pqtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func DSN(conninfo string) string {
defaultTo("PGHOST", "localhost")
defaultTo("PGDATABASE", "pqgo")
defaultTo("PGUSER", "pqgo")
defaultTo("PGSSLMODE", "disable")
defaultTo("PGCONNECT_TIMEOUT", "20")
})

Expand Down
2 changes: 1 addition & 1 deletion ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ssl(cfg Config, mode SSLMode) (func(net.Conn) (net.Conn, error), error) {
case mode == SSLModeDisable || mode == SSLModeAllow:
return nil, nil

case mode == "" || mode == SSLModeRequire || mode == SSLModePrefer:
case mode == SSLModeRequire || mode == SSLModePrefer:
// We must skip TLS's own verification since it requires full
// verification since Go 1.3.
tlsConf.InsecureSkipVerify = true
Expand Down
4 changes: 4 additions & 0 deletions ssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func TestSSLMode(t *testing.T) {
connect string
wantErr string
}{
// Default (prefer) should work both with and without ssl.
{"user=pqgossl", ""},
{f.DSN(), ""},

// sslmode=require: require SSL, but don't verify certificate.
{"sslmode=require user=pqgossl", ""},
{"sslmode=require " + f.DSN(), "pq: SSL is not enabled on the server"},
Expand Down