Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/pages/features/pooling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ client.release()
future requests to check out a client from the pool will wait forever.
</Alert>

With `max: 1`, a second caller waits while the only client is checked out. How the first caller releases that client determines whether the waiting caller receives the same client or a replacement:

![Caller A holds the sole pool client while B waits. When A calls release without an error, the healthy client is reused and B receives the same client. When A passes an error to release, the pool removes that client and connects a replacement for B.](/images/pool-release-outcomes.png)

This example assumes an active pool, a successful replacement connection, no connection timeout, and no lifetime or usage limit that removes an otherwise healthy client. Passing an error to `client.release(error)` discards that client; the figure describes this explicit release choice, rather than prescribing it for every query error. The replacement still needs to be released after use. `max: 1` makes the example easy to follow, rather than recommending a pool size.

[Download editable SVG](/images/pool-release-outcomes.svg).

### Single query

If you don't need a transaction or you just need to run a single query, the pool has a convenience method to run a query on any available client in the pool. This is the preferred way to query with node-postgres if you can as it removes the risk of leaking a client.
Expand Down
Binary file added docs/public/images/pool-release-outcomes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions docs/public/images/pool-release-outcomes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading