Add pgx listener support to database/sql - #1366
Draft
bgentry wants to merge 1 commit into
Draft
Conversation
bgentry
force-pushed
the
bg/dbsql-pgx-listener
branch
from
August 27, 2026 02:17
a4a2c9d to
380f3ad
Compare
The `database/sql` driver currently operates in poll-only mode because it cannot acquire the dedicated connection required by Postgres `LISTEN`. Cross-process actions like cancelling a running job therefore wait for a poll even when the underlying SQL driver is Pgx. Add `NewWithPgxListener`, which keeps all query and transaction execution on the supplied `*sql.DB` while delegating listener creation to a Pgx driver backed by a separately supplied pool. Preserve `New` as the poll-only constructor and reject a nil listener pool so configuration errors cannot silently disable notifications. Document the database, schema, connection ownership, and pool sizing requirements. Exercise the hybrid driver through the shared listener suite, including notification-driven cancellation and transactional job completion through an ordinary `*sql.Tx`.
bgentry
force-pushed
the
bg/dbsql-pgx-listener
branch
from
August 27, 2026 02:59
380f3ad to
657ee90
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
riverdatabasesql.NewWithPgxListener(dbPool, listenerPool). The*sql.DBremains the exclusive executor for River queries and transactions, while a privateriverpgxv5driver uses the separately supplied Pgx pool only to create listeners.This lets applications built around
database/sql, Bun, GORM, or another ORM run one coherently typed River client with PostgresLISTEN/NOTIFYsupport. Cross-process actions such as cancelling a running job no longer have to wait for the poll interval, whileJobCompleteTxcontinues to operate on an ordinary*sql.Tx. The existingNewconstructor remains explicitly poll-only, and the new constructor rejects a nil listener pool.The caller owns both pools and must configure them for the same database and schema. A listener pool dedicated to one River client can generally use
MinConns: 0andMaxConns: 1. Listener connections are hijacked and therefore no longer count against the pool maximum or close with the pool; stopping the River client closes them. PgBouncer must use session pooling or be bypassed for these connections.This provides a design-aligned solution for #1364 without adding mixed transactional-driver support.
River Pro companion: riverqueue/riverpro#361.