pgx icon indicating copy to clipboard operation
pgx copied to clipboard

Performance between sql.DB and pgxpool

Open vm-001 opened this issue 6 months ago • 1 comments

I noticed that pgxpool is also a DB pool, but its documentation only says, "Package pgxpool is a concurrency-safe connection pool for pgx."

Which one would have better performance theoretically? (Haven't done any benchmark yet)

vm-001 avatar Jun 20 '25 08:06 vm-001

Using pgx directly should have better performance than using database/sql. The pgx database/sql driver is implemented on top of the native pgx interface so in theory it should always be faster.

That said, whether the performance difference is significant or not depends to a great deal on network latency, PG server query times, and the data types of the query results.

In most cases, you should choose based on which features you need rather than performance. For example, most ORMs only work with database/sql, but many PostgreSQL specific features such as LISTEN/NOTIFY and the COPY protocol can only be accessed through the pgx native interface.

jackc avatar Jun 26 '25 01:06 jackc