只读副本
Deploy read-only databases across multiple regions, for lower latency and better resource management.
只读副本是与你的主数据库保持同步的额外数据库。你可以从只读副本中读取数据,这有助于:
🌐 Read Replicas are additional databases kept in sync with your Primary database. You can read your data from a Read Replica, which helps with:
- 负载均衡: 只读副本可以减轻主数据库的负担。例如,你可以把复杂的分析查询放到只读副本上,而把主数据库留给用户的创建、更新和删除操作。
- 延迟改善: 对于拥有全球用户的项目,可以在更接近用户的地方部署额外的数据库,以减少延迟。
- 冗余: 只读副本提供数据冗余。

关于只读副本 #
🌐 About Read Replicas
当你启动 Supabase 项目时,你开始使用的数据库就是你的主数据库。一个叫做“复制”的过程会让只读副本与主数据库保持同步。复制是异步的,以确保主数据库上的事务不会被阻塞。从主数据库更新到只读副本接收到变更之间会有延迟,这个延迟叫做“复制延迟”.
🌐 The database you start with when launching a Supabase project is your Primary database. A process called "replication" keeps Read Replicas in sync with the Primary. 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."
你只能从只读副本读取数据。这和主数据库不同,主数据库既可以读取也可以写入:
🌐 You can only read data from a Read Replica. This is in contrast to a Primary database, where you can both read and write:
| 选择 | 插入 | 更新 | 删除 | |
|---|---|---|---|---|
| 主库 | ✅ | ✅ | ✅ | ✅ |
| 只读副本 | ✅ | - | - | - |
功能 #
🌐 Features
只读副本提供以下功能:
🌐 Read Replicas offer the following features:
专用端点 #
🌐 Dedicated endpoints
每个只读副本都有自己专用的数据库和 API 端点。
🌐 Each Read Replica has its own dedicated database and API endpoints.
- 在项目的连接面板中找到数据库端点。使用 来源 下拉菜单在主数据库和只读副本之间切换。
- 在API 设置页面的 项目 URL 下找到 API 端点。使用 Source 下拉菜单在主服务器和只读副本之间切换。
如果你使用 IPv4 插件,你的只读副本的数据库端点也会使用 IPv4 插件。
🌐 If you use an IPv4 add-on, the database endpoints for your Read Replicas also use an IPv4 add-on.
只读副本仅支持来自 REST API 的 GET 请求。如果你通过 REST API 调用只读 Postgres 函数,确保设置 get: true 选项。
🌐 Read Replicas only support GET requests from the REST API. If you are calling a read-only Postgres function through the REST API, make sure to set the get: true option.
对其他 Supabase 产品的请求,比如 Auth、Storage 和 Realtime,无法使用只读副本或其 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.
专用连接池 #
🌐 Dedicated connection pool
每个只读副本也可以通过 Supavisor 使用连接池。你可以在数据库设置页面的 连接字符串 下找到连接字符串。
🌐 A connection pool through Supavisor is also available for each Read Replica. Find the connection string on the Database Settings page under Connection String.
API 负载均衡器 #
🌐 API load balancer
负载均衡器会自动在你的主数据库和只读副本之间平衡请求。在API 设置页面可以找到它的端点。
🌐 A load balancer automatically balances requests between your Primary database and Read Replicas. Find its endpoint on the API Settings page.
负载均衡器支持数据 API 请求的地理路由功能,可以自动将 GET 请求路由到离用户最近的数据库,从而确保最低延迟。你也可以通过这个端点发送非 GET 请求,它们会自动路由到主数据库。
🌐 The load balancer enables geo-routing for Data API requests to automatically route GET requests to the database closest to your user ensuring the lowest latency. You can also send Non-GET requests through this endpoint, and they are routed to the Primary database automatically.
你也可以通过这个负载均衡器与其他 Supabase 服务(Auth、Edge Functions、Realtime 和 Storage)互动,所以不用担心在哪些情况下使用哪个端点。Auth、Realtime 和 Storage 的地理路由功能还没上线,但很快就会有。
🌐 You can also interact with other Supabase services (Auth, Edge Functions, Realtime, and Storage) through this load balancer so there's no need to worry about which endpoint to use and in which situations. Geo-routing for Auth, Realtime, and Storage aren't yet available but are coming soon.
由于认证服务的要求,即使通过负载均衡器端点发送,所有认证请求也都是由主节点处理。这和数据 API(PostgREST)的非读取请求完全由主节点处理的情况类似。
🌐 Due to the requirements of the Auth service, all Auth requests are handled by the Primary, even when sent over the load balancer endpoint. This is similar to how non-Read requests for the Data API (PostgREST) are exclusively handled by the Primary.
要通过 REST API 在只读副本上调用只读 Postgres 函数,请使用 get: true 选项。
🌐 To call a read-only Postgres function on Read Replicas through the REST API, use the get: true option.
如果你从项目中移除所有只读副本,负载均衡器及其端点也会被移除。移除之前,确保将请求重定向回你的主数据库。
🌐 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.
从2025年4月4日起,符合条件的数据 API 请求的路由行为发生了变化:
🌐 From April 4th, 2025, the routing behavior for eligible Data API requests changed:
- 旧行为:对你项目的所有数据库(所有只读副本 + 主库)进行轮询分发,不管位置在哪里
- 新行为:地理路由,将请求导向最近的可用数据库(所有只读副本 + 主库)
这种新行为通过将延迟降至最低,为你的用户带来更好的体验。你可以通过将只读副本放在主要客户群附近来充分利用这一点。
🌐 The new behavior delivers a better experience for your users by minimizing the latency to your project. You can take full advantage of this by placing Read Replicas close to your major customer bases.
如果你使用 自定义域名,请求将不会通过负载均衡器路由。你应该使用仪表板中提供的专用端点。
🌐 If you use a custom domain, requests will not be routed through the load balancer. You should instead use the dedicated endpoints provided in the dashboard.
通过 SQL 编辑器查询 #
🌐 Querying through the SQL editor
在 SQL 编辑器中,你可以选择是否在特定的只读副本上执行查询。
🌐 In the SQL editor, you can choose if you want to run the query on a particular Read Replica.

伐木 #
🌐 Logging
当部署只读副本时,它会从以下服务发出日志:
🌐 When a Read Replica is deployed, it emits logs from the following services:
在 Log Explorer 上的视图会自动按数据库过滤,默认显示主数据库的日志。你可以通过日志浏览器页面右上角的 Source 按钮切换查看其他数据库的日志。
🌐 Views on Log Explorer 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.
对于 API 日志,日志也可能来自 API 负载均衡器。上游数据库或最终处理请求的数据库可以在 Redirect Identifier 字段中找到。在查询底层日志时,这相当于 metadata.load_balancer_redirect_identifier。
🌐 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.
指标 #
🌐 Metrics
可观察性和指标对于只读副本可以在 Supabase 仪表板上查看。特定只读副本的资源使用情况可以通过切换 Source 在数据库报告页面上查看。同样,通过只读副本或负载均衡 API 端点的 API 请求指标也可以在仪表板上的API 报告页面查看。
🌐 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 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
我们建议将你的项目指标导入到你自己的环境中。如果你的项目已经设置了现有的导入管道,你可以更新它以额外导入来自只读副本的指标。
🌐 We recommend ingesting your project's metrics into your own environment. If you have an existing ingestion pipeline set up for your project, you can update it to additionally ingest metrics from your Read Replicas.
集中配置管理 #
🌐 Centralized configuration management
通过仪表板配置的所有设置都会传播到项目的所有数据库中。这可以确保没有只读副本与主数据库或其他只读副本不同步。
🌐 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.
价格 #
🌐 Pricing
想详细了解我们如何计算费用,请阅读管理只读副本使用指南。
🌐 For a detailed breakdown of how we calculate charges, read the Manage Read Replica usage guide.