pgx
pgx copied to clipboard
Connection Pool Stacking and query_wait_timeout Error with pgx v5.4.1 and PgBouncer
I am facing an issue with the connection pooling behavior of the github.com/jackc/pgx package v5.4.1 in my Golang application. The application uses PgBouncer as a connection pooler between the Golang app and a PostgreSQL database. However, after deploying the application to my VPS and observing the logs, I noticed that the connection pool for my SELECT, INSERT, UPDATE, and DELETE queries keeps stacking up and eventually leads to a query_wait_timeout error when the connection limit is reached.
To troubleshoot this issue, I performed some investigations and found that downgrading the pgx package to v5.3.1 -- without even making any changes in the codes -- resolved the problem like magic✨. I deployed both the Golang app and PgBouncer using Docker containers.
Expected Behavior The connection pooling should work correctly with pgx v5.4.1 and PgBouncer, efficiently managing and reusing connections without excessive stacking or timeouts.
Actual Behavior The connection pool for queries keeps stacking up, leading to a query_wait_timeout error when the connection limit is reached.
Version
- Go: go 1.20
- PostgreSQL: PostgreSQL 13.11 (Debian 13.11-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
- PgBouncer: image
docker.io/bitnami/pgbouncer:1 - pgx: v5.4.1
Please try pgx v5.4.2. It resolved some issues with connections not being correctly cleaned up.