Skip to content

Conversation

@zachschultz
Copy link

@zachschultz zachschultz commented Jan 13, 2026

Resolves #1100

Saw this issue and it would help us out with our own app on Vercel.

Adds an onidle callback option that fires when a connection returns to the pool after completing queries.

Went with the callback pattern (onidle) instead of emitting an event to stay consistent with onclose, onnotify, etc.

Fires in the move() function when a connection transitions to the open queue - this is the same place idleTimer.start() is called, so it felt like the natural spot for "connection is now idle."

Usage

const sql = postgres(url, {
  onidle: (connId) => {
    console.log(`Connection ${connId} is now idle`)
  }
})

Or set after creation (e.g., like Vercel's attachDatabasePool()):

const sql = postgres(url)
sql.options.onidle = (connId) => { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observing pool clients going into idle state

1 participant