文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 97%

29.12.11 性能模式复制表29.12.11 Performance Schema Replication Tables

性能模式提供了显示复制信息的表。这类似于使用 SHOW REPLICA STATUS 语句可获得的信息,但以表格形式表示更易于访问,并且具有可用性优势:The Performance Schema provides tables that expose replication information. This is similar to the information available from the SHOW REPLICA STATUS statement, but representation in table form is more accessible and has usability benefits:

  • SHOW REPLICA STATUS 的输出对于直观检查很有用,但对程序化使用并不太适合。相比之下,使用性能模式表,可以通过通用的 SELECT 查询搜索副本状态信息,包括复杂的 WHERE 条件、连接等。SHOW REPLICA STATUS output is useful for visual inspection, but not so much for programmatic use. By contrast, using the Performance Schema tables, information about replica status can be searched using general SELECT queries, including complex WHERE conditions, joins, and so forth.

  • 查询结果可以保存到表中以便进一步分析,或者赋值给变量,从而在存储过程中使用。Query results can be saved in tables for further analysis, or assigned to variables and thus used in stored procedures.

  • 复制表提供了更好的诊断信息。对于多线程从库操作,SHOW REPLICA STATUS 使用 Last_SQL_Errno 和 Last_SQL_Error 字段报告所有协调器和工作线程错误,因此只能看到这些错误的最新信息,可能会丢失信息。复制表按线程存储错误信息,不会丢失数据。The replication tables provide better diagnostic information. For multithreaded replica operation, SHOW REPLICA STATUS reports all coordinator and worker thread errors using the Last_SQL_Errno and Last_SQL_Error fields, so only the most recent of those errors is visible and information can be lost. The replication tables store errors on a per-thread basis without loss of information.

  • 最后看到的事务可以在复制表中按每个工作线程查看。这是 SHOW REPLICA STATUS 无法提供的信息。The last seen transaction is visible in the replication tables on a per-worker basis. This is information not available from SHOW REPLICA STATUS.

  • 熟悉 Performance Schema 接口的开发人员可以通过向表中添加行来扩展复制表,以提供额外的信息。Developers familiar with the Performance Schema interface can extend the replication tables to provide additional information by adding rows to the tables.

复制表说明Replication Table Descriptions

Performance Schema 提供以下与复制相关的表:The Performance Schema provides the following replication-related tables:

以下 Performance Schema 复制表在禁用 Performance Schema 时仍会继续填充:The following Performance Schema replication tables continue to be populated when the Performance Schema is disabled:

例外情况是复制表中的本地时间信息(事务的开始和结束时间戳):replication_connection_status、replication_applier_status_by_coordinator 和 replication_applier_status_by_worker。当性能模式被禁用时,这些信息不会被收集。The exception is local timing information (start and end timestamps for transactions) in the replication tables replication_connection_status, replication_applier_status_by_coordinator, and replication_applier_status_by_worker. This information is not collected when the Performance Schema is disabled.

以下各节将更详细地描述每个复制表,包括由 SHOW REPLICA STATUS 生成的列与复制表中出现相同信息的列之间的对应关系。The following sections describe each replication table in more detail, including the correspondence between the columns produced by SHOW REPLICA STATUS and the replication table columns in which the same information appears.

本复制表介绍的其余部分描述了 Performance Schema 如何填充这些表,以及 SHOW REPLICA STATUS 中哪些字段未在表中表示。The remainder of this introduction to the replication tables describes how the Performance Schema populates them and which fields from SHOW REPLICA STATUS are not represented in the tables.

复制表生命周期Replication Table Life Cycle

Performance Schema 按如下方式填充复制表:The Performance Schema populates the replication tables as follows:

  • 在执行 CHANGE REPLICATION SOURCE TO 之前,表是空的。Prior to execution of CHANGE REPLICATION SOURCE TO, the tables are empty.

  • 在 CHANGE REPLICATION SOURCE TO 之后,配置参数可以在表中看到。此时,没有活动的复制线程,因此 THREAD_ID 列为 NULL,SERVICE_STATE 列的值为 OFF。After CHANGE REPLICATION SOURCE TO, the configuration parameters can be seen in the tables. At this time, there are no active replication threads, so the THREAD_ID columns are NULL and the SERVICE_STATE columns have a value of OFF.

  • After START REPLICA, non-null THREAD_ID values can be seen. Threads that are idle or active have a SERVICE_STATE删除表中名为ON. The thread that connects to the source has a value of CONNECTING while it establishes the connection, and ON thereafter as long as the connection lasts.After START REPLICA, non-null THREAD_ID values can be seen. Threads that are idle or active have a SERVICE_STATE value of ON. The thread that connects to the source has a value of CONNECTING while it establishes the connection, and ON thereafter as long as the connection lasts.

  • 在 STOP REPLICA 之后,THREAD_ID 列变为 NULL,不再存在的线程的 SERVICE_STATE 列值为 OFF。After STOP REPLICA, the THREAD_ID columns become NULL and the SERVICE_STATE columns for threads that no longer exist have a value of OFF.

  • 在执行 STOP REPLICA 或线程因错误停止后,表格会被保留。The tables are preserved after STOP REPLICA or threads stopping due to an error.

  • replication_applier_status_by_worker 表仅在副本以多线程模式运行时非空。也就是说,如果 replica_parallel_workers 系统变量大于 0,则在执行 START REPLICA 时,该表会被填充,行数显示工作线程的数量。The replication_applier_status_by_worker table is nonempty only when the replica is operating in multithreaded mode. That is, if the replica_parallel_workers system variable is greater than 0, this table is populated when START REPLICA is executed, and the number of rows shows the number of workers.

复制状态信息在复制表中不存在Replica Status Information Not In the Replication Tables

性能模式复制表中的信息与通过SHOW REPLICA STATUS 获取的信息略有不同,因为这些表面向全局事务标识符(GTID)使用,而不是文件名和位置,并且它们表示的是服务器 UUID 值,而不是服务器 ID 值。由于这些差异,一些SHOW REPLICA STATUS列在性能模式复制表中未保留,或者以不同的方式表示:The information in the Performance Schema replication tables differs somewhat from the information available from SHOW REPLICA STATUS because the tables are oriented toward use of global transaction identifiers (GTIDs), not file names and positions, and they represent server UUID values, not server ID values. Due to these differences, several SHOW REPLICA STATUS columns are not preserved in the Performance Schema replication tables, or are represented a different way:

  • 以下字段涉及文件名和位置,未被保留:The following fields refer to file names and positions and are not preserved:

    Master_Log_File
    Read_Master_Log_Pos
    Relay_Log_File
    Relay_Log_Pos
    Relay_Master_Log_File
    Exec_Master_Log_Pos
    Until_Condition
    Until_Log_File
    Until_Log_Pos
    
  • Master_Info_File 字段不会被保留。它指的是用于副本源元数据存储库的 master.info 文件,该文件已被用于存储库的崩溃安全表所取代。The Master_Info_File field is not preserved. It refers to the master.info file used for the replica's source metadata repository, which has been superseded by the use of crash-safe tables for the repository.

  • 以下字段基于 server_id,而非 server_uuid,且不会被保留:The following fields are based on server_id, not server_uuid, and are not preserved:

    Master_Server_Id
    Replicate_Ignore_Server_Ids
    
  • Skip_Counter 字段基于事件计数,而非 GTID,并且不会被保留。The Skip_Counter field is based on event counts, not GTIDs, and is not preserved.

  • 这些错误字段是 Last_SQL_Errno 和 Last_SQL_Error 的别名,因此不会被保留:These error fields are aliases for Last_SQL_Errno and Last_SQL_Error, so they are not preserved:

    Last_Errno
    Last_Error
    

    在性能模式(Performance Schema)中,此错误信息可以在 replication_applier_status_by_worker 表的 LAST_ERROR_NUMBER 和 LAST_ERROR_MESSAGE 列中找到(如果副本是多线程的,也可以在 replication_applier_status_by_coordinator 中找到)。这些表提供的每线程错误信息比 Last_Errno 和 Last_Error 提供的更具体。In the Performance Schema, this error information is available in the LAST_ERROR_NUMBER and LAST_ERROR_MESSAGE columns of the replication_applier_status_by_worker table (and replication_applier_status_by_coordinator if the replica is multithreaded). Those tables provide more specific per-thread error information than is available from Last_Errno and Last_Error.

  • 提供关于命令行过滤选项信息的字段不会被保留:Fields that provide information about command-line filtering options is not preserved:

    Replicate_Do_DB
    Replicate_Ignore_DB
    Replicate_Do_Table
    Replicate_Ignore_Table
    Replicate_Wild_Do_Table
    Replicate_Wild_Ignore_Table
    
  • Replica_IO_State 和 Replica_SQL_Running_State 字段不会被保留。如果需要,可以通过使用适当复制表的 THREAD_ID 列,并将其与 INFORMATION_SCHEMA PROCESSLIST 表中的 ID 列进行连接,从后者表中选择 STATE 列来获取这些值。The Replica_IO_State and Replica_SQL_Running_State fields are not preserved. If needed, these values can be obtained from the process list by using the THREAD_ID column of the appropriate replication table and joining it with the ID column in the INFORMATION_SCHEMA PROCESSLIST table to select the STATE column of the latter table.

  • Executed_Gtid_Set 字段可能显示大量文本的数据集。相反,Performance Schema 表显示的是复制正在应用的事务的 GTID。或者,可以从 gtid_executed 系统变量的值中获取已执行 GTID 的集合。The Executed_Gtid_Set field can show a large set with a great deal of text. Instead, the Performance Schema tables show GTIDs of transactions that are currently being applied by the replica. Alternatively, the set of executed GTIDs can be obtained from the value of the gtid_executed system variable.

  • Seconds_Behind_Master 和 Relay_Log_Space 字段处于待定状态,且不会被保留。The Seconds_Behind_Master and Relay_Log_Space fields are in to-be-decided status and are not preserved.

复制通道Replication Channels

复制性能模式表的第一列是CHANNEL_NAME。这使得表可以按复制通道查看。在非多源复制设置中,只有一个默认复制通道。当您在副本上使用多个复制通道时,可以按复制通道过滤表,以监控特定的复制通道。有关更多信息,请参见第 19.2.2 节,“复制通道”和第 19.1.5.8 节,“多源复制监控”。The first column of the replication Performance Schema tables is CHANNEL_NAME. This enables the tables to be viewed per replication channel. In a non-multisource replication setup there is a single default replication channel. When you are using multiple replication channels on a replica, you can filter the tables per replication channel to monitor a specific replication channel. See Section 19.2.2, “Replication Channels” and Section 19.1.5.8, “Monitoring Multi-Source Replication” for more information.