jackc / jackc/pgx

Connection Pool Stacking and query_wait_timeout Error with pgx v5.4.1 and PgBouncer

Open
#1,687 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior with pgx v5.4.1, PostgreSQL 13.11, and the Dockerized PgBouncer setup, then compare it with pgx v5.3.1. Inspect connection-pool behavior around the query_wait_timeout and establish a minimal reproduction; done means identifying the version-specific cause and adding a verified fix or regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.