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/features/sharding/cross-shard.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ While this works for simple queries, others that involve sorting or aggregation
15
15
16
16
## Sorting
17
17
18
-
If the client requests results to be ordered by one or more columns, PgDog can interpret this request and perform the sorting once it receives all data messages from all servers. For queries that span multiple shards, this feature allows to retrieve results in the correct order. For example:
18
+
If the client requests results to be ordered by one or more columns, PgDog can interpret this request and perform the sorting once it receives all data messages from all servers. For queries that span multiple shards, this feature allows you to retrieve results in the correct order. For example:
19
19
20
20
```postgresql
21
21
SELECT * FROM users WHERE admin IS true
@@ -71,13 +71,12 @@ DDL statements, i.e., queries that modify the database schema, like `CREATE TABL
71
71
72
72
This assumes that all shards in the cluster have an identical schema. This is typically desired to make management of sharded databases simpler, but in scenarios where this is not possible, DDL queries can always be routed to specific shards using [manual routing](manual-routing.md).
73
73
74
-
!!! note
75
-
PgDog doesn't use two-phase commit so make sure your DDL
76
-
statements are idempotent and can be retried in case of an error.
74
+
If [two-phase commit](2pc.md) is enabled, DDL statements have a high chance to be atomic. Alternatively, they can generally be written to be idempotent and safe to retry in case of error.
77
75
78
76
### Two-phase commit
79
77
80
-
Currently, PgDog doesn't use two-phase commit to synchronize changes across all shards. Support for this feature is currently being built, and will require database operators to enable [prepared transactions](https://www.postgresql.org/docs/current/sql-prepare-transaction.html).
78
+
PgDog supports Postgres' [prepared transactions](https://www.postgresql.org/docs/current/sql-prepare-transaction.html) and [two-phase commit](2pc.md). If enabled, cross-shard writes have a high chance to be atomic and eventually consistent.
Copy file name to clipboardExpand all lines: docs/features/sharding/omnishards.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,14 +19,16 @@ tables = [
19
19
]
20
20
```
21
21
22
-
## Query router
22
+
## Query routing
23
23
24
24
Omnisharded tables are treated differently by the query router. Write queries are sent to all shards concurrently, while read queries are distributed evenly between shards using round robin.
25
25
26
26
If the query contains a sharding key, it will be used instead, and omnisharded tables in that query will be ignored.
27
27
28
28
### Consistency
29
29
30
-
Writing data to omnisharded tables is not currently atomic. While we work on adding support for two-phase commit, make sure writes to omni tables can be repeated in case of failure. This can be done with unique indexes and `ON CONFLICT ... DO UPDATE` queries.
30
+
Writing data to omnisharded tables is atomic if you enabled [two-phase commit](2pc.md).
31
31
32
-
Reads from omni tables are routed to individual shards. If you update data in those tables at the same time, `SELECT` queries to these tables may return different results for a brief period of time.
32
+
If you can't or choose not to use 2pc, make sure writes to omnisharded tables can be repeated in case of failure. This can be achieved by using unique indexes and `INSERT ... ON CONFLICT ... DO UPDATE` queries.
33
+
34
+
Since reads from omnisharded tables are routed to individual shards, while two-phase commit takes place, queries to these tables may return different results for a brief period of time.
Copy file name to clipboardExpand all lines: docs/features/sharding/supported-queries.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,8 @@
5
5
Postgres has 3 kinds of queries, each handled a little bit differently in a sharded context:
6
6
7
7
1. CRUD statements (`INSERT`, `UPDATE`, `SELECT`, `DELETE`, `COPY`) are parsed for sharding keys and routed to one or more shards
8
-
5. DDL statements (e.g., `CREATE TABLE`, `BEGIN`, `ROLLBACK`, etc.) are sent to all shards in parallel
9
-
6.`SET` statements are intercepted and client state is updated to keep track of session variables
8
+
2. DDL statements (e.g., `CREATE TABLE`, `BEGIN`, `ROLLBACK`, etc.) are sent to all shards in parallel
9
+
3.`SET` statements are intercepted and client state is updated to keep track of session variables
10
10
11
11
## CRUD
12
12
@@ -20,14 +20,14 @@ Postgres has 3 kinds of queries, each handled a little bit differently in a shar
20
20
#### Examples
21
21
22
22
```postgresql
23
-
-- Sharding key equals to a single value
23
+
-- Sharding key equals a single value
24
24
SELECT * FROM users WHERE user_id = $1
25
25
26
26
-- Sharding keys IN tuple
27
27
SELECT * FROM users WHERE id IN ($1, $2, $3)
28
28
```
29
29
30
-
Queries that don't match this pattern presently will be routed to all shards. We are continuously adding support for more complex patterns.
30
+
Queries that don't match this pattern will currently be routed to all shards. We are continuously adding support for more complex patterns.
31
31
32
32
#### `SELECT` queries that write
33
33
@@ -72,4 +72,4 @@ Currently, PgDog only supports `INSERT` statements with one tuple in the `VALUES
72
72
73
73
## DDL
74
74
75
-
DDL statements are sent to all shards in parallel. Currently, PgDog doesn't use 2-phase commit so consider using idempotent schema changes to guarantee consistency across shards.
75
+
DDL statements (e.g., `CREATE TABLE`) are sent to all shards in parallel. If [two-phase commit](2pc.md) is enabled, DDL statements have a high chance to be atomic.
0 commit comments