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: apps/docs/content/guides/platform/read-replicas.mdx
+56-44Lines changed: 56 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,17 @@
1
1
---
2
2
title: 'Read Replicas'
3
-
description: 'Deploy additional read-only databases in multiple regions for your project.'
4
-
subtitle: 'Deploy additional read-only databases in multiple regions for your project'
3
+
description: 'Deploy read-only databases across multiple regions, for lower latency.'
4
+
subtitle: 'Deploy read-only databases across multiple regions, for lower latency and better resource management.'
5
5
---
6
6
7
-
<Admonitiontype="note"label="Read Replicas are available to Pro, Team, and Enterprise organizations who have signed up for early access.">
7
+
Read Replicas are additional databases that are kept in sync with your Primary database. You can read your data from a Read Replica, which helps with:
8
8
9
-
[Request early access](https://forms.supabase.com/read-replica) and you'll be notified once Read Replicas are available to your organization.
10
-
11
-
</Admonition>
9
+
-**Load balancing:** Read Replicas reduce load on the Primary database. For example, you can use a Read Replica for complex analytical queries and reserve the Primary for user-facing create, update, and delete operations.
10
+
-**Improved latency:** For projects with a global user base, additional databases can be deployed closer to users to reduce latency.
11
+
-**Redundancy:** Read Replicas provide data redundancy.
12
12
13
13
<figureclassName="max-w-[700px] mx-auto">
14
+
14
15
<Image
15
16
className="hidden dark:block"
16
17
alt="Map view of all project databases"
@@ -25,57 +26,74 @@ subtitle: 'Deploy additional read-only databases in multiple regions for your pr
25
26
26
27
</figure>
27
28
28
-
Read Replicas are Postgres databases that are continuously synced to a Supabase project's Primary database. You can both read from and write to a Primary database, but you can _only_ read from a Read Replica, such as using `select` statements.
29
+
## About Read Replicas
30
+
31
+
The database you start with when launching a Supabase project is your Primary database. Read Replicas are kept in sync with the Primary through a process called "replication." Replication is asynchronous to ensure that transactions on the Primary aren't blocked. There is a delay between an update on the Primary and the time that a Read Replica receives the change. This delay is called "replication lag."
32
+
33
+
You can only read data from a Read Replica. This is in contrast to a Primary database, where you can both read and write:
A database is spun up automatically with every Supabase project. This database is the Primary database. You can choose to add Read Replicas to your project and those Replicas will receive and synchronize data from the Primary database.
40
+
## Prerequisites
36
41
37
-
Replication is asynchronous and happens in the background so transactions on the Primary aren't blocked. The time delay between writing data to the Primary and the Read Replica receiving the change is replication lag.
42
+
<Admonitiontype="note"label="Read Replicas are available on the Team and Enterprise plans">
38
43
39
-
Read Replicas have many applications:
44
+
Read replicas are available to projects created on the Teams and Enterprise plans after 2024 March 20. They will be progressively rolled out to older projects, and eventually available on the Pro plan.
40
45
41
-
- They reduce read load on the Primary database.
42
-
- For example, you can use a Read Replica for complex analytical queries and reserve the Primary for user-facing create, update, and delete operations.
43
-
- For projects that need to cover a global audience, additional databases can be deployed closer to users in any of our twelve supported regions to reduce latency.
44
-
- Read Replicas provide data redundancy.
46
+
If your project doesn't meet these criteria, you can join the [early access queue](https://forms.supabase.com/read-replica).
45
47
46
-
## Prerequisites
48
+
</Admonition>
47
49
48
-
A project needs to satisfy these requirements to deploy a Read Replica:
50
+
Projects must meet these requirements to use Read Replicas:
49
51
50
52
1. Running on AWS.
51
53
- Support for projects on Fly.io is coming.
52
54
1. Running on at least a [Small compute add-on](/docs/guides/platform/compute-add-ons).
53
-
- Read Replicas are currently placed on the same compute instance as the database to make sure they can keep up with the Primary's activities.
54
-
1. Running on Postgres 15.
55
-
- For projects running on older versions of PostgreSQL, you will need to [upgrade to the latest platform version](/docs/guides/platform/migrating-and-upgrading-projects#pgupgrade).
55
+
- Read Replicas are started on the same compute instance as the Primary to keep up with changes.
56
+
1. Running on Postgres 15+.
57
+
- For projects running on older versions of Postgres, you will need to [upgrade to the latest platform version](/docs/guides/platform/migrating-and-upgrading-projects#pgupgrade).
56
58
1. Using [physical backups](/docs/guides/platform/backups#point-in-time-recovery)
57
59
- Physical backups are automatically enabled if using [PITR](/docs/guides/platform/backups#point-in-time-recovery)
58
60
- If you're not using PITR, you'll be able to switch to physical backups as part of the Read Replica setup process. Note that physical backups can't be downloaded from the dashboard in the way logical backups can.
59
61
60
62
## Getting started
61
63
62
-
Read Replicas can be managed from the [infrastructure settings page](https://supabase.com/dashboard/project/_/settings/infrastructure). For now, each project can only deploy up to two Read Replicas and all Read Replicas inherit the compute size of their Primary database.
64
+
To add a Read Replica, go to the [Infrastructure Settings page](/dashboard/project/_/settings/infrastructure) in your dashboard. Each project can deploy up to two Read Replicas and all Read Replicas inherit the compute size of their Primary database.
65
+
66
+
## Features
63
67
64
68
Read Replicas offer the following features:
65
69
66
70
### Dedicated endpoints
67
71
68
-
Each Read Replica has its own dedicated database and API endpoints. The database endpoint can be found in your [dashboard database settings](https://supabase.com/dashboard/project/_/settings/database) under **Connection info**. The API endpoint can be found in [dashboard API settings](https://supabase.com/dashboard/project/_/settings/api) under **Project URL**.
72
+
Each Read Replica has its own dedicated database and API endpoints.
73
+
74
+
- Find the database endpoint on the [Database Settings page](/dashboard/project/_/settings/database) under **Connection Info**
75
+
- Find the API endpoint on the [API Settings page](/dashboard/project/_/settings/api) under **Project URL**
69
76
70
-
A Read Replica's API endpoint only supports`GET` requests to the [REST API](https://supabase.com/docs/guides/api). Requests towards other Supabase products, such as Auth, Storage, and Realtime, are not able to utilize a Read Replica nor its API endpoint for now. We are working on adding Read Replica support for them.
77
+
Read Replicas only support`GET` requests and the [REST API](/docs/guides/api). Requests to other Supabase products, such as Auth, Storage, and Realtime, aren't able to use a Read Replica or its API endpoint. Support for more products will be added in the future.
71
78
72
-
###Dedicated connection pool
79
+
## Dedicated connection pool
73
80
74
-
A connection pool through Supavisor is also available for each Read Replica. Its unique connection string can be found in your [dashboard database settings](https://supabase.com/dashboard/project/_/settings/database) under **Connection string**.
81
+
A connection pool through Supavisor is also available for each Read Replica. Find the connection string on the [Database Settings page](/dashboard/project/_/settings/database) under **Connection String**.
82
+
83
+
## API load balancer
84
+
85
+
A load balancer is deployed to balance requests between your Primary database and Read Replicas. Find its endpoint on the [API Settings page](/dashboard/project/_/settings/api).
86
+
87
+
The load balancer uses a round-robin strategy to route `GET` requests to all available API endpoints, including the Primary database. Non-`GET` requests can also be sent through this endpoint, and will be routed to the Primary database. Read-only Postgres functions can be called using a [`GET` request](https://github.com/supabase/supabase-js/blob/v2.42.3/src/SupabaseClient.ts#L176-L177) as well.
88
+
89
+
If you remove all Read Replicas from your project, the load balancer and its endpoint are removed as well. Make sure to redirect requests back to your Primary database before removal.
75
90
76
91
### Querying through the SQL editor
77
92
93
+
In the SQL editor, you can choose if you want to run the query on a particular Read Replica.
94
+
78
95
<figureclassName="max-w-[700px] mx-auto">
96
+
79
97
<Image
80
98
className="hidden dark:block"
81
99
alt="SQL editor view."
@@ -90,23 +108,28 @@ A connection pool through Supavisor is also available for each Read Replica. Its
90
108
91
109
</figure>
92
110
93
-
In the SQL editor, you can choose if you want to run the query on the Primary or one of the Replicas.
111
+
### Metrics
94
112
95
-
### API load balancer
113
+
Observability and metrics for Read Replicas are not currently available in the Supabase Dashboard.
96
114
97
-
When Read Replicas are deployed, an API load balancer becomes available for the project. An endpoint for it is provisioned and can be found [here](https://supabase.com/dashboard/project/_/settings/api).
115
+
If you're ingesting your [project's metrics](/docs/guides/platform/metrics#accessing-the-metrics-endpoint) into your own environment, you can update [your scraping setup](https://github.com/supabase/supabase-grafana?tab=readme-ov-file#read-replica-support) to additionally ingest metrics from your Read Replicas.
98
116
99
-
The load balancer uses a round-robin strategy to route `GET` requests to any of the API endpoints available, including that of the Primary database. Non-`GET` requests can also be sent through this endpoint. They are immediately redirected to the Primary database.
117
+
### Centralized configuration management
100
118
101
-
Similar to the Read Replica API endpoints, only requests to the REST API are available for now. Support for other Supabase products will become available once Read Replica support has been completed for them.
119
+
All settings configured through the dashboard will be propagated across all databases of a project. This ensures that no Read Replica get out of sync with the Primary database or with other Read Replicas.
102
120
103
-
When a project no longer has any Read Replicas, the load balancer and its endpoint are brought down as well.
121
+
## Operations blocked by Read Replicas
104
122
105
-
### Centralized configuration management
123
+
### Project upgrades and data restorations
106
124
107
-
All settings made through the dashboard will be propagated across all databases of a project. This ensures that no Read Replica get out of sync with its Primary database or with other Read Replicas.
125
+
The following procedures require all Read Replicas for a project to be brought down before they can be performed:
These operations need to be completed before Read Replicas can be re-deployed.
131
+
132
+
## About replication
110
133
111
134
We use a hybrid approach to replicate data from a Primary to its Read Replicas, combining the native methods of streaming replication and file-based log shipping.
112
135
@@ -135,14 +158,3 @@ In this replication method, the Primary continuously buffers WAL changes to a lo
135
158
We bring these two methods together to achieve quick, stable, and reliable replication. Each method addresses the limitations of the other. Streaming replication minimizes replication lag, while file-based log shipping provides a fallback. For file-based log shipping, we use our existing Point In Time Recovery (PITR) infrastructure. We regularly archive files from the Primary using [WAL-G](https://github.com/wal-g/wal-g), an open source archival and restoration tool, and ship the WAL files to S3.
136
159
137
160
We combine it with streaming replication to reduce replication lag. Once WAL-G files have been synced from S3, Read Replicas connect to the Primary and stream the WAL directly.
138
-
139
-
## Operations blocked by Read Replicas
140
-
141
-
### Project upgrades and data restorations
142
-
143
-
The following procedures require all Read Replicas for a project to be brought down before they can be performed:
0 commit comments