通过 Azure 门户创建和管理 Azure Database for PostgreSQL(单一服务器)中的只读副本Create and manage read replicas in Azure Database for PostgreSQL - Single Server from the Azure portal

本文介绍如何使用 Azure 门户在 Azure Database for PostgreSQL 中创建和管理只读副本。In this article, you learn how to create and manage read replicas in Azure Database for PostgreSQL from the Azure portal. 若要详细了解只读副本,请参阅概述To learn more about read replicas, see the overview.

先决条件Prerequisites

将用作主服务器的 Azure Database for PostgreSQL 服务器An Azure Database for PostgreSQL server to be the primary server.

Azure 复制支持Azure replication support

只读副本逻辑解码都依赖 Postgres 预写日志 (WAL) 来获取信息。Read replicas and logical decoding both depend on the Postgres write ahead log (WAL) for information. 这两个功能需要来自 Postgres 的不同级别的日志记录。These two features need different levels of logging from Postgres. 逻辑解码需要的日志记录的级别比只读副本需要的更高。Logical decoding needs a higher level of logging than read replicas.

若要配置正确的日志记录级别,请使用 Azure 复制支持参数。To configure the right level of logging, use the Azure replication support parameter. Azure 复制支持有三个设置选项:Azure replication support has three setting options:

  • 关闭 - 提供的 WAL 中的信息最少。Off - Puts the least information in the WAL. 大多数 Azure Database for PostgreSQL 服务器上都不提供此设置。This setting is not available on most Azure Database for PostgreSQL servers.
  • 副本 - 比“关闭”详细 。Replica - More verbose than Off. 这是运行读取副本所需的最低日志记录级别。This is the minimum level of logging needed for read replicas to work. 此设置是大多数服务器上的默认设置。This setting is the default on most servers.
  • 逻辑 - 比“副本”详细 。Logical - More verbose than Replica. 这是运行逻辑解码所需的最低日志记录级别。This is the minimum level of logging for logical decoding to work. 使用此设置时,只读副本也可以运行。Read replicas also work at this setting.

备注

为持久的大量写入密集型主工作负荷部署只读副本时,复制滞后时间可能会持续增长,并且可能永远无法赶上主工作负荷。When deploying read replicas for persistent heavy write-intensive primary workloads, the replication lag could continue to grow and may never be able to catch-up with the primary. 这还可能会增加主服务器上的存储使用量,因为 WAL 文件在副本收到它们之前不会被删除。This may also increase storage usage at the primary as the WAL files are not deleted until they are received at the replica.

准备主服务器Prepare the primary server

  1. 在 Azure 门户中,选择用作主服务器的现有 Azure Database for PostgreSQL 服务器。In the Azure portal, select an existing Azure Database for PostgreSQL server to use as a master.

  2. 在服务器菜单中,选择“复制”。From the server's menu, select Replication. 如果将 Azure 复制支持至少设置为“副本”,则可创建只读副本。If Azure replication support is set to at least Replica, you can create read replicas.

  3. 如果没有将 Azure 复制支持至少设置为“副本”,请进行此设置。If Azure replication support is not set to at least Replica, set it. 选择“保存” 。Select Save.

    Azure Database for PostgreSQL - 复制 - 设置副本并保存

  4. 通过选择“是”,重启服务器以应用更改。Restart the server to apply the change by selecting Yes.

    Azure Database for PostgreSQL - 复制 - 确认重启

  5. 操作完成后,会收到两个 Azure 门户通知。You will receive two Azure portal notifications once the operation is complete. 一个通知是关于更新服务器参数的。There is one notification for updating the server parameter. 另一个通知是关于随后立即进行的服务器重启的。There is another notification for the server restart that follows immediately.

    成功通知

  6. 刷新 Azure 门户页,更新“复制”工具栏。Refresh the Azure portal page to update the Replication toolbar. 现在可以为此服务器创建只读副本。You can now create read replicas for this server.

创建只读副本Create a read replica

若要创建只读副本,请遵循以下步骤:To create a read replica, follow these steps:

  1. 选择将用作主服务器的现有 Azure Database for PostgreSQL 服务器。Select an existing Azure Database for PostgreSQL server to use as the primary server.

  2. 在服务器边栏中的“设置”下,选择“复制”。 On the server sidebar, under SETTINGS, select Replication.

  3. 选择“添加副本”。Select Add Replica.

    添加副本

  4. 输入只读副本的名称。Enter a name for the read replica.

    为副本命名

  5. 选择副本的位置。Select a location for the replica. 默认位置与主服务器的位置相同。The default location is the same as the primary server's.

    选择位置

    备注

    若要详细了解可以在哪些区域中创建副本,请访问只读副本概念文章To learn more about which regions you can create a replica in, visit the read replica concepts article.

  6. 选择“确定”以确认创建该副本。Select OK to confirm the creation of the replica.

创建只读副本后,可以在“复制”窗口中查看它:After the read replica is created, it can be viewed from the Replication window:

在“复制”窗口中查看新副本

重要

查看“只读副本”概述的注意事项部分Review the considerations section of the Read Replica overview.

将主服务器设置更新为新值之前,请将副本设置更新为一个相等的或更大的值。Before a primary server setting is updated to a new value, update the replica setting to an equal or greater value. 此操作可帮助副本与主服务器发生的任何更改保持同步。This action helps the replica keep up with any changes made to the master.

停止复制Stop replication

可以停止主服务器与只读副本之间的复制。You can stop replication between a primary server and a read replica.

重要

停止复制到主服务器和只读副本后,无法撤消该操作。After you stop replication to a primary server and a read replica, it can't be undone. 只读副本将成为支持读取和写入的独立服务器。The read replica becomes a standalone server that supports both reads and writes. 独立服务器不能再次成为副本。The standalone server can't be made into a replica again.

若要在 Azure 门户中停止主服务器与只读副本之间的复制,请执行以下步骤:To stop replication between a primary server and a read replica from the Azure portal, follow these steps:

  1. 在 Azure 门户中,选择 Azure Database for PostgreSQL 主服务器。In the Azure portal, select your primary Azure Database for PostgreSQL server.

  2. 在服务器菜单中的“设置”下,选择“复制”。 On the server menu, under SETTINGS, select Replication.

  3. 选择要停止复制的副本服务器。Select the replica server for which to stop replication.

    选择副本

  4. 选择“停止复制”。Select Stop replication.

    选择停止复制

  5. 选择“确定”以停止复制。Select OK to stop replication.

    确认停止复制

删除主服务器Delete a primary server

若要删除主服务器,请执行删除 Azure Database for PostgreSQL 独立服务器的相同步骤。To delete a primary server, you use the same steps as to delete a standalone Azure Database for PostgreSQL server.

重要

删除主服务器后,将停止复制到所有只读副本。When you delete a primary server, replication to all read replicas is stopped. 只读副本将成为支持读取和写入的独立服务器。The read replicas become standalone servers that now support both reads and writes.

若要在 Azure 门户中删除服务器,请遵循以下步骤:To delete a server from the Azure portal, follow these steps:

  1. 在 Azure 门户中,选择 Azure Database for PostgreSQL 主服务器。In the Azure portal, select your primary Azure Database for PostgreSQL server.

  2. 此时会打开该服务器的“概述”页。Open the Overview page for the server. 选择“删除” 。Select Delete.

    在服务器的“概述”页面上,选择删除主服务器

  3. 输入要删除的主服务器的名称。Enter the name of the primary server to delete. 选择“删除”以确认删除主服务器。Select Delete to confirm deletion of the primary server.

    确认删除主服务器

删除副本Delete a replica

可以像删除主服务器一样删除只读副本。You can delete a read replica similar to how you delete a primary server.

  • 在 Azure 门户中,打开只读副本的“概述”页。In the Azure portal, open the Overview page for the read replica. 选择“删除” 。Select Delete.

    在副本的“概述”页上,选择删除该副本

也可以在“复制”窗口中遵循以下步骤删除只读副本:You can also delete the read replica from the Replication window by following these steps:

  1. 在 Azure 门户中,选择 Azure Database for PostgreSQL 主服务器。In the Azure portal, select your primary Azure Database for PostgreSQL server.

  2. 在服务器菜单中的“设置”下,选择“复制”。 On the server menu, under SETTINGS, select Replication.

  3. 选择要删除的只读副本。Select the read replica to delete.

    选择要删除的副本

  4. 选择“删除副本”。Select Delete replica.

    选择“删除副本”

  5. 输入要删除的副本的名称。Enter the name of the replica to delete. 选择“删除”以确认删除该副本。Select Delete to confirm deletion of the replica.

    确认删除副本

监视副本Monitor a replica

可以使用两个指标来监视只读副本。Two metrics are available to monitor read replicas.

“副本的最大滞后时间”指标Max Lag Across Replicas metric

“副本的最大滞后时间”指标显示主服务器与滞后时间最长的副本之间的滞后时间(以字节为单位)。The Max Lag Across Replicas metric shows the lag in bytes between the primary server and the most-lagging replica.

  1. 在 Azure 门户中,选择 Azure Database for PostgreSQL 主服务器。In the Azure portal, select the primary Azure Database for PostgreSQL server.

  2. 选择“指标”。Select Metrics. 在“指标”窗口中,选择“副本的最大滞后时间”。 In the Metrics window, select Max Lag Across Replicas.

    监视副本的最大滞后时间

  3. 对于“聚合”,请选择“最大”。 For your Aggregation, select Max.

“副本滞后时间”指标Replica Lag metric

“副本滞后时间”指标显示自从在副本上最后一次执行重放事务以来所经历的时间。The Replica Lag metric shows the time since the last replayed transaction on a replica. 如果主服务器上未发生任何事务,则该指标会反映此滞后时间。If there are no transactions occurring on your master, the metric reflects this time lag.

  1. 在 Azure 门户中,选择 Azure Database for PostgreSQL 只读副本。In the Azure portal, select the Azure Database for PostgreSQL read replica.

  2. 选择“指标”。Select Metrics. 在“指标”窗口中,选择“副本滞后时间”。 In the Metrics window, select Replica Lag.

    监视副本滞后时间

  3. 对于“聚合”,请选择“最大”。 For your Aggregation, select Max.

后续步骤Next steps