Skip to content

Commit b78bb96

Browse files
committed
feat: user guide for connection pool sizing
1 parent 41c59c0 commit b78bb96

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

docs/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ nav:
55
- 'configuration'
66
- 'administration'
77
- 'architecture'
8+
- 'user_guides'
89
- '...'
910
- 'about.md'

docs/user_guides/.pages

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nav:
2+
- 'connection_pool.md'
3+
icon: material/book-open-variant
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
icon: material/pipe
3+
---
4+
5+
# Connection pools configuration
6+
7+
When deploying a connection pooler for the first time, it can be challenging to know how many connections to provision for each [connection pool](../configuration/pgdog.toml/general.md#default_pool_size). The goal of using a connection pooler, like PgDog, is to reduce the total number of database connections by taking advantage of [transaction mode](../features/transaction-mode.md).
8+
9+
Sizing up the right value for that setting depends on your database, but follows a few general principles.
10+
11+
## One pool per user
12+
13+
PgDog creates one, independent, connection pool for each user entry in [`users.toml`](../configuration/users.toml/users.md). If the [`pool_size`](../configuration/users.toml/users.md#pool_size) setting is not specified, it will use [`default_pool_size`](../configuration/pgdog.toml/general.md#default_pool_size) instead.
14+
15+
This property is important to keep in mind, since adding several users will increase the maximum possible connection count on the database.
16+
17+
### Estimating the pool size
18+
19+
To get the right setting for `default_pool_size` (or `pool_size`), take the current peak database connection count on your database and divide it by the number of users in `users.toml`. This will give PgDog the ability to open, _at most_, that number of connections, if needed.
20+
21+
Transaction mode connection re-use will bring that number down pretty quickly, but setting it that high to start with helps prevent any edge cases, e.g., slow queries, from starving the pool.
22+
23+
If you don't have reliable statistics for peak database usage, use the [`max_connections`](https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-MAX-CONNECTIONS) setting from `postgresql.conf`.
24+
25+
#### The formula
26+
27+
```
28+
default_pool_size = max_connections / <number of users>
29+
```
30+
31+
| Argument | Description |
32+
|-|-|
33+
| `default_pool_size` | Maximum number of connections PgDog can open to the database _per_ user in `users.toml`. |
34+
| `max_connections` | Maximum number of connections configured in the database. PgDog won't be able to open more connections than this setting. |
35+
| `<number of users>` | Number of entries in `users.toml`. |

0 commit comments

Comments
 (0)