pgx: 4.1.2 Can't query with with PGBouncer?
Connecting to PGBouncer, without SSL, and attempting to run any query fails with:
ERROR: unsupported pkt type: 80 (SQLSTATE 08P01)
I also tried 4.0.0 and it seems that this error is not new. Looks quite similar to #512. I attempted both the sql.DB
interface and the native pgx
interface to no avail.
Versions:
- PGBouncer 1.11.0
- pgx 4.0.0, 4.1.2
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 17 (6 by maintainers)
Commits related to this issue
- Add prefer_simple_protocol option to ParseConfig refs #650 — committed to jackc/pgx by jackc 3 years ago
For everyone, who used this but migrated to V5.
Right now, simple protocol can be enabled in a different way.
There are a few restrictions when using PgBouncer. One is that you cannot use prepared statements. So if you have any explicit prepared statement usage that would be a problem. But also pgx automatically uses prepared statements internally. So that needs to be disabled for pgx to work with pgbouncer.
There are two ways of doing that:
statement_cache_mode=describe
in your connection string is the simplest way to set this)PreferSimpleProtocol
totrue
in your pgx.ConnConfigDescribe statement cache mode allows pgx to remember the argument types and result types from a query. If a column type changes then query errors or even data corruption could occur. For example, if the server changed a column from an
int4
tofloat4
data corruption could occur as the binary representation of an integer would be stored into a float.@pavelpatrin thanks for that