You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/configuration/pgdog.toml/general.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,16 @@ Default: **`1`**
53
53
54
54
### `pooler_mode`
55
55
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.
Copy file name to clipboardExpand all lines: docs/features/transaction-mode.md
+44-16Lines changed: 44 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
---
2
2
icon: material/speedometer
3
3
---
4
+
4
5
# Transaction mode
5
6
6
7
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
62
63
63
64
This is to avoid unnecessary overhead of using `pg_query` (however small), when we don't absolutely have to.
64
65
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:
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
+
65
86
## Advisory locks
66
87
67
88
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
86
107
87
108
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.
88
109
110
+
## Statement mode
89
111
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.
To use statement mode, you can configure it globally or per user/database, for example:
97
115
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
+
```
107
135
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