Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: updates to Read Replica documentation (#26813)

angelicof697169c7f03
diff --git a/apps/docs/content/guides/platform/logs.mdx b/apps/docs/content/guides/platform/logs.mdx
index fb7d0e5b549..de7b42234f4 100644
--- a/apps/docs/content/guides/platform/logs.mdx
+++ b/apps/docs/content/guides/platform/logs.mdx
@@ -21,14 +21,16 @@ Supabase provides a logging interface specific to each product. You can use simp
>
<TabPanel id="api" label="API">
-[API logs](https://supabase.com/dashboard/project/_/database/api-logs) show all network requests and response for the REST and GraphQL [APIs](../../guides/database/api).
+[API logs](https://supabase.com/dashboard/project/_/logs/edge-logs) show all network requests and response for the REST and GraphQL [APIs](../../guides/database/api). If [Read Replicas](/docs/guides/platform/read-replicas) are enabled, logs are automatically filtered between databases as well as the [API Load Balancer](/docs/guides/platform/read-replicas#api-load-balancer) endpoint. Logs for a specific endpoint can be toggled with the `Source` button on the upper-right section of the dashboard.
+
+When viewing logs originating from the API Load Balancer endpoint, the upstream database or the one that eventually handles the request can be found under the `Redirect Identifier` field. This is equivalent to `metadata.load_balancer_redirect_identifier` when querying the underlying logs.
![API Logs](/docs/img/guides/platform/logs/logs-api.png)
</TabPanel>
<TabPanel id="postgres" label="Postgres">
-[Postgres logs](https://supabase.com/dashboard/project/_/logs/postgres-logs) show queries and activity for your [database](../../guides/database).
+[Postgres logs](https://supabase.com/dashboard/project/_/logs/postgres-logs) show queries and activity for your [database](../../guides/database). If [Read Replicas](/docs/guides/platform/read-replicas) are enabled, logs are automatically filtered between databases. Logs for a specific database can be toggled with the `Source` button on the upper-right section of the dashboard.
![Postgres Logs](/docs/img/guides/platform/logs/logs-database.png)
diff --git a/apps/docs/content/guides/platform/read-replicas.mdx b/apps/docs/content/guides/platform/read-replicas.mdx
index 7bb1247db8f..882892700d6 100644
--- a/apps/docs/content/guides/platform/read-replicas.mdx
+++ b/apps/docs/content/guides/platform/read-replicas.mdx
@@ -39,11 +39,9 @@ You can only read data from a Read Replica. This is in contrast to a Primary dat
## Prerequisites
-<Admonition type="note" label="Read Replicas are available on the Team and Enterprise plans">
+<Admonition type="note">
-Read replicas are available to projects created on the Teams and Enterprise plans on or after 2023 January 1. They will be progressively rolled out to older projects, and eventually available on the Pro plan.
-
-If your project doesn't meet these criteria, you can join the [early access queue](https://forms.supabase.com/read-replica).
+Read Replicas are available for all projects on the Pro, Team and Enterprise plans. Spin one up now over at the [Infrastructure Settings page](/dashboard/project/_/settings/infrastructure).
</Admonition>
@@ -63,18 +61,45 @@ Projects must meet these requirements to use Read Replicas:
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.
+### Deploying a Read Replica
+
+A Read Replica is deployed by using a physical backup as a starting point, and a combination of WAL file archives and direct replication from the Primary database to catch up. Both components may take significant time to complete. The duration of restoring from a physical backup is roughly dependent and directly related to the database size of your project. The time taken to catch up to the primary using WAL archives and direct replication is dependent on the level of activity on the Primary database; a more active database will produce a larger number of WAL files that will need to be processed.
+
+Along with the progress of the deployment, the dashboard displays rough estimates for each component.
+
+### What does it mean when "Init failed" is observed?
+
+The status `Init failed` indicates that the Read Replica has failed to deploy. Some possible scenarios as to why a Read Replica may have failed to be deployed:
+
+- Underlying instance failed to come up.
+- Network issue leading to inability to connect to the Primary database.
+- Possible incompatible database settings between the Primary and Read Replica databases.
+- Platform issues.
+
+It is safe to drop this failed Read Replica, and in the event of a transient issue, attempt to spin up another one. If however spinning up Read Replicas for your project consistently fails, do check out our [status page](https://status.supabase.com) for any ongoing incidents, or open a support ticket [here](/dashboard/support/new). To aid the investigation, do not bring down the recently failed Read Replica.
+
## Features
Read Replicas offer the following features:
### Dedicated endpoints
+<Admonition type="note" label="Known bug in PostgREST schema reloading">
+
+For Read Replicas deployed before May 24, 2024, there is a known bug that results in the [PostgREST schema cache](https://postgrest.org/en/v12/references/schema_cache.html) on Read Replicas not being reloaded correctly on DDL changes. A stale schema cache can result in PostgREST on Read Replicas not knowing about newly created functions, tables, changes to their structure, etc.
+
+A fix for this issue has already been deployed for newer Read Replicas but not fully applied for older ones as it requires a restart of the API service. You can perform a one-time restart of the service by [saving any trivial configuration change](https://supabase.com/dashboard/project/_/settings/api) to your PostgREST configuration (For example, changing the `Max Rows` by 1), which will result in the service being restarted.
+
+</Admonition>
+
Each Read Replica has its own dedicated database and API endpoints.
- Find the database endpoint on the [Database Settings page](/dashboard/project/_/settings/database) under **Connection Info**
- Find the API endpoint on the [API Settings page](/dashboard/project/_/settings/api) under **Project URL**
-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.
+Read Replicas only support `GET` requests from the [REST API](/docs/guides/api). If you are calling a read-only Postgres function through the REST API, make sure to set the `get: true` [option](/docs/reference/javascript/rpc?queryGroups=example&example=call-a-read-only-postgres-function).
+
+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.
If you're using an [IPv4 add-on](/docs/guides/platform/ipv4-address#read-replicas), the database endpoints for your Read Replicas will also use an IPv4 add-on.
@@ -82,16 +107,22 @@ If you're using an [IPv4 add-on](/docs/guides/platform/ipv4-address#read-replica
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**.
-## API load balancer
+### API load balancer
-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).
+A load balancer is deployed to automatically balance requests between your Primary database and Read Replicas. Find its endpoint on the [API Settings page](/dashboard/project/_/settings/api).
-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.
+The load balancer uses a round-robin strategy to route `GET` requests to all available API endpoints, including the Primary database. This means that `GET` requests are randomly and evenly split among databases. Non-`GET` requests can also be sent through this endpoint, and will be routed to the Primary database.
-To call a read-only Postgres function on Read Replicas, use the `get: true` [option](/docs/reference/javascript/rpc?queryGroups=example&example=call-a-read-only-postgres-function).
+To call a read-only Postgres function on Read Replicas through the REST API, use the `get: true` [option](/docs/reference/javascript/rpc?queryGroups=example&example=call-a-read-only-postgres-function).
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.
+<Admonition type="caution">
+
+If you use a [custom domain](/docs/guides/platform/custom-domains), requests will not be routed through the load balancer. You should instead use the dedicated endpoints provided in the dashboard.
+
+</Admonition>
+
### Querying through the SQL editor
In the SQL editor, you can choose if you want to run the query on a particular Read Replica.
@@ -112,17 +143,24 @@ In the SQL editor, you can choose if you want to run the query on a particular R
</figure>
-### Metrics
+### Logging
-Observability and metrics for Read Replicas are not currently available in the Supabase Dashboard.
+When a Read Replica is deployed, it emits logs from the following services:
-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.
+- [API](/dashboard/project/_/logs/edge-logs)
+- [Postgres](/dashboard/project/_/logs/postgres-logs)
+- [PostgREST](/dashboard/project/_/logs/postgrest-logs)
+- [Supavisor](/dashboard/project/_/logs/pooler-logs)
-<Admonition type="caution">
+Views on [Log Explorer](/docs/guides/platform/logs) are automatically filtered by databases, with the logs of the Primary database displayed by default. Viewing logs from other databases can be toggled with the `Source` button found on the upper-right part section of the Logs Explorer page.
-If you use a [custom domain](/docs/guides/platform/custom-domains), requests will not be routed through the load balancer. You should use the dedicated endpoints provided in the dashboard.
+For API logs, logs can originate from the API Load Balancer as well. The upstream database or the one that eventually handles the request can be found under the `Redirect Identifier` field. This is equivalent to `metadata.load_balancer_redirect_identifier` when querying the underlying logs.
-</Admonition>
+### Metrics
+
+Observability and metrics for Read Replicas are available on the Supabase Dashboard. Resource utilization for a specific Read Replica can be viewed on the [Database Reports page](/dashboard/project/_/reports/database) by toggling for `Source`. Likewise, metrics on API requests going through either a Read Replica or Load Balancer API endpoint are also available on the dashboard through the [API Reports page](/dashboard/project/_/reports/api-overview)
+
+We recommend ingesting your [project's metrics](/docs/guides/platform/metrics#accessing-the-metrics-endpoint) into your own environment. If you have an existing ingestion pipeline set up for your project, you can [update it](https://github.com/supabase/supabase-grafana?tab=readme-ov-file#read-replica-support) to additionally ingest metrics from your Read Replicas.
### Centralized configuration management
@@ -168,3 +206,9 @@ In this replication method, the Primary continuously buffers WAL changes to a lo
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.
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.
+
+### Monitoring replication lag
+
+Replication lag for a specific Read Replica can be monitored through the dashboard. On the [Database Reports page](/dashboard/project/_/reports/database) Read Replicas will have an additional chart under `Replica Information` displaying historical replication lag in seconds. Realtime replication lag in seconds can be observed on the [Infrastructure Settings page](/dashboard/project/_/settings/infrastructure). This is the value on top of the Read Replica. Do note that there is no single threshold to indicate when replication lag should be addressed. It would be fully dependent on the requirements of your project.
+
+If you are already ingesting your [project's metrics](/docs/guides/platform/metrics#accessing-the-metrics-endpoint) into your own environment, you can also keep track of replication lag and set alarms accordingly with the metric: `physical_replication_lag_physical_replica_lag_seconds`.
diff --git a/apps/docs/content/guides/platform/troubleshooting.mdx b/apps/docs/content/guides/platform/troubleshooting.mdx
index 0b4c96254cc..485a2f4efee 100644
--- a/apps/docs/content/guides/platform/troubleshooting.mdx
+++ b/apps/docs/content/guides/platform/troubleshooting.mdx
@@ -27,7 +27,9 @@ Some common solutions for this issue are:
- [Upgrading](https://supabase.com/dashboard/project/_/settings/addons?panel=computeInstance) to a [larger compute add-on](../platform/compute-add-ons) in order to serve higher volumes of traffic.
- [Optimizing the queries](../platform/performance#examining-query-performance) being executed.
- [Using fewer Postgres connections](../platform/performance#configuring-clients-to-use-fewer-connections) can reduce the amount of resources needed on the project.
-- [Restarting](https://supabase.com/dashboard/project/_/settings/general) the database. This only temporarily solves the issue by terminating any ongoing workloads that might be tying up your compute resources.
+- [Restarting](https://supabase.com/dashboard/project/_/settings/general) the project. This only temporarily solves the issue by terminating any ongoing workloads that might be tying up your compute resources.
+ - All databases of the project, including [Read replicas](/docs/guides/platform/read-replicas), will be restarted.
+ - If you only want to restart a specific Read Replica, you can do so from the [Infrastructure Settings page](/dashboard/project/_/settings/infrastructure).
If your [Disk IO budget](../platform/compute-add-ons#disk-io) has been drained, you will need to either wait for it to be replenished the next day, or upgrade to a larger compute add-on to increase the budget available to your project.
diff --git a/packages/shared-data/logConstants.ts b/packages/shared-data/logConstants.ts
index 28e1e31e8f0..89089e95f57 100644
--- a/packages/shared-data/logConstants.ts
+++ b/packages/shared-data/logConstants.ts
@@ -7,6 +7,7 @@ const schemas = [
{ path: 'timestamp', type: 'datetime' },
{ path: 'event_message', type: 'string' },
{ path: 'identifier', type: 'string' },
+ { path: 'metadata.load_balancer_redirect_identifier', type: 'string' },
{ path: 'metadata.request.cf.asOrganization', type: 'string' },
{ path: 'metadata.request.cf.asn', type: 'number' },
{ path: 'metadata.request.cf.botManagement.corporateProxy', type: 'boolean' },
@@ -222,6 +223,7 @@ const schemas = [
fields: [
{ path: 'event_message', type: 'string' },
{ path: 'id', type: 'string' },
+ { path: 'identifier', type: 'string' },
{ path: 'timestamp', type: 'datetime' },
{ path: 'metadata.host', type: 'string' },
],