Skip to content

Update max_protocol_version and min_protocol_version defaults#2526

Open
abrightwell wants to merge 1 commit intojackc:masterfrom
abrightwell:abrightwell-min-proto
Open

Update max_protocol_version and min_protocol_version defaults#2526
abrightwell wants to merge 1 commit intojackc:masterfrom
abrightwell:abrightwell-min-proto

Conversation

@abrightwell
Copy link
Copy Markdown
Contributor

@abrightwell abrightwell commented Mar 26, 2026

When max_protocol_version is not explicitly set, the default value is set to "3.0". This is reasonable and is inline with the same behavior as libpq[1]. Though, what libpq attempts to do that was not being done here is to reasonably upgrade or auto-raise the value of max_protocol_version when it has not been explicitly set.

Here, we're providing the same functionality. In libpq, this determination is based on the parsed config values. We do the same here, parsing the values in ParseConfig to validate and determine the appropriate default for max_protocol_version. The string fields on Config are then set accordingly, and re-parsed at connection time as before.

After parsing, when max_protocol_version has not been explicitly set, if min_protocol_version is greater than 3.0, max_protocol_version defaults to latest; otherwise it defaults to 3.0 for compatibility with older servers/poolers that don't support NegotiateProtocolVersion.

[1] postgres/postgres@285613c

Fixes: #2525

When `max_protocol_version` is not explicitly set, the default value is
set to "3.0". This is reasonable and is inline with the same behavior as
libpq[1]. Though, what libpq attempts to do that was not being done here
is to reasonably upgrade or auto-raise the value of
`max_protocol_version` when it has not been explicitly set.

Here, we're providing the same functionality. In libpq, this
determination is based on the parsed config values. We do the same here,
parsing the values in ParseConfig to validate and determine the
appropriate default for max_protocol_version. The string fields on
Config are then set accordingly, and re-parsed at connection time as
before.

After parsing, when `max_protocol_version` has not been explicitly set,
if `min_protocol_version` is greater than 3.0, `max_protocol_version`
defaults to `latest`; otherwise it defaults to 3.0 for compatibility
with older servers/poolers that don't support NegotiateProtocolVersion.

[1] postgres/postgres@285613c
@abrightwell abrightwell force-pushed the abrightwell-min-proto branch from 5f6ed71 to 2f81f1f Compare March 26, 2026 13:18
const (
ProtocolVersion30 = 196608 // 3.0
ProtocolVersion32 = 196610 // 3.2
ProtocolVersionLatest = ProtocolVersion32 // Latest is 3.2
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary for this change. But as I was working through attempting to remove the double-parse requirement, I had added it. Certainly could remove it but felt like it was a potential gap that was worth filling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsing error when defining min_protocol_version=3.2

1 participant