jackc / pgx

PostgreSQL driver and toolkit for Go
MIT License
10.2k stars 815 forks source link

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

Open sultanfariz opened 1 year ago

sultanfariz commented 1 year ago

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

jackc commented 1 year ago

Please try pgx v5.4.2. It resolved some issues with connections not being correctly cleaned up.