feat: add binary_parameters provider attribute for connection pooler compatibility#629
feat: add binary_parameters provider attribute for connection pooler compatibility#629MrrKirill wants to merge 3 commits into
Conversation
…compatibility When connecting through connection poolers (PgBouncer, Odyssey) in TRANSACTION pooling mode, lib/pq's Extended Query Protocol causes 'unnamed prepared statement does not exist' errors. Adding binary_parameters=yes to the connection string switches lib/pq to Simple Query Protocol, avoiding prepared statements entirely. New provider attribute: binary_parameters = true (default: false) Only applies to postgres scheme (not awspostgres/gcppostgres). Closes cyrilgdn#191
There was a problem hiding this comment.
Pull request overview
This PR adds a new binary_parameters provider configuration attribute to improve compatibility when the provider connects to PostgreSQL through transaction-pooling connection poolers (e.g., PgBouncer/Odyssey), by propagating binary_parameters=yes into the lib/pq connection parameters when enabled.
Changes:
- Adds
binary_parametersto the provider schema and wires it into provider configuration. - Extends connection string parameter generation to include
binary_parameters=yes(forscheme = "postgres"only) when enabled. - Adds unit tests covering enabled/disabled behavior and non-
postgresscheme behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| postgresql/provider.go | Adds the binary_parameters schema attribute and passes it into Config during providerConfigure. |
| postgresql/config.go | Adds BinaryParameters to Config and includes binary_parameters=yes in connParams() for the postgres scheme when enabled. |
| postgresql/config_test.go | Adds test cases verifying parameter inclusion/exclusion and that non-postgres schemes ignore the setting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi! I merged the latest The repository checks passed. I also ran the full provider acceptance suite against PostgreSQL 12 through 18, and all 14 suites passed. Separately, I tested transaction pooling on PostgreSQL 18.4 with:
With With
This change should help users who currently cannot use the provider through transaction-pooling proxies. @cyrilgdn, when you have time, I would appreciate another look at this PR. I am happy to make any additional changes needed before merge. |
Problem
When connecting to PostgreSQL through a connection pooler (PgBouncer, Odyssey, etc.) in TRANSACTION pooling mode, the provider fails with:
This happens because
lib/pquses the Extended Query Protocol (Parse → Bind → Execute) for parameterized queries. In TRANSACTION mode, the pooler may routeBind/Executeto a different backend process than the one that receivedParse. The new backend has no knowledge of the parsed statement, causing the error.This is a well-known limitation documented by:
Solution
Add a new
binary_parametersprovider attribute that maps directly to thelib/pqconnection parameter of the same name.When enabled,
lib/pqswitches from Extended Query Protocol to Simple Query Protocol for parameterized queries — sending everything in a single message without creating prepared statements. This makes all provider operations compatible with TRANSACTION pooling mode.Usage
Naming
The attribute is named
binary_parametersto match thelib/pqDSN parameter name directly, following the project's established convention (e.g.sslmodematches lib/pq, while Terraform-stylessl_modewas deprecated).Changes
postgresql/config.go: AddBinaryParameters boolfield toConfigstruct; appendbinary_parameters=yesto connection params when enabled (only forpostgresscheme, same assslmode/connect_timeout)postgresql/provider.go: Addbinary_parametersschema attribute (TypeBool, optional, defaultfalse); wire it inproviderConfigure()postgresql/config_test.go: Add test cases verifyingbinary_parameters=yesappears in connection params when enabled, is absent when disabled, and is ignored for non-postgres schemesTesting
Tested with Odyssey connection pooler:
binary_parametersfalsefalseunnamed prepared statement does not existtrueResources tested:
postgresql_grant,postgresql_default_privileges,postgresql_schemas(data source).Closes #191