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/databases.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,3 +105,7 @@ Overrides the [`idle_timeout`](general.md#idle_timeout) setting. Idle server con
105
105
### `read_only`
106
106
107
107
Sets the `default_transaction_read_only` connection parameter to `on` on all server connections to this database. Clients can still override it with `SET`.
108
+
109
+
### `server_lifetime`
110
+
111
+
Overrides the [`server_lifetime`](general.md#server_lifetime) setting. Server connections older than this will be closed when returned to the pool.
Copy file name to clipboardExpand all lines: docs/configuration/pgdog.toml/general.md
+40-2Lines changed: 40 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,6 +141,12 @@ Delay running idle healthchecks at PgDog startup to give databases (and pools) t
141
141
142
142
Default: **`5_000`** (5s)
143
143
144
+
### `healthcheck_timeout`
145
+
146
+
Maximum amount of time to wait for a healthcheck query to complete.
147
+
148
+
Default: **`5_000`** (5s)
149
+
144
150
### `connection_recovery`
145
151
146
152
Controls if server connections are recovered or dropped if a client abruptly disconnects.
@@ -237,6 +243,12 @@ Close client connections that have been idle, i.e., haven't sent any queries, fo
237
243
238
244
Default: **`none`** (disabled)
239
245
246
+
### `client_idle_in_transaction_timeout`
247
+
248
+
Close client connections that have been idle inside a transaction for this amount of time. This prevents clients from holding server connections indefinitely while in a transaction.
249
+
250
+
Default: **`none`** (disabled)
251
+
240
252
### `client_login_timeout`
241
253
242
254
Maximum amount of time new clients have to complete authentication. Clients that don't will be disconnected.
@@ -261,6 +273,17 @@ Which strategy to use for load balancing read queries. See [load balancer](../..
261
273
262
274
Default: **`random`**
263
275
276
+
### `read_write_strategy`
277
+
278
+
How aggressive the query parser should be in determining read vs. write queries.
279
+
280
+
Available options:
281
+
282
+
-`conservative` (default): transactions are writes, standalone `SELECT` are reads
283
+
-`aggressive`: use first statement inside a transaction for determining query route
284
+
285
+
Default: **`conservative`**
286
+
264
287
### `read_write_split`
265
288
266
289
How to handle the separation of read and write queries.
@@ -449,10 +472,25 @@ Available options:
449
472
### `reload_schema_on_ddl`
450
473
451
474
!!! warning
452
-
This setting is intended for local development / CI / single node PgDog deployments.
453
-
475
+
This setting requires [PgDog Enterprise Edition](../../enterprise_edition/index.md) to work as expected. If using the open source edition,
476
+
it will only work with single-node PgDog deployments, e.g., in local development or CI.
477
+
454
478
Automatically reload the schema cache used by PgDog to route queries upon detecting DDL statements (e.g., `CREATE TABLE`, `ALTER TABLE`, etc.).
455
479
480
+
Default: **`true`** (enabled)
481
+
482
+
### `load_schema`
483
+
484
+
Controls whether PgDog loads the database schema at startup for query routing.
485
+
486
+
Available options:
487
+
488
+
-`on`: always load schema on startup
489
+
-`off`: disable loading schema
490
+
-`auto` (default): load schema if number of database shards is greater than 1
Copy file name to clipboardExpand all lines: docs/configuration/pgdog.toml/rewrite.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,13 +11,15 @@ The `rewrite` section controls PgDog's automatic SQL rewrites for sharded databa
11
11
enabled = false
12
12
shard_key = "error"
13
13
split_inserts = "error"
14
+
primary_key = "ignore"
14
15
```
15
16
16
17
| Setting | Description | Default |
17
18
| --- | --- | --- |
18
19
|`enabled`| Enables/disables the query rewrite engine. |`false`|
19
20
|`shard_key`| Behavior when an `UPDATE` changes a sharding key: `error` rejects the statement,<br>`rewrite` migrates the row between shards,<br>`ignore` forwards it unchanged. |`"error"`|
20
21
|`split_inserts`| Behavior when a sharded table receives a multi-row `INSERT`: `error` rejects the statement, `rewrite` fans the rows out to their shards, `ignore` forwards it unchanged. |`"error"`|
22
+
|`primary_key`| Behavior when an `INSERT` is missing a `BIGINT` primary key: `error` rejects the statement,<br>`rewrite` auto-injects `pgdog.unique_id()` for missing keys,<br>`ignore` allows the INSERT without modification. |`"ignore"`|
21
23
22
24
!!! note "Two-phase commit"
23
25
Consider enabling [two-phase commit](../../features/sharding/2pc.md) when either feature is set to `rewrite`. Without it, rewrites are committed shard-by-shard and can leave partial changes if a transaction fails.
The name of the database in [`[[databases]]`](databases.md) section in which the table is located. PgDog supports sharding thousands of databases and tables in the same configuration file.
59
59
60
-
### `table`
60
+
### `schema`
61
+
62
+
The name of the PostgreSQL schema where the sharded table is located. This is optional. If not set, all schemas will be sharded.
63
+
64
+
### `name`
61
65
62
66
The name of the PostgreSQL table. Only columns explicitly referencing that table will be sharded.
63
67
64
68
The name must not contain the schema name, just the table name.
65
69
66
-
!!! note "Postgres schemas"
67
-
Disambiguating tables in different schemas isn't currently supported and all of them will be sharded.
68
-
69
70
### `column`
70
71
71
72
The name of the sharded column.
@@ -79,6 +80,25 @@ The data type of the column. Currently supported options are:
79
80
-`varchar`
80
81
-`vector`
81
82
83
+
### `hasher`
84
+
85
+
The hash function to use for sharding. Available options:
86
+
87
+
-`postgres` (default) - PostgreSQL's native hash function
88
+
-`sha1` - SHA-1 hash function
89
+
90
+
### `centroids`
91
+
92
+
For vector sharding, specify the centroid vectors directly in the configuration. This is useful for small centroid sets.
93
+
94
+
### `centroids_path`
95
+
96
+
Path to a JSON file containing centroid vectors. This is useful when centroids are large (1000+ dimensions) and impractical to embed in `pgdog.toml`.
97
+
98
+
### `centroid_probes`
99
+
100
+
Number of centroids to probe during vector similarity search. If not specified, defaults to the square root of the number of centroids.
101
+
82
102
## Omnisharded tables
83
103
84
104
[Omnisharded](../../features/sharding/omnishards.md) tables are tables that have the same data on all shards. They typically are small and contain metadata, e.g., list of countries, cities, etc., and are used in joins. PgDog allows to read from these tables directly and load balances traffic evenly across all shards.
@@ -113,9 +133,56 @@ By default, PgDog uses hash-based sharding, with data evenly split between shard
113
133
114
134
To configure either one, you need to specify the value-to-shard mapping in the configuration.
115
135
136
+
## Mapping fields
137
+
138
+
!!! note
139
+
The `column`, `table`, and `schema` fields must match a corresponding `[[sharded_tables]]` entry.
140
+
141
+
### `database`
142
+
143
+
The name of the database in [`[[databases]]`](databases.md) section.
144
+
145
+
### `column`
146
+
147
+
The name of the column to match for routing. Must match a `column` in `[[sharded_tables]]`.
148
+
149
+
### `table`
150
+
151
+
The name of the table to match. Must match a `name` in `[[sharded_tables]]` if specified there. This is optional.
152
+
153
+
### `schema`
154
+
155
+
The name of the PostgreSQL schema to match. Must match a `schema` in `[[sharded_tables]]` if specified there. This is optional.
156
+
157
+
### `kind`
158
+
159
+
The type of mapping. Available options:
160
+
161
+
-`list`: match specific values (i.e., `PARTITION BY LIST`)
162
+
-`range`: match a range of values (i.e., `PARTITION BY RANGE`)
163
+
-`default`: fallback for unmatched values (list-based sharding only)
164
+
165
+
### `values`
166
+
167
+
For `list` mappings, the set of values that route to this shard.
168
+
169
+
### `start`
170
+
171
+
For `range` mappings, the starting value (inclusive).
172
+
173
+
### `end`
174
+
175
+
For `range` mappings, the ending value (exclusive).
176
+
177
+
### `shard`
178
+
179
+
The target shard number for matched queries.
180
+
181
+
## Mapping examples
182
+
116
183
### Lists
117
184
118
-
Lists are defined as a list of values and a corresponding shard number. Just like sharded tables, the mapping is database and column (and optionally, table) specific:
185
+
Lists are defined as a list of values and a corresponding shard number. Just like sharded tables, the mapping is database and column (and optionally, table and schema) specific:
119
186
120
187
```toml
121
188
[[sharded_mappings]]
@@ -153,3 +220,20 @@ shard = 0
153
220
UPDATE users SET deleted_at = NOW()
154
221
WHERE tenant_id IN (1, 2, 5, 10, 56)
155
222
```
223
+
224
+
### Default
225
+
226
+
The `default` kind specifies a fallback shard for values that don't match any list mapping:
227
+
228
+
```toml
229
+
[[sharded_mappings]]
230
+
database = "prod"
231
+
column = "tenant_id"
232
+
kind = "default"
233
+
shard = 2
234
+
```
235
+
236
+
Any sharding key value that doesn't match an explicit list mapping will be routed to the default shard.
237
+
238
+
!!! note
239
+
The `default` kind only works with list-based sharding, not range-based sharding.
0 commit comments