Skip to content

Commit a5a33a2

Browse files
committed
Document statement mode
1 parent 307b1b1 commit a5a33a2

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

docs/configuration/pgdog.toml/general.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ Default: **`1`**
5353

5454
### `pooler_mode`
5555

56-
Default pooler mode to use for database pools. See [Transaction mode](../../features/transaction-mode.md) and [session mode](../../features/session-mode.md) for more details on each mode.
56+
Default pooler mode to use for database pools.
57+
58+
Available options:
59+
60+
- `session`
61+
- `transaction` (default)
62+
- `statement`
63+
64+
65+
See [transaction mode](../../features/transaction-mode.md) and [session mode](../../features/session-mode.md) for more details on each mode.
5766

5867
Default: **`transaction`**
5968

docs/features/transaction-mode.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
icon: material/speedometer
33
---
4+
45
# Transaction mode
56

67
Transaction mode allows PgDog to share just a few of PostgreSQL server connections with thousands of clients. This is required for at-scale production deployments where the number of clients is much higher than the number of available connections to the database.
@@ -62,6 +63,26 @@ This is performed efficiently, and server parameters are updated only if they di
6263

6364
This is to avoid unnecessary overhead of using `pg_query` (however small), when we don't absolutely have to.
6465

66+
### Connection parameters
67+
68+
Most Postgres connection drivers support passing parameters in the connection URL. Using the special `options` setting, each parameter is set using the `-c` flag, for example:
69+
70+
```
71+
postgres://user@host:6432/db?options=-c%20statement_timeout%3D3s
72+
```
73+
74+
This sets the `statement_timeout` setting to `3s` (3 seconds). Each time this client
75+
executes a transaction, the pooler will check the value for `statement_timeout` on the server connection,
76+
and if it differs, issue a command to Postgres to update it:
77+
78+
```postgresql
79+
SET statement_timeout TO '3s';
80+
```
81+
82+
### Latency
83+
84+
PgDog keeps a real-time mapping of servers and their parameters, so checking the current value for any parameter doesn't require the pooler to talk to the database. Additionally, it's typically expected that applications have similar connection parameters, so the pooler won't have to synchronize parameters frequently.
85+
6586
## Advisory locks
6687

6788
Advisory locks are an implementation of distributed locking in PostgreSQL. They are set on the server connection and released when the client removes the lock or disconnects.
@@ -86,23 +107,30 @@ PgDog is able to detect advisory lock usage and will pin the server connection t
86107

87108
PgDog doesn't keep track of multiple advisory locks inside client connections. If a client acquires two different locks, for example, and only releases one, the server connection will still be returned back to the pool with the acquired lock.
88109

110+
## Statement mode
89111

90-
### Connection parameters
91-
92-
Most Postgres connection drivers support passing parameters in the connection URL. Using the special `options` setting, each parameter is set using the `-c` flag, for example:
112+
Statement mode is a subset of transaction mode. In statement mode, clients are not allowed to start explicit transactions, i.e. using the `BEGIN` statement. All queries will be sent to the first available connection in the pool.
93113

94-
```
95-
postgres://user@host:6432/db?options=-c%20statement_timeout%3D3s
96-
```
114+
To use statement mode, you can configure it globally or per user/database, for example:
97115

98-
This sets the `statement_timeout` setting to `3s` (3 seconds). Each time this client
99-
executes a transaction, the pooler will check the value for `statement_timeout` on the server connection,
100-
and if it differs, issue a command to Postgres to update it:
101-
102-
```postgresql
103-
SET statement_timeout TO '3s';
104-
```
105-
106-
### Latency
116+
=== "pgdog.toml (global)"
117+
```toml
118+
[general]
119+
pooler_mode = "statement"
120+
```
121+
=== "pgdog.toml (database)"
122+
```toml
123+
[[databases]]
124+
name = "prod"
125+
host = "127.0.0.1"
126+
pooler_mode = "statement"
127+
```
128+
=== "users.toml"
129+
```toml
130+
[[users]]
131+
name = "alice"
132+
database = "prod"
133+
pooler_mode = "statement"
134+
```
107135

108-
PgDog keeps a real-time mapping of servers and their parameters, so checking the current value for any parameter doesn't require the pooler to talk to the database. Additionally, it's typically expected that applications have similar connection parameters, so the pooler won't have to synchronize parameters frequently.
136+
Statement mode is useful when you want to avoid holding server connections idle while the client executes long transactions, but it does remove an important feature of Postgres, so additional care needs to be taken on the client to handle concurrent database updates.

0 commit comments

Comments
 (0)