El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Relational Database Service/ Troubleshooting/ RDS for MySQL/ Primary/Standby Replication Issues/ Primary/Standby Replication Delay Scenarios and Solutions

Primary/Standby Replication Delay Scenarios and Solutions

Updated on 2024-10-24 GMT+08:00

RDS for MySQL standby instances, read replicas, self-built standby databases, and DR instances established through DRS all use MySQL Primary-Secondary Replication. Primary/standby replication can be implemented in asynchronous or semi-synchronous mode. In either mode, primary/standby replication delay is inevitable for some statements.

Symptom: The replication delay of the standby instance or read replica is too long, or even an alarm is generated for too long replication delay.

Scenario 1: Large Transaction Executed on the Primary Instance

A large transaction is a transaction containing a large quantity of data update operations, for example, a transaction including tens of thousands of DML (INSERT, UPDATE, and DELETE) operations, or an SQL statement that updates tens of thousands of rows of data in batches. The execution of a large transaction usually takes a long time (minutes). After a large transaction is executed on the primary instance, a large number of binlogs are generated. It takes much more time for the standby instance or read replica to obtain these binlogs than for a common transaction. In addition, replaying the transaction also takes much time, at least the same as the time for the transaction being executed on the primary instance. As a result, replication delay occurs on the standby node or read replica.

Troubleshooting:

  • For a large transaction that contains a large number of DML statements, run the following command to find the statement that is executed for a long time:

    select t.*,to_seconds(now())-to_seconds(t.trx_started) idle_time from INFORMATION_SCHEMA.INNODB_TRX t \G;

  • For a large transaction where an SQL statement executes a large amount of data updates, run show full processlist to check whether any DELETE or UPDATE statements are taking a long time to execute.
  • Analyze full logs or slow query logs to check whether there are any large transactions.

Solution:

  • To ensure data consistency between the primary and standby instances, wait until the large transaction is complete.
  • Split a large transaction into small transactions and execute them in batches. For example, you can use the WHERE condition or LIMIT statement to limit the amount of data to be updated each time.

Scenario 2: Table Without a Primary Key Updated

RDS for MySQL binlogs use row-based logging. When data in a row is updated, an event record in row format is generated in the binlog. For example, if an UPDATE statement updates 100 rows of data in a table, 100 rows of update records will be generated in the binlog. During playback on the standby instance or read replica, 100 single-row updates are executed.

When replaying binlog events of the primary instance, the standby instance or read replica searches for rows to be modified based on the primary key or unique secondary index of the table. If no primary key is created for the table, a large number of full table scans are generated. As a result, the application speed of the binlog is reduced and replication delay occurs.

Troubleshooting:

Use show create table xxx to find out which table has the problematic UPDATE or DELETE statement and check whether the table has a primary key.

Solution:

Add a primary key to the table without a primary key or add a unique secondary index as required.

Scenario 3: DDL Operation Performed

A DDL operation typically takes a long time to complete, especially if the table contains a large amount of data. Generally, the time for replaying a DDL operation on the standby instance or read replica is almost the same as that for executing the DDL operation on the primary instance. Therefore, after a DDL operation is performed on a large table in the primary instance, the replication time will increase when the standby instance or read replica replays the operation.

Solution:

Wait for the DDL execution to complete, or perform DDL operations during off-peak hours.

Scenario 4: Read Replica Waiting for a Metadata Lock

When a long transaction is being executed on a table in a read replica, the DDL operation of the table synchronized from the primary instance will be blocked due to a metadata lock, and subsequent binlog playback of the table is also blocked. As a result, the replication delay increases.

Troubleshooting:

  1. Log in to the read replica and run the following command to check whether there are any transactions that are taking a long time to complete:

    select t.*,to_seconds(now())-to_seconds(t.trx_started) idle_time from INFORMATION_SCHEMA.INNODB_TRX t \G;

  2. View the metadata lock view of the read replica to check whether a metadata lock conflict occurs.

    select * from information_schema.metadata_lock_info;

    Find the blocked session based on the thread ID in the metadata lock view. For more information, see MDL Views.

Solution:

Kill the long transaction that blocks DDL operations on the read replica, or commit the long transaction on the application.

Scenario 5: Read Replica Specifications Smaller Than the Primary Instance

If the specifications of the read replica or DR instance established through DRS are smaller than those of the primary instance and the write load of the primary instance increases somewhat, the read replica or DR instance cannot replay binlogs in a timely manner due to insufficient resources. As a result, the replication delay increases.

Solution:

Scale up the specifications of the read replica or DR instance to match the specifications of the primary instance.

Scenario 6: Sudden Increase in Read Requests

In addition to synchronizing data from the primary instance, the read replica also processes read requests. If read requests soar up, the replay threads of the read replica may be affected, leading to an increase in the replication delay.

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback