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: src/content/docs/d1/best-practices/read-replication.mdx
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ To checkout D1 read replication and Sessions API:
18
18
19
19
[](https://deploy.workers.cloudflare.com/?url=https://github.com/lambrospetrou/d1-starter-sessions-api)
20
20
21
-
2. Enable read replication on the just created D1 database:
21
+
2. Enable read replication on the just created D1 database.
22
22
23
23
```curl
24
24
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/d1/database/{database_id}" \
@@ -27,6 +27,12 @@ curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/d1/datab
27
27
-d '{"read_replication": {"mode": "auto"}}'
28
28
```
29
29
30
+
:::note
31
+
To use REST API, you need to have an API token with `D1:Edit` permission.
32
+
33
+
If you do not have an API token, follow the guide: [Create API token](/fundamentals/api/get-started/create-token/).
@@ -183,7 +189,7 @@ All write queries are still forwarded to the primary database instance. Read rep
183
189
| Primary database instance | The database instance containing the “original” copy of the database | Can serve write queries | Can serve read queries |
184
190
| Read replica database instance | A database instance containing a copy of the original database which asynchronously receives updates from the primary database instance | Forwards any write queries to the primary database instance | Can serve read queries using its own copy of the database |
185
191
186
-
## Sessions API examples
192
+
## Use Sessions API
187
193
188
194
By using [Sessions API](/d1/worker-api/d1-database/#withsession) for read replication, all of your queries from a single <GlossaryTooltipterm="session">Session</GlossaryTooltip> read from a version of the database which ensures sequential consistency. This ensures that the version of the database you are reading is logically consistent even if the queries are handled by different read replicas.
189
195
@@ -192,7 +198,12 @@ D1 read replication achieves this by attaching a <GlossaryTooltip term="bookmark
192
198
### Enable read replication
193
199
194
200
With the REST API, set `read_replication.mode: auto` to enable read replication on a D1 database.
195
-
Use an [API token](/fundamentals/api/get-started/create-token/) with `D1:Edit`[permission](/fundamentals/api/reference/permissions/#account-permissions).
201
+
202
+
:::note
203
+
To use REST API, you need to have an API token with `D1:Edit` permission.
204
+
205
+
If you do not have an API token, follow the guide: [Create API token](/fundamentals/api/get-started/create-token/).
206
+
:::
196
207
197
208
<Tabs>
198
209
<TabItemlabel="cURL">
@@ -203,6 +214,7 @@ curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/d1/datab
0 commit comments