WO2017177941A1 - 主备数据库切换方法和装置 - Google Patents

主备数据库切换方法和装置 Download PDF

Info

Publication number
WO2017177941A1
WO2017177941A1 PCT/CN2017/080418 CN2017080418W WO2017177941A1 WO 2017177941 A1 WO2017177941 A1 WO 2017177941A1 CN 2017080418 W CN2017080418 W CN 2017080418W WO 2017177941 A1 WO2017177941 A1 WO 2017177941A1
Authority
WO
WIPO (PCT)
Prior art keywords
database
standby
last
location
primary
Prior art date
Application number
PCT/CN2017/080418
Other languages
English (en)
French (fr)
Inventor
张玲东
随建
黄鑫娟
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2017177941A1 publication Critical patent/WO2017177941A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • the present disclosure relates to the field of database technologies, and in particular, to a method and apparatus for switching between active and standby databases.
  • the MariaDB/MySQL database uses a master-slave replication strategy.
  • the core idea is that the primary database provides external services.
  • the main library The SQL of the update operation is written to the binary log (Bin log), and an index of the binary log file is maintained to facilitate the log file rotation (Rotate).
  • Bin log binary log
  • Rotate log file rotation
  • Master-slave replication is the backup of the host binlog log. Due to factors such as the host write log delay and the network communication delay and the backup log delay, the active and standby logs are not synchronized.
  • a service application layer user adds a monitoring table to the primary database, periodically updates the timestamp in the table, and the management module monitors the time in the primary and secondary monitoring tables. The difference between the stamps determines the gap between the master and the backup data. The other is to increase the DBAgent proxy module in the database master and backup machine, and periodically query the current binlog location of the database and report it to the management module.
  • the management module judges the data synchronization gap between the master and backup machines. condition.
  • the third-party management module is introduced, which increases the complexity of interaction. At the same time, when the third-party management module fails, the entire monitoring system is faulty.
  • the main purpose of the present disclosure is to provide a method and apparatus for switching between active and standby databases, which aims to solve the problem of poor data accuracy, complicated operation, and low stability when switching between the primary and secondary databases in the prior art.
  • the present disclosure provides a method for switching between active and standby databases, including:
  • connection local database service operation exceeds a preset number of times, determining that the local database is abnormal, and performing an alarm operation or performing an active/standby switch between the local database and the peer database Operation, or, if the number of failures of the current location of the peer database sent by the peer database exceeds a preset number of times, performing an alarm operation or performing an active/standby switch between the local database and the peer database operating.
  • the step of performing the operation of connecting the native database service comprises:
  • the step of receiving the current location of the peer database sent by the peer database includes:
  • the method further includes:
  • the alarm operation is performed when the difference between the current location of the local database and the current location of the peer database is greater than a preset threshold.
  • the steps of performing the active/standby switching operation include:
  • the local database is a standby database
  • the peer database is the primary database
  • an alarm operation is performed, and the connection detection operation is continued;
  • the log file of the local database is parsed, the last location of the local database is obtained, and the active/standby switchover is performed according to the last location. operating.
  • the step of performing an active/standby switching operation includes:
  • the last location of the primary database is not empty, compare the last location of the primary database with the current location of the standby database, where the automatic location is performed if the current location of the standby database is equal to the last location of the primary database a switching operation, if the current location of the standby database is smaller than a last location of the primary database, determining whether to perform the automatic switching operation according to a service requirement;
  • the last location of the primary database is empty, compare the current location of the primary database with the current location of the standby database, where if the current location of the standby database is greater than or equal to the current location of the primary database, execute The automatic switching operation, otherwise, determines whether to perform the automatic switching operation according to a service requirement.
  • the automatic switching operation comprises:
  • the standby database is switched to the primary database, and the active/standby replication relationship is restored after the standby database service is restored.
  • the step of acquiring the last location of the native database comprises:
  • the last log file of the last log file is scanned until the last event is found.
  • the present disclosure further provides an apparatus for switching between active and standby databases, including:
  • connection module is set to perform the operation of connecting the native database service
  • a location module configured to receive a current location of the peer database sent by the peer database
  • An execution module configured to determine that the local database is abnormal if the number of failures of the connection local database service operation exceeds a preset number of times, and perform an alarm operation or in the local database and the peer database Performing an active/standby switchover operation, or performing an alert operation or in the local database and the peer database if the number of failures of the current location of the peer database sent by the peer database exceeds a preset number of times Perform an active/standby switchover.
  • connection module is further configured to perform a connection local database service operation, and periodically acquire a current location of the local database;
  • the location module is further configured to receive a current location of the peer database sent by the peer database, and compare the current location of the local database with the current location of the peer database;
  • the device also includes:
  • the alarm module is configured to perform an alarm operation when a difference between a current location of the local database and a current location of the peer database is greater than a preset threshold.
  • the execution module is further configured to: if the local database is a standby database, and the peer database is a primary database, perform an alarm operation, and continue to perform a connection detection operation; If the local database is the primary database, and the peer database is the standby database, the log file of the local database is parsed, the last location of the local database is obtained, and the active/standby switchover is performed according to the last location. operating.
  • the execution module is further configured to compare a last location of the primary database with a current location of the standby database if the last location of the primary database is not empty, wherein if the current location of the standby database is equal to The last location of the primary database performs an automatic switching operation. If the current location of the standby database is less than the last location of the primary database, it is determined according to the service requirement whether to perform the automatic switching operation; if the primary database is last If the location is empty, comparing the current location of the primary database with the current location of the standby database, where the automatic switching operation is performed if the current location of the standby database is greater than or equal to the current location of the primary database, otherwise And, according to the business requirement, decide whether to perform the automatic switching operation.
  • the execution module is further configured to perform a specified orientation information binding operation if the user is a non-designated user.
  • the execution module is further configured to acquire a current log file list of the local database; start scanning from a last log file in the current log file list, and from the last one of the last log file The last location of the native database is obtained in the event; if the last event cannot be found from the last log file, the last log file of the last log file is scanned until the last event is found.
  • a storage medium comprising a stored program, wherein the program is executed to perform the method of any of the above.
  • a processor for running a program wherein the program is executed to perform the method of any of the above.
  • the present disclosure also provides a method and apparatus for switching between a primary and a secondary database, by performing a connection to a local database service operation; receiving a current location of a peer database sent by a peer database; and if the number of failed connection database services exceeds a preset number of times, Then, it is determined that the local database is abnormal, and an alarm operation is performed or an active/standby switchover operation is performed between the local database and the peer database, or If the number of failures of the current location of the peer database sent by the peer database exceeds the preset number of times, the alarm operation or the active/standby switchover between the local database and the peer database is performed, which solves the problem of the active/standby switch in the prior art.
  • the database is switched, the data accuracy is poor, the operation is complicated, and the stability is low. Real-time monitoring is achieved to grasp the synchronization gap between the primary and backup databases, simplify operations, ensure data consistency, and avoid mis-switching.
  • FIG. 1 is a schematic flowchart of a first embodiment of a method for switching between a primary and a standby database according to the present disclosure
  • FIG. 2 is a schematic diagram of a master and standby database replication monitoring management architecture in an embodiment of the present disclosure
  • FIG. 3 is a schematic flowchart of a second embodiment of a method for switching between a primary and a standby database according to the present disclosure
  • connection local database service operation exceeds a preset number of times, determining that the local database is abnormal, and performing an alarm operation or in the local database and the pair
  • FIG. 5 is a schematic flowchart of steps of performing an active/standby switching operation in an embodiment of the present disclosure
  • FIG. 6 is a schematic flow chart of steps of an automatic switching operation in an embodiment of the present disclosure.
  • FIG. 7 is a schematic flowchart of a step of acquiring a final location of the local database in an embodiment of the present disclosure
  • FIG. 8 is a diagram showing relationship changes of binlog log positions before and after active/standby switching in an embodiment of the present disclosure
  • FIG. 9 is a schematic diagram of functional modules of a first embodiment of a primary and secondary database switching device of the present disclosure.
  • FIG. 10 is a schematic diagram of functional modules of a second embodiment of a primary and secondary database switching apparatus according to the present disclosure.
  • a first embodiment of the present disclosure provides a method for switching between a primary and a standby database, including:
  • step S10 the operation of connecting the local database service is performed.
  • the executor of the method of the present disclosure may be a database management platform or a database server.
  • the specific application to the primary database or the standby database will be specifically described in the following description, and is of course not limited to other devices or servers capable of implementing the switching between the primary and secondary databases.
  • the disclosure mainly ensures that the database master/slave data synchronization process can be monitored by using the MariaDB and binlog logs to ensure fast and automatic switching when the database is abnormal.
  • the database agent software DBAgent (or other software capable of implementing the same function) can be deployed on the device where the active and standby databases are located.
  • the DBAgent is a database agent software, which can be used to monitor the running of the database service and parse the binlog.
  • the log file can be used to switch the control process in the event of a failure; in the operation of the MariaDB database, the related actions are recorded in the binlog log file, in order to read the synchronous data from the database, the MariaDB database execution process
  • the binlog log file is generated, the binlog position is given, that is, the current log position (long integer value).
  • the DBAgent of the active and standby databases periodically monitors the running status of the local database and the latest GTID in the current binlog log. At the same time, the active and standby databases share the running status of the active and standby databases.
  • the DBAgent of the primary database periodically connects to the primary database service port through a MYSQL protocol, queries and obtains the current location of the local database (current gtid_current_pos), and records and updates it, and sends it to the DBAgent of the standby database through the heartbeat message interface for recording.
  • the DBAgent of the standby database is periodically connected with a specific user through the MYSQL protocol.
  • the database service port queries and obtains the current location of the local database (current gtid_current_pos), and records and updates it, and sends it to the DBAgent of the primary database through the heartbeat message interface for recording.
  • Step S20 Receive a current location of the peer database sent by the peer database.
  • the local database is the primary database and the peer database is the standby database:
  • the DBAgent of the primary database receives the heartbeat message sent by the DBAgent of the standby database, and records the current gtid_current_pos location of the standby database.
  • the DBAgent of the standby database receives the heartbeat message sent by the DBAgent of the primary database, and records the current gtid_current_pos location of the primary database.
  • Step S30 if the number of failures of the connection local database service operation exceeds a preset number of times, determining that the local database is abnormal, and performing an alarm operation or between the local database and the peer database An active/standby switchover operation, or performing an alarm operation or between the local database and the peer database if the number of failures of the current location of the peer database sent by the peer database exceeds a preset number of times Active/standby switching operation.
  • the peer database is the primary database
  • the DBAgent connection database service of the standby database fails more than the specified number of times (for example, 10 times, the number of times may be preset by the system, or may be modified by the user according to actual usage conditions)
  • the current primary database is determined to be abnormal, and the connection detection operation is continued.
  • the DBAgent connection database service fails to exceed the specified number of times (for example, 10 times, the number can be preset by the system, or can be modified by the user according to the actual usage), determine the current primary database exception, and parse the log file of the primary database. The last location of the primary database is obtained, and the active/standby switchover operation is performed according to the last location.
  • the specified number of times for example, 10 times, the number can be preset by the system, or can be modified by the user according to the actual usage
  • the DBAgent of the primary database sends a handover request message to the DBAgent of the standby database, where the message includes the last_pos location of the primary database;
  • the DBAgent of the primary database continues to periodically check whether the database service is normal until the database service is restored;
  • the DBAgent of the primary database initiates an active/standby switchover process according to the last_pos location of the primary database in the handover request, where:
  • the last location of the primary database is not empty, compare the last location of the primary database with the current location of the standby database. If the current location of the standby database is equal to the last location of the primary database, an automatic switching operation is performed, if the current location of the standby database is smaller than the primary The final location of the database, whether to perform automatic switching operations according to business requirements;
  • the above automatic switching operation may be: switching the standby database as the primary database, and restoring the active/standby replication relationship after the standby database service is restored.
  • the host database is the primary database and the peer database is the standby database:
  • the alarm is generated.
  • the host database is the standby database and the peer database is the primary database:
  • the DBAgent of the standby database does not receive the heartbeat message sent by the DBAgent of the primary database beyond the specified number of times, connect the primary database service port to the current database gtid_current_pos through the MYSQL protocol. If the successful completion indicates that the DBAgent process of the primary database is abnormal, the database service Normally, you do not need to initiate the active/standby switchover. You only need to alarm and record the related logs. If the acquisition fails, the primary database DBAgent process and the database service are abnormal. You can initiate an active/standby switchover request.
  • the transaction When the main database executes a DDL statement or a transaction containing updated SQL, the transaction is assigned a globally unique order GTID number. Before the transaction commits, the binary binlog log file is simultaneously written to the slave database, and the binlog log of the master database is read from the database. The information is synchronized with the data, and the corresponding SQL statement is executed in response to the synchronization with the primary database data;
  • the database agent software DBAgent regularly monitors the running status of the local database service, and accesses the local database through the MYSQL protocol to monitor whether the database is running normally.
  • the local gtid_current_pos location of the local database is sent to send the heartbeat message to the peer DBAgent, and the DBAgent receives the heartbeat of the peer.
  • the location of the gtid_current_pos of the peer database is parsed, and the location of the gtid_current_pos of the local database and the peer database is compared, and the data synchronization of the master-slave database is judged according to the difference.
  • the difference between the master-slave database gtid_current_pos exceeds the set range, real-time alarms and other related measures are performed. .
  • the database agent software DBAgent actively connects to the peer database service through the MYSQL protocol, determines whether the peer database service is normal, and obtains the location of the gtid_current_pos of the peer database. If the connection fails, it determines that the peer database is abnormal, and decides whether to initiate the active/standby switch according to the master-slave role of the database.
  • the present disclosure provides a master-slave database switching method, which can monitor the master-slave data synchronization gap in real time, and indirectly understand the system's write transaction load change; remove the third-party management component and directly circumvent the The problem of the entire system being unavailable due to the failure of the three-party management component; simplifying the processing logic and simplifying the installation and deployment, the DBAgent can be bundled with the DB software, and the deployment of each database node is simple and convenient; the data of the database of the master and backup machines is quickly identified and the data is consistent. It can automatically perform active/standby switchover and build a new master-slave replication relationship. When the data is inconsistent, it can automatically generate differentiated SQL scripts, save time for manual intervention, and ensure data consistency. When the DBAgent itself is abnormal, the database service is normal, avoid unnecessary mis-switching.
  • a second embodiment of the present disclosure provides a method for switching between a primary and a standby database, including:
  • step S11 the operation of connecting the local database service is performed, and the current location of the local database is obtained periodically.
  • the DBAgent of the active and standby databases periodically monitors the running status of the local database and the latest GTID in the current binlog log. At the same time, the active and standby databases share the running status of the active and standby databases.
  • the DBAgent of the primary database periodically connects to the primary database service port through a MYSQL protocol, queries and obtains the current location of the local database (current gtid_current_pos), and records and updates it, and sends it to the DBAgent of the standby database through the heartbeat message interface for recording.
  • the DBAgent of the standby database periodically connects to the standby database service port through a MYSQL protocol, queries and acquires the current location of the local database (current gtid_current_pos), and records and updates it, and sends it to the DBAgent of the primary database through the heartbeat message interface for recording.
  • Step S21 Receive a current location of the peer database sent by the peer database, and compare the current location of the local database with the current location of the peer database.
  • the local database is the primary database and the peer database is the standby database:
  • the DBAgent of the primary database receives the heartbeat message sent by the DBAgent of the standby database, records the current gtid_current_pos location of the standby database, compares the current gtid_current_pos location of the primary database with the current gtid_current_pos location of the standby database.
  • the DBAgent of the standby database receives the heartbeat message sent by the DBAgent of the primary database, records the current gtid_current_pos location of the primary database, compares the current gtid_current_pos location of the primary database with the current gtid_current_pos location of the standby database.
  • step S40 when the difference between the current location of the local database and the current location of the peer database is greater than a preset threshold, an alarm operation is performed.
  • the threshold may be preset by the system, or may be modified by the user according to actual usage
  • corresponding measures are taken. Such as alarms.
  • the present disclosure provides a master-slave database switching method, which can monitor the master-slave data synchronization gap in real time, and indirectly understand the system's write transaction load change; remove the third-party management component and directly circumvent the The problem of the entire system being unavailable due to the failure of the three-party management component; simplifying the processing logic and simplifying the installation and deployment, the DBAgent can be bundled with the DB software, and the deployment of each database node is simple and convenient; the data of the database of the master and backup machines is quickly identified and the data is consistent. It can automatically perform active/standby switchover and build a new master-slave replication relationship. When the data is inconsistent, it can automatically generate differentiated SQL scripts, save time for manual intervention, and ensure data consistency. When the DBAgent itself is abnormal, the database service is normal, avoid unnecessary mis-switching.
  • step S30 includes:
  • Step S31 If the local database is a standby database and the peer database is a primary database, an alarm operation is performed, and the connection detection operation is continued.
  • the peer database is the primary database
  • DBAgent connection database service of the standby database fails more than the specified number of times (for example, 10 times, the number of times may be preset by the system, or may be performed by the user according to actual usage. Modify), determine the current primary database exception, continue to perform the connection detection operation.
  • the specified number of times for example, 10 times, the number of times may be preset by the system, or may be performed by the user according to actual usage. Modify
  • Step S32 if the local database is a primary database, and the peer database is a standby database, parse the log file of the local database, obtain a final location of the local database, and execute according to the last location. Active/standby switching operation.
  • the local database is the primary database and the peer database is the standby database:
  • the DBAgent connection database service fails to exceed the specified number of times (for example, 10 times, the number can be preset by the system, or can be modified by the user according to the actual usage), determine the current primary database exception, and parse the log file of the primary database. The last location of the primary database is obtained, and the active/standby switchover operation is performed according to the last location.
  • the specified number of times for example, 10 times, the number can be preset by the system, or can be modified by the user according to the actual usage
  • the DBAgent of the primary database sends a handover request message to the DBAgent of the standby database, where the message includes the last_pos location of the primary database;
  • the DBAgent of the primary database continues to periodically check whether the database service is normal until the database service is restored;
  • the DBAgent of the primary database initiates an active/standby switchover process according to the last_pos location of the primary database in the handover request, where:
  • the last location of the primary database is not empty, compare the last location of the primary database with the current location of the standby database. If the current location of the standby database is equal to the last location of the primary database, an automatic switching operation is performed, if the current location of the standby database is smaller than the primary The final location of the database, whether to perform automatic switching operations according to business requirements;
  • the present disclosure provides a method for switching between primary and secondary databases, which When the local database is abnormal, different processing methods performed by the active and standby databases can better realize the real-time monitoring and master the synchronization gap between the primary and backup databases, simplify the operation, ensure data consistency, and avoid mis-switching.
  • FIG. 5 is a schematic flowchart of steps of performing an active/standby switchover operation according to an embodiment of the present disclosure.
  • step S32 includes:
  • Step S321 if the last location of the primary database is not empty, compare the last location of the primary database with the current location of the standby database, wherein if the current location of the standby database is equal to the last location of the primary database, Then, an automatic switching operation is performed. If the current location of the standby database is smaller than the last location of the primary database, whether to perform the automatic switching operation is determined according to service requirements.
  • the last_pos location of the primary database is not empty, compare whether the last GTID location last_pos of the primary database is consistent with the current gtid_current_pos of the standby database, and if the standby database gtid_current_pos is equal to the primary database last_pos, perform an automatic switching operation, if the standby database gtid_current_pos Less than the primary database last_pos indicates that the data of the primary database has not been completely synchronized to the primary database.
  • the data of the primary and secondary databases are inconsistent. At this time, it is possible to decide whether to automatically switch and record related log information according to service requirements.
  • Step S322 if the last location of the primary database is empty, comparing the current location of the primary database with the current location of the standby database, wherein if the current location of the standby database is greater than or equal to the current location of the primary database And executing the automatic switching operation; otherwise, determining whether to perform the automatic switching operation according to a service requirement.
  • the location of the primary database last_pos is null, compare whether the current GTID location gtid_current_pos of the primary database and the current gtid_current_pos of the standby database are consistent. If the standby database is greater than or equal to the location of the primary database gtid_current_pos, then the automatic switching operation is performed. If the data of the primary database is not completely synchronized to the standby database, the data of the primary and secondary databases are inconsistent. In this case, you can decide whether to automatically switch and record related log information according to service requirements.
  • the present disclosure provides a method for switching between the active and standby databases, which implements the corresponding active/standby switching operations according to different situations, thereby realizing real-time monitoring and grasping the synchronization gap between the active and standby databases, simplifying operations, and ensuring data. Consistency while avoiding false switching.
  • FIG. 6 is a schematic flowchart of steps of performing an automatic switching operation according to an embodiment of the present disclosure.
  • step S32 includes:
  • step S323 the standby database is switched to be the primary database, and after the standby database service is restored, the active/standby replication relationship is restored.
  • the DBAgent switches the standby database as the primary database, and sets the primary primary database as the standby database. After the standby database service is restored, the DBAgent restores the replication relationship between the primary and backup databases. When the data of the primary and secondary databases is inconsistent, the original primary database needs to be parsed.
  • the binlog log file after parsing all the GTID SQL statements from the gtid_current_pos location of the standby database, generates a forward SQL statement, and restores the original primary and backup database data after the original database is replenished.
  • the present disclosure provides a method for switching between the active and standby databases, which implements the automatic switching operation, better realizes the real-time monitoring and grasps the synchronization gap between the active and standby databases, simplifies the operation, ensures data consistency, and avoids errors. Switch.
  • FIG. 7 is a schematic flowchart of a step of acquiring a final location of the local database in the specific embodiment of the present disclosure.
  • step S32 includes:
  • Step S324 obtaining a current log file list of the local database.
  • the DBAgent obtains the last GTID location last_pos of the database by calling the mysqlbinlog tool.
  • the index file of the current binlog file is obtained through the index file in the binary log folder of the database binlog.
  • Step S325 starting scanning from the last log file in the current log file list, and obtaining the last location of the local database from the last event of the last log file.
  • scanning from the last binlog log file scanning to find the last gtid event (GTID_LOG_EVENT) of the binlog file, and obtaining the last gtid is last_pos.
  • Step S326 if the last event cannot be found from the last log file, scan the last log file of the last log file until the last event is found.
  • the previous binlog file is scanned and looped until the last gtid is found.
  • the method for finding the location of the specified gtid_current_pos by the binlog log file is the same as the method for finding the last_pos.
  • the binlog log position change of the primary and secondary databases is performed before and after the MariaDB active/standby switch operation.
  • the PosA is the position of the gtid_current_pos in the normal heartbeat message reported by the original primary database; the Last_pos is the maximum GTID location in the binq binary log that the last write transaction of the original primary database actually writes; PosB is the original standby database to copy the binlog log from the primary database.
  • the Last_pos and PosB are identical, the master and backup data are identical, and the master/slave switchover can be performed automatically.
  • the PosB is greater than or equal to Whether the primary and backup data is in PosA If the original host switchover is performed, the relationship between the location of the Last_pos and the PosB needs to be re-confirmed.
  • Last_pos is greater than the PosB, the primary and backup machines have different binlogs. Otherwise, the data of the active and standby devices are consistent.
  • the Last_pos is unknown (the physical machine is abnormal when the power is disconnected), and the PosB is smaller than the PosA, the data of the original standby machine is obviously behind the original host, and the data of the active and standby machines are inconsistent.
  • the present disclosure provides a method for switching between the active and standby databases, which better realizes real-time monitoring and grasps the synchronization gap between the primary and secondary databases, simplifies operations, ensures data consistency, and avoids false handover.
  • the present disclosure also provides corresponding device embodiments.
  • the first embodiment of the present disclosure provides a master/slave database switching apparatus, including:
  • connection module 100 is configured to perform a connection native database service operation.
  • the disclosure mainly ensures that the database master/slave data synchronization process can be monitored by using the MariaDB and binlog logs to ensure fast and automatic switching when the database is abnormal.
  • the database agent software DBAgent (or other software capable of implementing the same function) can be deployed on the device where the active and standby databases are located.
  • the DBAgent is a database agent software, which can be used to monitor the running of the database service and parse the binlog.
  • the log file can be used to switch the control process in the event of a failure; in the operation of the MariaDB database, the related actions are recorded in the binlog log file, in order to read the synchronous data from the database, the MariaDB database execution process
  • the binlog log file is generated, the binlog position is given, that is, the current log position (long integer value).
  • the DBAgent of the active and standby databases periodically monitors the running status of the local database and the latest GTID in the current binlog log. At the same time, the active and standby databases share the running status of the active and standby databases.
  • the DBAgent of the primary database is periodically connected to the main user through the MYSQL protocol.
  • the database service port queries and obtains the current location of the local database (current gtid_current_pos), and records and updates it, and sends it to the DBAgent of the standby database through the heartbeat message interface for recording.
  • the DBAgent of the standby database periodically connects to the standby database service port through a MYSQL protocol, queries and acquires the current location of the local database (current gtid_current_pos), and records and updates it, and sends it to the DBAgent of the primary database through the heartbeat message interface for recording.
  • the location module 200 is configured to receive a current location of the peer database sent by the peer database.
  • the local database is the primary database and the peer database is the standby database:
  • the DBAgent of the primary database receives the heartbeat message sent by the DBAgent of the standby database, and records the current gtid_current_pos location of the standby database.
  • the DBAgent of the standby database receives the heartbeat message sent by the DBAgent of the primary database, and records the current gtid_current_pos location of the primary database.
  • the execution module 300 is configured to determine that the local database is abnormal if the number of failures of the connection local database service operation exceeds a preset number of times, and perform an alarm operation or in the local database and the peer database Performing an active/standby switchover operation, or performing an alarm operation or the local database and the peer database if the number of failures of the current location of the peer database sent by the peer database exceeds a preset number of times Perform an active/standby switchover between the two.
  • the peer database is the primary database
  • the DBAgent connection database service of the standby database fails more than the specified number of times (for example, 10 times, the number of times may be preset by the system, or may be modified by the user according to actual usage conditions)
  • the current primary database is determined to be abnormal, and the connection detection operation is continued.
  • the database DBAgent connection database service fails more than the specified number of times (such as 10 The number of times can be preset by the system, or can be modified by the user according to the actual usage. It determines that the current primary database is abnormal, parses the log file of the primary database, obtains the last location of the primary database, and performs the primary and secondary operations according to the last location. Switching operations, in the specific implementation, you can take the following approach:
  • the DBAgent of the primary database sends a handover request message to the DBAgent of the standby database, where the message includes the last_pos location of the primary database;
  • the DBAgent of the primary database continues to periodically check whether the database service is normal until the database service is restored;
  • the DBAgent of the primary database initiates an active/standby switchover process according to the last_pos location of the primary database in the handover request, where:
  • the last location of the primary database is not empty, compare the last location of the primary database with the current location of the standby database. If the current location of the standby database is equal to the last location of the primary database, an automatic switching operation is performed, if the current location of the standby database is smaller than the primary The final location of the database, whether to perform automatic switching operations according to business requirements;
  • the above automatic switching operation may be: switching the standby database as the primary database, and restoring the active/standby replication relationship after the standby database service is restored.
  • the host database is the primary database and the peer database is the standby database:
  • the alarm is generated.
  • the host database is the standby database and the peer database is the primary database:
  • the primary database is not received.
  • the heartbeat message sent by the DBAgent is connected to the primary database service port through the MYSQL protocol to obtain the current location of the primary database gtid_current_pos. If the successful execution indicates that the DBAgent process of the primary database is abnormal, the database service is normal, and there is no need to initiate an active/standby switchover. If the log fails, the primary database DBAgent process and the database service are abnormal. You can initiate an active/standby switchover request.
  • the transaction When the main database executes a DDL statement or a transaction containing updated SQL, the transaction is assigned a globally unique order GTID number. Before the transaction commits, the binary binlog log file is simultaneously written to the slave database, and the binlog log of the master database is read from the database. The information is synchronized with the data, and the corresponding SQL statement is executed in response to the synchronization with the primary database data;
  • the database agent software DBAgent regularly monitors the running status of the local database service, and accesses the local database through the MYSQL protocol to monitor whether the database is running normally.
  • the local gtid_current_pos location of the local database is sent to send the heartbeat message to the peer DBAgent, and the DBAgent receives the heartbeat of the peer.
  • the location of the gtid_current_pos of the peer database is parsed, and the location of the gtid_current_pos of the local database and the peer database is compared, and the data synchronization of the master-slave database is judged according to the difference.
  • the difference between the master-slave database gtid_current_pos exceeds the set range, real-time alarms and other related measures are performed. .
  • the database agent software DBAgent actively connects to the peer database service through the MYSQL protocol, determines whether the peer database service is normal, and obtains the location of the gtid_current_pos of the peer database. If the connection fails, it determines that the peer database is abnormal, and decides whether to initiate the active/standby switch according to the master-slave role of the database.
  • the present disclosure provides a master-slave database switching device, which can monitor the master-slave data synchronization gap in real time, and indirectly understand the system write transaction load change; remove the third-party management component and directly circumvent the The entire system is unavailable due to the failure of the three-party management component; simplifying the processing logic and simplifying the installation and deployment, DBAgent can be bundled with the DB software, and the deployment of each database node is simple and convenient; quickly identify the data of the main and backup machines.
  • the library data is inconsistent. When the data is consistent, the master/slave switchover can be performed automatically, and a new master-slave replication relationship is constructed. When the data is inconsistent, it can automatically generate differentiated SQL scripts, save time for manual intervention, and ensure data consistency.
  • the database service is normal, avoid unnecessary mis-switching.
  • a second embodiment of the present disclosure provides a master/slave database switching apparatus, where:
  • connection module 100 is further configured to perform a connection to the local database service operation, and periodically acquire the current location of the local database.
  • the DBAgent of the active and standby databases periodically monitors the running status of the local database and the latest GTID in the current binlog log. At the same time, the active and standby databases share the running status of the active and standby databases.
  • the DBAgent of the primary database periodically connects to the primary database service port through a MYSQL protocol, queries and obtains the current location of the local database (current gtid_current_pos), and records and updates it, and sends it to the DBAgent of the standby database through the heartbeat message interface for recording.
  • the DBAgent of the standby database periodically connects to the standby database service port through a MYSQL protocol, queries and acquires the current location of the local database (current gtid_current_pos), and records and updates it, and sends it to the DBAgent of the primary database through the heartbeat message interface for recording.
  • the location module 200 is further configured to receive a current location of the peer database sent by the peer database, and compare the current location of the local database with the current location of the peer database.
  • the local database is the primary database and the peer database is the standby database:
  • the DBAgent of the primary database receives the heartbeat message sent by the DBAgent of the standby database, and records Record the current gtid_current_pos location of the database, compare the current gtid_current_pos location of the primary database with the current gtid_current_pos location of the standby database.
  • the DBAgent of the standby database receives the heartbeat message sent by the DBAgent of the primary database, records the current gtid_current_pos location of the primary database, compares the current gtid_current_pos location of the primary database with the current gtid_current_pos location of the standby database.
  • the device also includes:
  • the alarm module 400 is configured to perform an alarm operation when a difference between a current location of the local database and a current location of the peer database is greater than a preset threshold.
  • the threshold may be preset by the system, or may be modified by the user according to actual usage
  • corresponding measures are taken. Such as alarms.
  • the present disclosure provides a master-slave database switching device, which can monitor the master-slave data synchronization gap in real time, and indirectly understand the system write transaction load change; remove the third-party management component and directly circumvent the The problem of the entire system being unavailable due to the failure of the three-party management component; simplifying the processing logic and simplifying the installation and deployment, the DBAgent can be bundled with the DB software, and the deployment of each database node is simple and convenient; the data of the database of the master and backup machines is quickly identified and the data is consistent. It can automatically perform active/standby switchover and build a new master-slave replication relationship. When the data is inconsistent, it can automatically generate differentiated SQL scripts, save time for manual intervention, and ensure data consistency. When the DBAgent itself is abnormal, the database service is normal, avoid unnecessary mis-switching.
  • the execution module 300 is further configured to perform an alarm operation if the local database is a standby database and the peer database is a primary database. And continuing to perform the connection detection operation; if the local database is the primary database, and the peer database is the standby database, parsing the log of the local database File, obtain the last location of the native database, and perform an active/standby switch operation according to the last location.
  • the peer database is the primary database
  • the DBAgent connection database service of the standby database fails more than the specified number of times (for example, 10 times, the number of times may be preset by the system, or may be modified by the user according to actual usage conditions)
  • the current primary database is determined to be abnormal, and the connection detection operation is continued.
  • the DBAgent connection database service fails to exceed the specified number of times (for example, 10 times, the number can be preset by the system, or can be modified by the user according to the actual usage), determine the current primary database exception, and parse the log file of the primary database. The last location of the primary database is obtained, and the active/standby switchover operation is performed according to the last location.
  • the specified number of times for example, 10 times, the number can be preset by the system, or can be modified by the user according to the actual usage
  • the DBAgent of the primary database sends a handover request message to the DBAgent of the standby database, where the message includes the last_pos location of the primary database;
  • the DBAgent of the primary database continues to periodically check whether the database service is normal until the database service is restored;
  • the DBAgent of the primary database initiates an active/standby switchover process according to the last_pos location of the primary database in the handover request, where:
  • the last location of the primary database is not empty, compare the last location of the primary database with the current location of the standby database. If the current location of the standby database is equal to the last location of the primary database, an automatic switching operation is performed, if the current location of the standby database is smaller than the primary The final location of the database, whether to perform automatic switching operations according to business requirements;
  • the present disclosure provides a master-slave database switching device, which achieves real-time monitoring and mastering the synchronization gap between the master and standby databases by performing different processing modes of the active and standby databases when the local database is abnormal. Simplify operations to ensure data consistency while avoiding false switching.
  • the execution module 300 is further configured to compare the last location of the primary database with the The current location of the standby database, wherein if the current location of the standby database is equal to the last location of the primary database, an automatic switching operation is performed, and if the current location of the standby database is smaller than the last location of the primary database, the decision is made according to service requirements. Whether the automatic switching operation is performed; if the last location of the primary database is empty, comparing the current location of the primary database with the current location of the standby database, wherein if the current location of the standby database is greater than or equal to the If the current location of the primary database is performed, the automatic switching operation is performed; otherwise, whether the automatic switching operation is performed according to the service requirement is determined.
  • the last_pos location of the primary database is not empty, compare whether the last GTID location last_pos of the primary database is consistent with the current gtid_current_pos of the standby database, and if the standby database gtid_current_pos is equal to the primary database last_pos, perform an automatic switching operation, if the standby database gtid_current_pos Less than the primary database last_pos indicates that the data of the primary database has not been completely synchronized to the primary database.
  • the data of the primary and secondary databases are inconsistent. At this time, it is possible to decide whether to automatically switch and record related log information according to service requirements.
  • the current GTID location gtid_current_pos of the primary database is compared with the current gtid_current_pos of the standby database. If the standby database is greater than or equal to the location of the primary database gtid_current_pos, an automatic switching operation is performed; otherwise, the primary database is indicated.
  • the data has not been fully synchronized to the standby database, the primary and secondary database data Inconsistent. At this time, you can decide whether you need to automatically switch and record related log information according to business requirements.
  • the present disclosure provides an active/standby database switching device, which implements a corresponding active/standby switching operation according to different situations, thereby realizing real-time monitoring to grasp the synchronization gap between the primary and backup databases, simplifying operations, and ensuring data. Consistency while avoiding false switching.
  • the execution module 300 is further configured to switch the standby database as a primary database, and resume the active/standby replication after the standby database service is restored. relationship.
  • the DBAgent switches the standby database as the primary database, and sets the primary primary database as the standby database. After the standby database service is restored, the DBAgent restores the replication relationship between the primary and backup databases. When the data of the primary and secondary databases is inconsistent, the original primary database needs to be parsed.
  • the binlog log file after parsing all the GTID SQL statements from the gtid_current_pos location of the standby database, generates a forward SQL statement, and restores the original primary and backup database data after the original database is replenished.
  • the present disclosure provides an active/standby database switching device, which implements an automatic switching operation, better realizes real-time monitoring, grasps the synchronization gap between the primary and backup databases, simplifies operations, ensures data consistency, and avoids errors. Switch.
  • the execution module 300 is further configured to obtain a current log file list of the local database; and the last log in the current log file list.
  • the file begins scanning and obtains the last location of the native database from the last event of the last log file; if the last event cannot be found from the last log file, the last log is scanned The last log file of the file until the last event is found.
  • the DBAgent obtains the last GTID location last_pos of the database by calling the mysqlbinlog tool.
  • the index file of the current binlog file is obtained through the index file in the binary log folder of the database binlog.
  • the last binlog file is scanned and looped until the last gtid is found.
  • the method for finding the location of the specified gtid_current_pos by the binlog log file is the same as the method for finding the last_pos.
  • the binlog log position change of the primary and secondary databases is performed before and after the MariaDB active/standby switch operation.
  • the PosA is the position of the gtid_current_pos in the normal heartbeat message reported by the original primary database; the Last_pos is the maximum GTID location in the binq binary log that the last write transaction of the original primary database actually writes; PosB is the original standby database to copy the binlog log from the primary database.
  • the Last_pos and PosB are identical, the master and backup data are identical, and the master/slave switchover can be performed automatically.
  • the PosB is greater than or equal to If the primary and backup data are in the same state, the primary and backup devices need to be re-confirmed. The relationship between the location of the Last_pos and the PosB is re-confirmed.
  • Last_pos is greater than the PosB
  • the primary and backup machines have differentiated binlogs.
  • the master/slave data is consistent.
  • the Last_pos is unknown (the physical machine is abnormal when the power is disconnected)
  • the PosB is smaller than the PosA
  • the original standby data is obviously behind the original host, and the data of the active and standby machines are inconsistent.
  • the present disclosure provides a master-slave database switching device, which better realizes real-time monitoring and grasps the synchronization gap between the master and standby databases, simplifies operations, ensures data consistency, and avoids false switching.
  • each of the above modules can be implemented by software or hardware.
  • the latter can be implemented in the following manner, but is not limited thereto: the above modules are all located in the same processor; or, the above modules are respectively located in different processors in any combination.
  • Embodiments of the present disclosure also provide a storage medium including a stored program, wherein the program described above executes the method of any of the above.
  • the foregoing storage medium may include, but is not limited to, a USB flash drive, a Read-Only Memory (ROM), and a Random Access Memory (RAM).
  • ROM Read-Only Memory
  • RAM Random Access Memory
  • Embodiments of the present disclosure also provide a processor for running a program, wherein the program executes the steps of any of the above methods when executed.
  • modules or steps of the present disclosure described above can be implemented by a general-purpose computing device that can be centralized on a single computing device or distributed across a network of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein.
  • the steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof are fabricated as a single integrated circuit module. As such, the disclosure is not limited to any specific combination of hardware and software.
  • the method and apparatus for switching between the active and standby databases provided by the embodiments of the present disclosure have the following beneficial effects: the problem of poor data accuracy, complicated operation, and low stability when the primary and secondary databases are switched in the prior art.
  • Real-time monitoring is achieved to grasp the synchronization gap between the primary and backup databases, simplify operations, ensure data consistency, and avoid mis-switching.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种主备数据库切换方法和装置,其方法包括:执行连接本机数据库服务操作(S10);接收对端数据库发送的对端数据库当前位置(S20);若连接数据库服务操作的失败次数超过预设的次数,则判定本机数据库异常,并执行告警操作或在本机数据库和对端数据库之间进行主备切换操作,或者,若接收对端数据库发送的对端数据库当前位置的失败次数超过预设的次数,则执行告警操作或在本机数据库和对端数据库之间进行主备切换操作(S30)。解决了主备数据库进行切换时,数据精度差,操作复杂,稳定性低的问题。实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。

Description

主备数据库切换方法和装置 技术领域
本公开涉及数据库技术领域,尤其涉及一种主备数据库切换方法和装置。
背景技术
在现今数据库应用中,数据库并发度高、数据增长速度快是当今数据库业务两大特点。在短时间内,可能存在大量数据新增或修改。随着数据数量级递增,从字节、千字节、兆字节到现在的万兆字节,结合MariaDB/MySQL数据库良好横向扩展特性,基于MariaDB/MySQL数据库的分布式数据库得到广泛的应用。
同时为了提高数据库容灾性,各数据库提供商均提出了相应策略,其中MariaDB/MySQL数据库使用的是主从复制策略,其核心理念是主数据库对外提供服务,当主库有更新的时候,主库会把更新操作的SQL写入二进制日志(Bin log),并维护一个二进制日志文件的索引,以便于日志文件轮回(Rotate)。从数据库读取主数据库运行所生成binlog日志,并执行binlog日志中相关动作,从而保证主从数据库数据一致。当数据库主机出现宕机,需要在较短时间内恢复应用,就需要使用从机来充当主数据库(即主备切换),如何判断从机数据库和主机数据库数据是否一致,如何在较短时间内将主从机数据库数据恢复成一致,成为一个技术难题。
主从复制是备机复制主机binlog日志,由于存在主机写日志时延和网络通讯时延以及备机回放日志时延等因素,因此必然存在主备日志不同步现象。当前业界识别主备数据是否一致的通常做法大致有两种:一种业务应用层用户自行在主数据库新增监控表,定期更新该表中的时间戳,管理模块监控主备机监控表中时间戳差值判断主备数据同步差距情况。另外一种是在数据库主备机分别增加DBAgent代理模块,定时查询数据库的当前binlog位置,上报给管理模块,由管理模块判断主备机数据同步差距情 况。
以上两种方式存在如下弊端:
1、均引入了第三方的管理模块,增加了交互复杂度,同时当第三方管理模块出现故障情况下,整个监控***瘫痪,发生故障时无法实现切换。
2、由于引入第三方管理模块并且是定时上报,因此存在周期内的时间差问题,众所周知数据库应用每秒钟的tps都是成千上万的,而这种定时上报机制至少也是秒级,因此大大降低了判断精度,无法保证在切换的时候主备机是强一致的,对数据安全要求极高的保险类、证券类、银行类等行业是无法接受这种方案的。
3、上述方式二当数据库服务正常,而监控数据库运行情况的主DBAgent代理模块异常,也可能会引起异常的数据库的主备切换。
公开内容
本公开的主要目的在于提出一种主备数据库切换方法和装置,旨在解决现有技术中主备数据库进行切换时,数据精度差,操作复杂,稳定性低的问题。
为实现上述目的,本公开提出一种主备数据库切换方法,包括:
执行连接本机数据库服务操作;
接收对端数据库发送的对端数据库当前位置;
若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作,或者,若所述接收对端数据库发送的对端数据库当前位置的失败次数超过预设的次数,则执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作。
优选地,所述执行连接本机数据库服务操作的步骤包括:
执行连接数据库服务操作,定时获取本机数据库当前位置;
所述接收对端数据库发送的对端数据库当前位置的步骤包括:
接收对端数据库发送的对端数据库当前位置,将所述本机数据库当前位置与所述对端数据库当前位置进行比对;
所述接收对端数据库发送的对端数据库当前位置,将所述本机数据库当前位置与所述对端数据库当前位置进行比对的步骤之后,还包括:
当所述本机数据库当前位置与所述对端数据库当前位置的差值大于预设的阈值时,执行告警操作。
优选地,所述若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作的步骤包括:
若所述本机数据库为备数据库,所述对端数据库为主数据库,则执行告警操作,并继续执行连接检测操作;
若所述本机数据库为主数据库,所述对端数据库为备数据库,则解析所述本机数据库的日志文件,获取所述本机数据库的最后位置,并根据所述最后位置执行主备切换操作。
优选地,所述执行主备切换操作的步骤包括:
若所述主数据库的最后位置不为空,则对比所述主数据库的最后位置与所述备数据库当前位置,其中,若所述备数据库当前位置等于所述主数据库的最后位置,则执行自动切换操作,若所述备数据库当前位置小于所述主数据库的最后位置,则根据业务要求决策是否执行所述自动切换操作;
若所述主数据库的最后位置为空,则对比所述主数据库的当前位置与所述备数据库当前位置,其中,若所述备数据库当前位置大于或等于所述主数据库的当前位置,则执行所述自动切换操作,否则,则根据业务要求决策是否执行所述自动切换操作。
优选地,所述自动切换操作包括:
切换所述备数据库为主数据库,并在所述备数据库服务恢复后,重新恢复主备复制关系。
优选地,所述获取所述本机数据库的最后位置的步骤包括:
获取所述本机数据库的当前日志文件列表;
从所述当前日志文件列表中的最后一个日志文件开始扫描,并从所述最后一个日志文件的最后一个事件中获取所述本机数据库的最后位置;
若无法从所述最后一个日志文件找到所述最后一个事件,则扫描所述最后一个日志文件的上一个日志文件,直到找到所述最后一个事件。
为实现上述目的,本公开还提出一种主备数据库切换装置,包括:
连接模块,设置为执行连接本机数据库服务操作;
位置模块,设置为接收对端数据库发送的对端数据库当前位置;
执行模块,设置为若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作,或者,若所述接收对端数据库发送的对端数据库当前位置的失败次数超过预设的次数,则执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作。
优选地,所述连接模块,还设置为执行连接本机数据库服务操作,定时获取本机数据库当前位置;
所述位置模块,还设置为接收对端数据库发送的对端数据库当前位置,将所述本机数据库当前位置与所述对端数据库当前位置进行比对;
所述装置还包括:
告警模块,设置为当所述本机数据库当前位置与所述对端数据库当前位置的差值大于预设的阈值时,执行告警操作。
优选地,所述执行模块,还设置为若所述本机数据库为备数据库,所述对端数据库为主数据库,则执行告警操作,并继续执行连接检测操作; 若所述本机数据库为主数据库,所述对端数据库为备数据库,则解析所述本机数据库的日志文件,获取所述本机数据库的最后位置,并根据所述最后位置执行主备切换操作。
优选地,所述执行模块,还设置为若所述主数据库的最后位置不为空,则对比所述主数据库的最后位置与所述备数据库当前位置,其中,若所述备数据库当前位置等于所述主数据库的最后位置,则执行自动切换操作,若所述备数据库当前位置小于所述主数据库的最后位置,则根据业务要求决策是否执行所述自动切换操作;若所述主数据库的最后位置为空,则对比所述主数据库的当前位置与所述备数据库当前位置,其中,若所述备数据库当前位置大于或等于所述主数据库的当前位置,则执行所述自动切换操作,否则,则根据业务要求决策是否执行所述自动切换操作。
优选地,所述执行模块,还设置为若所述用户为非指定用户,则执行指定定向信息绑卡操作。
优选地,所述执行模块,还设置为获取所述本机数据库的当前日志文件列表;从所述当前日志文件列表中的最后一个日志文件开始扫描,并从所述最后一个日志文件的最后一个事件中获取所述本机数据库的最后位置;若无法从所述最后一个日志文件找到所述最后一个事件,则扫描所述最后一个日志文件的上一个日志文件,直到找到所述最后一个事件。
根据本公开的又一个实施例,还提供了一种存储介质,所述存储介质包括存储的程序,其中,所述程序运行时执行上述任一项所述的方法。
根据本公开的又一个实施例,还提供了一种处理器,所述处理器用于运行程序,其中,所述程序运行时执行上述任一项所述的方法。
本公开还提供了一种主备数据库切换方法和装置,通过执行连接本机数据库服务操作;接收对端数据库发送的对端数据库当前位置;若连接数据库服务操作的失败次数超过预设的次数,则判定本机数据库异常,并执行告警操作或在本机数据库和对端数据库之间进行主备切换操作,或者, 若接收对端数据库发送的对端数据库当前位置的失败次数超过预设的次数,则执行告警操作或在本机数据库和对端数据库之间进行主备切换操作,解决了现有技术中主备数据库进行切换时,数据精度差,操作复杂,稳定性低的问题。实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
附图说明
图1是本公开主备数据库切换方法第一实施例的流程示意图;
图2是本公开实施例中主备数据库复制监控管理架构图;
图3是本公开主备数据库切换方法第二实施例的流程示意图;
图4是本公开实施例中若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作的步骤的一种流程示意图;
图5是本公开实施例中执行主备切换操作的步骤的一种流程示意图;
图6是本公开实施例中自动切换操作的步骤的一种流程示意图;
图7是本公开实施例中获取所述本机数据库的最后位置的步骤的一种流程示意图;
图8是本公开实施例中主备切换前后binlog日志位置变化关系图;
图9是本公开主备数据库切换装置第一实施例的功能模块示意图;
图10是本公开主备数据库切换装置第二实施例的功能模块示意图。
本公开目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅仅用以解释本公开,并不用于 限定本公开。
如图1所示,本公开第一实施例提出一种主备数据库切换方法,包括:
步骤S10,执行连接本机数据库服务操作。
本公开方法的执行主体可以为一种数据库管理平台或数据库服务器,具体应用于主数据库或备数据库将在下述说明书进行具体说明,当然也不限定于其他能够实现主备数据库切换的设备或服务器。
其中,本公开主要通过利用MariaDB和binlog日志保障数据库主备数据同步过程可监控,保证数据库异常时快速自动切换。
其中,在具体实现时,可以在主备数据库所在设备上部署数据库代理软件DBAgent(或其他能够实现相同功能的软件),DBAgent是一种数据库代理软件,可以用于监控数据库服务运行情况,解析binlog日志文件,在出现故障时可以用于切换控制进程;其中,在MariaDB数据库运行过程中,会将执行过的相关动作记录到binlog日志文件中,以备从数据库读取同步数据,MariaDB数据库执行过程中,产生binlog日志文件时,会相应给出binlog位置,即当前日志位置(长整形值)。
可选地,主备数据库的DBAgent定时监控本机数据库运行情况及当前binlog日志中的最新GTID,同时,主备数据库之间互相共享主备机数据库运行情况。
当本机数据库为主数据库,对端数据库为备数据库时:
主数据库的DBAgent定时通过MYSQL协议,用特定的用户连接主数据库服务端口,查询并获取本机数据库当前位置(当前gtid_current_pos),并进行记录更新,通过心跳消息接口发送给备数据库的DBAgent进行记录。
当本机数据库为备数据库,对端数据库为主数据库时:
备数据库的DBAgent定时通过MYSQL协议,用特定的用户连接备 数据库服务端口,查询并获取本机数据库当前位置(当前gtid_current_pos),并进行记录更新,通过心跳消息接口发送给主数据库的DBAgent进行记录。
步骤S20,接收对端数据库发送的对端数据库当前位置。
可选地,当本机数据库为主数据库,对端数据库为备数据库时:
主数据库的DBAgent接收备数据库的DBAgent发送的心跳消息,记录备数据库当前gtid_current_pos位置。
当本机数据库为备数据库,对端数据库为主数据库时:
备数据库的DBAgent接收主数据库的DBAgent发送的心跳消息,记录主数据库当前gtid_current_pos位置。
步骤S30,若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作,或者,若所述接收对端数据库发送的对端数据库当前位置的失败次数超过预设的次数,则执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作。
可选地,当本机数据库为备数据库,对端数据库为主数据库时:
若备数据库的DBAgent连接数据库服务失败超出规定次数(比如10次,该次数可以是***预先设置的,也可以由用户根据实际使用情况进行修改),判定当前主数据库异常,继续执行连接检测操作。
当本机数据库为主数据库,对端数据库为备数据库时:
若备数据库的DBAgent连接数据库服务失败超出规定次数(比如10次,该次数可以是***预先设置的,也可以由用户根据实际使用情况进行修改),判定当前主数据库异常,解析主数据库的日志文件,获取主数据库的最后位置,并根据最后位置执行主备切换操作,在具体实现时,可以采取如下方式:
1、通过解析数据库binlog日志文件的方式,获取主数据库最后的 gtid_current_pos位置,记录为last_pos位置;
2、主数据库的DBAgent发送切换请求消息至备数据库的DBAgent,该消息中包括主数据库的last_pos位置;
3、主数据库的DBAgent继续定时检测数据库服务是否正常,直至数据库服务恢复;
4、主数据库的DBAgent根据切换请求中的主数据库的last_pos位置,发起主备切换流程,其中:
若主数据库的最后位置不为空,则对比主数据库的最后位置与备数据库当前位置,其中,若备数据库当前位置等于主数据库的最后位置,则执行自动切换操作,若备数据库当前位置小于主数据库的最后位置,则根据业务要求决策是否执行自动切换操作;
若主数据库的最后位置为空,则对比主数据库的当前位置与备数据库当前位置,其中,若备数据库当前位置大于或等于主数据库的当前位置,则执行自动切换操作,否则,则根据业务要求决策是否执行自动切换操作。
上述自动切换操作可以为:切换备数据库为主数据库,并在备数据库服务恢复后,重新恢复主备复制关系。
或者,当主机数据库为主数据库,对端数据库为备数据库时:
如果主数据库的DBAgent超出规定次数未接收到主数据库的DBAgent发送的心跳消息,则执行告警告警操作。
当主机数据库为备数据库,对端数据库为主数据库时:
如果备数据库的DBAgent超出规定次数未接收到主数据库的DBAgent发送的心跳消息,则通过MYSQL协议连接主数据库服务端口获取主数据库当前位置gtid_current_pos,如果获取成功说明主数据库的DBAgent进程运行异常,数据库服务正常,无须发起主备切换,只需告警并记录相关日志,如果获取失败,说明主数据库DBAgent进程和数据库服务均异常,此时可以发起主备切换请求。
另外,如图2所示,为主从复制监控管理平台架构图,具体描述如下:
主数据库执行DDL语句或包含更新SQL的事务时,为该事务分配一个全局唯一的顺序的GTID编号,事务提交前写入二进制binlog日志文件同时同步给从数据库,从数据库读取主数据库的binlog日志信息同步数据,回复执行对应的SQL语句,从而达到与主数据库数据同步;
数据库代理软件DBAgent定时监测本机数据库服务运行情况,通过MYSQL协议连接访问本机数据库监控数据库运行是否正常,同时获取本机数据库当前gtid_current_pos位置定时发送心跳消息给对端DBAgent,DBAgent接收到对端的心跳消息后解析记录对端数据库的gtid_current_pos位置,比对本机数据库与对端数据库的gtid_current_pos位置,根据差值判断主从数据库的数据同步情况,当主从数据库gtid_current_pos差距超过设定范围进行实时告警等相关措施。
可选地,数据库代理软件DBAgent一定时间内接收不到对端DBAgent发送的心跳消息后,主动通过MYSQL协议连接对端数据库服务,判断对端数据库服务是否正常,同时获取对端数据库的gtid_current_pos位置,如果连接失败则判定对端数据库异常,根据数据库的主从角色决策是否发起主备切换。
通过上述方案,本公开提供了一种主备数据库切换方法,该方法能够实时监控掌握主从数据同步差距情况,间接了解***的写事务负载变化情况;去掉了第三方管理组件,直接规避了第三方管理组件故障引起的整个***不可用问题;简化处理逻辑的同时也简化了安装部署,DBAgent可以与DB进行软件捆绑,各数据库节点部署统一简便;快速识别主备机数据库数据不一致,数据一致时能自动进行主备切换,并构建新主从复制关系。数据不一致时能自动化生成差异化SQL脚本,为人工干预节约时间,并高度保证数据一致性;在DBAgent本身进程异常数据库服务正常情况下,避免不必要的误切换。
如图3所示,本公开第二实施例提出一种主备数据库切换方法,包括:
步骤S11,执行连接本机数据库服务操作,定时获取本机数据库当前位置。
可选地,主备数据库的DBAgent定时监控本机数据库运行情况及当前binlog日志中的最新GTID,同时,主备数据库之间互相共享主备机数据库运行情况。
当本机数据库为主数据库,对端数据库为备数据库时:
主数据库的DBAgent定时通过MYSQL协议,用特定的用户连接主数据库服务端口,查询并获取本机数据库当前位置(当前gtid_current_pos),并进行记录更新,通过心跳消息接口发送给备数据库的DBAgent进行记录。
当本机数据库为备数据库,对端数据库为主数据库时:
备数据库的DBAgent定时通过MYSQL协议,用特定的用户连接备数据库服务端口,查询并获取本机数据库当前位置(当前gtid_current_pos),并进行记录更新,通过心跳消息接口发送给主数据库的DBAgent进行记录。
步骤S21,接收对端数据库发送的对端数据库当前位置,将所述本机数据库当前位置与所述对端数据库当前位置进行比对。
可选地,当本机数据库为主数据库,对端数据库为备数据库时:
主数据库的DBAgent接收备数据库的DBAgent发送的心跳消息,记录备数据库当前gtid_current_pos位置,比对主数据库的当前gtid_current_pos位置和备数据库的当前gtid_current_pos位置。
当本机数据库为备数据库,对端数据库为主数据库时:
备数据库的DBAgent接收主数据库的DBAgent发送的心跳消息,记录主数据库当前gtid_current_pos位置,比对主数据库的当前gtid_current_pos位置和备数据库的当前gtid_current_pos位置。
步骤S40,当所述本机数据库当前位置与所述对端数据库当前位置的差值大于预设的阈值时,执行告警操作。
可选地,当主数据库的当前gtid_current_pos位置和备数据库的当前gtid_current_pos位置差值大于配置的阈值时(该阈值可以是***预先设置的,也可以由用户根据实际使用情况进行修改),采取相应措施,如告警等。
通过上述方案,本公开提供了一种主备数据库切换方法,该方法能够实时监控掌握主从数据同步差距情况,间接了解***的写事务负载变化情况;去掉了第三方管理组件,直接规避了第三方管理组件故障引起的整个***不可用问题;简化处理逻辑的同时也简化了安装部署,DBAgent可以与DB进行软件捆绑,各数据库节点部署统一简便;快速识别主备机数据库数据不一致,数据一致时能自动进行主备切换,并构建新主从复制关系。数据不一致时能自动化生成差异化SQL脚本,为人工干预节约时间,并高度保证数据一致性;在DBAgent本身进程异常数据库服务正常情况下,避免不必要的误切换。
可选地,为了更好地保证贮备数据库切换时数据的一致性,参照图4,为本公开具体实施方式中,若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作的步骤的一种流程示意图。
作为一种实施方式,上述步骤S30包括:
步骤S31,若所述本机数据库为备数据库,所述对端数据库为主数据库,则执行告警操作,并继续执行连接检测操作。
可选地,当本机数据库为备数据库,对端数据库为主数据库时:
若备数据库的DBAgent连接数据库服务失败超出规定次数(比如10次,该次数可以是***预先设置的,也可以由用户根据实际使用情况进行 修改),判定当前主数据库异常,继续执行连接检测操作。
步骤S32,若所述本机数据库为主数据库,所述对端数据库为备数据库,则解析所述本机数据库的日志文件,获取所述本机数据库的最后位置,并根据所述最后位置执行主备切换操作。
可选地,当本机数据库为主数据库,对端数据库为备数据库时:
若备数据库的DBAgent连接数据库服务失败超出规定次数(比如10次,该次数可以是***预先设置的,也可以由用户根据实际使用情况进行修改),判定当前主数据库异常,解析主数据库的日志文件,获取主数据库的最后位置,并根据最后位置执行主备切换操作,在具体实现时,可以采取如下方式:
1、通过解析数据库binlog日志文件的方式,获取主数据库最后的gtid_current_pos位置,记录为last_pos位置;
2、主数据库的DBAgent发送切换请求消息至备数据库的DBAgent,该消息中包括主数据库的last_pos位置;
3、主数据库的DBAgent继续定时检测数据库服务是否正常,直至数据库服务恢复;
4、主数据库的DBAgent根据切换请求中的主数据库的last_pos位置,发起主备切换流程,其中:
若主数据库的最后位置不为空,则对比主数据库的最后位置与备数据库当前位置,其中,若备数据库当前位置等于主数据库的最后位置,则执行自动切换操作,若备数据库当前位置小于主数据库的最后位置,则根据业务要求决策是否执行自动切换操作;
若主数据库的最后位置为空,则对比主数据库的当前位置与备数据库当前位置,其中,若备数据库当前位置大于或等于主数据库的当前位置,则执行自动切换操作,否则,则根据业务要求决策是否执行自动切换操作。
通过上述方案,本公开提供了一种主备数据库切换方法,该方法通过 在本机数据库异常时,主备数据库执行的不同处理方式,更好地实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
可选地,为了更好地保证贮备数据库切换时数据的一致性,参照图5,为本公开具体实施方式中,执行主备切换操作的步骤的一种流程示意图。
作为一种实施方式,上述步骤S32包括:
步骤S321,若所述主数据库的最后位置不为空,则对比所述主数据库的最后位置与所述备数据库当前位置,其中,若所述备数据库当前位置等于所述主数据库的最后位置,则执行自动切换操作,若所述备数据库当前位置小于所述主数据库的最后位置,则根据业务要求决策是否执行所述自动切换操作。
可选地,如果主数据库的last_pos位置不为空,则比较主数据库最后的GTID位置last_pos和备数据库的当前gtid_current_pos是否一致,如果备数据库gtid_current_pos等于主数据库last_pos则进行自动切换操作,如果备数据库gtid_current_pos小于主数据库last_pos说明主数据库的数据尚未完全同步至主数据库,主备数据库数据不一致,此时,可以根据业务要求决策是否需要自动切换并记录相关的日志信息。
其中,根据MariaDB的复制原理,不可能出现备数据库gtid_current_pos大于主数据库last_pos的情况。
步骤S322,若所述主数据库的最后位置为空,则对比所述主数据库的当前位置与所述备数据库当前位置,其中,若所述备数据库当前位置大于或等于所述主数据库的当前位置,则执行所述自动切换操作,否则,则根据业务要求决策是否执行所述自动切换操作。
可选地,如果主数据库last_pos位置为空,则比较主数据库当前的GTID位置gtid_current_pos和备数据库的当前gtid_current_pos是否一致,如果备数据库大于等于主数据库gtid_current_pos位置,则进行自动切换操 作,否则,则说明主数据库的数据尚未完全同步至备数据库,主备数据库数据不一致,此时,可以根据业务要求决策是否需要自动切换并记录相关的日志信息。
通过上述方案,本公开提供了一种主备数据库切换方法,该方法通过根据不同情况执行相应的主备切换操作,更好地实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
可选地,为了更好地保证贮备数据库切换时数据的一致性,参照图6,为本公开具体实施方式中,执行自动切换操作的步骤的一种流程示意图。
作为一种实施方式,上述步骤S32包括:
步骤S323,切换所述备数据库为主数据库,并在所述备数据库服务恢复后,重新恢复主备复制关系。
可选地,DBAgent切换备数据库为主数据库,将主原数据库设置为备数据库,待备数据库服务恢复后,DBAgent重新恢复主备数据库复制关系;当主备数据库数据不一致时,则需要解析原主数据库的binlog日志文件,从备数据库的gtid_current_pos位置处解析之后的所有GTID涉及的SQL语句,生成正向SQL语句后,在原备数据库补充执行完毕后使得原主备数据库数据恢复一致。
通过上述方案,本公开提供了一种主备数据库切换方法,该方法通过执行自动切换操作,更好地实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
可选地,为了更好地保证贮备数据库切换时数据的一致性,参照图7,为本公开具体实施方式中,获取所述本机数据库的最后位置的步骤的一种流程示意图。
作为一种实施方式,上述步骤S32包括:
步骤S324,获取所述本机数据库的当前日志文件列表。
可选地,当主机数据库服务异常时,DBAgent通过调用mysqlbinlog工具获取数据库最后的GTID位置last_pos。
其中,通过数据库binlog二进制日志文件夹下的index文件获取当前binlog文件列表。
步骤S325,从所述当前日志文件列表中的最后一个日志文件开始扫描,并从所述最后一个日志文件的最后一个事件中获取所述本机数据库的最后位置。
可选地,从最后一个binlog日志文件开始扫描,扫描找到这个binlog文件的最后一个gtid事件(GTID_LOG_EVENT),获取最后一个gtid即为last_pos。
步骤S326,若无法从所述最后一个日志文件找到所述最后一个事件,则扫描所述最后一个日志文件的上一个日志文件,直到找到所述最后一个事件。
可选地,如果当前binlog没有找到gtid事件,即没有事务提交记录在这个binlog文件中,那么就扫描上一个binlog文件,循环往复,直到找到最后一个gtid。
可选地,通过binlog日志文件查找指定gtid_current_pos位置的方法同上述查找last_pos方法。
另外,如图8所示,为MariaDB主备切换操作前后,主备数据库相应的binlog日志位置变换情况。
其中,PosA是原主数据库最后一次上报的正常心跳消息中的gtid_current_pos位置;Last_pos是原主数据库最后一个写事务实际写入binlog二进制日志中的最大GTID位置;PosB为原备机数据库从主数据库复制binlog日志的最后一个事务对应的GTID位置;当Last_pos、PosB两者重合相等时,主备数据完全一致,可自动进行主备切换;当Last_pos未知(掉电断网等物理机异常情况),PosB大于等于PosA时主备数据是否 一致未知;此时进行主备切换后,待原主机恢复异常后需要重新确认Last_pos位置与PosB的关系,如果Last_pos大于PosB,则主备机之间有差异化binlog,否则主备机数据一致;当Last_pos未知(掉电断网等物理机异常情况),PosB小于PosA时,原备机数据明显落后原主机,主备机数据不一致。
通过上述方案,本公开提供了一种主备数据库切换方法,更好地实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
基于上述方法实施例的实现,本公开还提供相应的装置实施例。
如图9所示,本公开第一实施例提出一种主备数据库切换装置,包括:
连接模块100,设置为执行连接本机数据库服务操作。
其中,本公开主要通过利用MariaDB和binlog日志保障数据库主备数据同步过程可监控,保证数据库异常时快速自动切换。
其中,在具体实现时,可以在主备数据库所在设备上部署数据库代理软件DBAgent(或其他能够实现相同功能的软件),DBAgent是一种数据库代理软件,可以用于监控数据库服务运行情况,解析binlog日志文件,在出现故障时可以用于切换控制进程;其中,在MariaDB数据库运行过程中,会将执行过的相关动作记录到binlog日志文件中,以备从数据库读取同步数据,MariaDB数据库执行过程中,产生binlog日志文件时,会相应给出binlog位置,即当前日志位置(长整形值)。
可选地,主备数据库的DBAgent定时监控本机数据库运行情况及当前binlog日志中的最新GTID,同时,主备数据库之间互相共享主备机数据库运行情况。
当本机数据库为主数据库,对端数据库为备数据库时:
主数据库的DBAgent定时通过MYSQL协议,用特定的用户连接主 数据库服务端口,查询并获取本机数据库当前位置(当前gtid_current_pos),并进行记录更新,通过心跳消息接口发送给备数据库的DBAgent进行记录。
当本机数据库为备数据库,对端数据库为主数据库时:
备数据库的DBAgent定时通过MYSQL协议,用特定的用户连接备数据库服务端口,查询并获取本机数据库当前位置(当前gtid_current_pos),并进行记录更新,通过心跳消息接口发送给主数据库的DBAgent进行记录。
位置模块200,设置为接收对端数据库发送的对端数据库当前位置。
可选地,当本机数据库为主数据库,对端数据库为备数据库时:
主数据库的DBAgent接收备数据库的DBAgent发送的心跳消息,记录备数据库当前gtid_current_pos位置。
当本机数据库为备数据库,对端数据库为主数据库时:
备数据库的DBAgent接收主数据库的DBAgent发送的心跳消息,记录主数据库当前gtid_current_pos位置。
执行模块300,设置为若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作,或者,若所述接收对端数据库发送的对端数据库当前位置的失败次数超过预设的次数,则执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作。
可选地,当本机数据库为备数据库,对端数据库为主数据库时:
若备数据库的DBAgent连接数据库服务失败超出规定次数(比如10次,该次数可以是***预先设置的,也可以由用户根据实际使用情况进行修改),判定当前主数据库异常,继续执行连接检测操作。
当本机数据库为主数据库,对端数据库为备数据库时:
若备数据库的DBAgent连接数据库服务失败超出规定次数(比如10 次,该次数可以是***预先设置的,也可以由用户根据实际使用情况进行修改),判定当前主数据库异常,解析主数据库的日志文件,获取主数据库的最后位置,并根据最后位置执行主备切换操作,在具体实现时,可以采取如下方式:
1、通过解析数据库binlog日志文件的方式,获取主数据库最后的gtid_current_pos位置,记录为last_pos位置;
2、主数据库的DBAgent发送切换请求消息至备数据库的DBAgent,该消息中包括主数据库的last_pos位置;
3、主数据库的DBAgent继续定时检测数据库服务是否正常,直至数据库服务恢复;
4、主数据库的DBAgent根据切换请求中的主数据库的last_pos位置,发起主备切换流程,其中:
若主数据库的最后位置不为空,则对比主数据库的最后位置与备数据库当前位置,其中,若备数据库当前位置等于主数据库的最后位置,则执行自动切换操作,若备数据库当前位置小于主数据库的最后位置,则根据业务要求决策是否执行自动切换操作;
若主数据库的最后位置为空,则对比主数据库的当前位置与备数据库当前位置,其中,若备数据库当前位置大于或等于主数据库的当前位置,则执行自动切换操作,否则,则根据业务要求决策是否执行自动切换操作。
上述自动切换操作可以为:切换备数据库为主数据库,并在备数据库服务恢复后,重新恢复主备复制关系。
或者,当主机数据库为主数据库,对端数据库为备数据库时:
如果主数据库的DBAgent超出规定次数未接收到主数据库的DBAgent发送的心跳消息,则执行告警告警操作。
当主机数据库为备数据库,对端数据库为主数据库时:
如果备数据库的DBAgent超出规定次数未接收到主数据库的 DBAgent发送的心跳消息,则通过MYSQL协议连接主数据库服务端口获取主数据库当前位置gtid_current_pos,如果获取成功说明主数据库的DBAgent进程运行异常,数据库服务正常,无须发起主备切换,只需告警并记录相关日志,如果获取失败,说明主数据库DBAgent进程和数据库服务均异常,此时可以发起主备切换请求。
另外,如图2所示,为主从复制监控管理平台架构图,具体描述如下:
主数据库执行DDL语句或包含更新SQL的事务时,为该事务分配一个全局唯一的顺序的GTID编号,事务提交前写入二进制binlog日志文件同时同步给从数据库,从数据库读取主数据库的binlog日志信息同步数据,回复执行对应的SQL语句,从而达到与主数据库数据同步;
数据库代理软件DBAgent定时监测本机数据库服务运行情况,通过MYSQL协议连接访问本机数据库监控数据库运行是否正常,同时获取本机数据库当前gtid_current_pos位置定时发送心跳消息给对端DBAgent,DBAgent接收到对端的心跳消息后解析记录对端数据库的gtid_current_pos位置,比对本机数据库与对端数据库的gtid_current_pos位置,根据差值判断主从数据库的数据同步情况,当主从数据库gtid_current_pos差距超过设定范围进行实时告警等相关措施。
可选地,数据库代理软件DBAgent一定时间内接收不到对端DBAgent发送的心跳消息后,主动通过MYSQL协议连接对端数据库服务,判断对端数据库服务是否正常,同时获取对端数据库的gtid_current_pos位置,如果连接失败则判定对端数据库异常,根据数据库的主从角色决策是否发起主备切换。
通过上述方案,本公开提供了一种主备数据库切换装置,该方法能够实时监控掌握主从数据同步差距情况,间接了解***的写事务负载变化情况;去掉了第三方管理组件,直接规避了第三方管理组件故障引起的整个***不可用问题;简化处理逻辑的同时也简化了安装部署,DBAgent可以与DB进行软件捆绑,各数据库节点部署统一简便;快速识别主备机数据 库数据不一致,数据一致时能自动进行主备切换,并构建新主从复制关系。数据不一致时能自动化生成差异化SQL脚本,为人工干预节约时间,并高度保证数据一致性;在DBAgent本身进程异常数据库服务正常情况下,避免不必要的误切换。
如图10所示,本公开第二实施例提出一种主备数据库切换装置,其中:
上述连接模块100,还设置为执行连接本机数据库服务操作,定时获取本机数据库当前位置。
可选地,主备数据库的DBAgent定时监控本机数据库运行情况及当前binlog日志中的最新GTID,同时,主备数据库之间互相共享主备机数据库运行情况。
当本机数据库为主数据库,对端数据库为备数据库时:
主数据库的DBAgent定时通过MYSQL协议,用特定的用户连接主数据库服务端口,查询并获取本机数据库当前位置(当前gtid_current_pos),并进行记录更新,通过心跳消息接口发送给备数据库的DBAgent进行记录。
当本机数据库为备数据库,对端数据库为主数据库时:
备数据库的DBAgent定时通过MYSQL协议,用特定的用户连接备数据库服务端口,查询并获取本机数据库当前位置(当前gtid_current_pos),并进行记录更新,通过心跳消息接口发送给主数据库的DBAgent进行记录。
上述位置模块200,还设置为接收对端数据库发送的对端数据库当前位置,将所述本机数据库当前位置与所述对端数据库当前位置进行比对。
可选地,当本机数据库为主数据库,对端数据库为备数据库时:
主数据库的DBAgent接收备数据库的DBAgent发送的心跳消息,记 录备数据库当前gtid_current_pos位置,比对主数据库的当前gtid_current_pos位置和备数据库的当前gtid_current_pos位置。
当本机数据库为备数据库,对端数据库为主数据库时:
备数据库的DBAgent接收主数据库的DBAgent发送的心跳消息,记录主数据库当前gtid_current_pos位置,比对主数据库的当前gtid_current_pos位置和备数据库的当前gtid_current_pos位置。
该装置还包括:
告警模块400,设置为当所述本机数据库当前位置与所述对端数据库当前位置的差值大于预设的阈值时,执行告警操作。
可选地,当主数据库的当前gtid_current_pos位置和备数据库的当前gtid_current_pos位置差值大于配置的阈值时(该阈值可以是***预先设置的,也可以由用户根据实际使用情况进行修改),采取相应措施,如告警等。
通过上述方案,本公开提供了一种主备数据库切换装置,该方法能够实时监控掌握主从数据同步差距情况,间接了解***的写事务负载变化情况;去掉了第三方管理组件,直接规避了第三方管理组件故障引起的整个***不可用问题;简化处理逻辑的同时也简化了安装部署,DBAgent可以与DB进行软件捆绑,各数据库节点部署统一简便;快速识别主备机数据库数据不一致,数据一致时能自动进行主备切换,并构建新主从复制关系。数据不一致时能自动化生成差异化SQL脚本,为人工干预节约时间,并高度保证数据一致性;在DBAgent本身进程异常数据库服务正常情况下,避免不必要的误切换。
可选地,为了更好地保证贮备数据库切换时数据的一致性,上述执行模块300,还设置为若所述本机数据库为备数据库,所述对端数据库为主数据库,则执行告警操作,并继续执行连接检测操作;若所述本机数据库为主数据库,所述对端数据库为备数据库,则解析所述本机数据库的日志 文件,获取所述本机数据库的最后位置,并根据所述最后位置执行主备切换操作。
可选地,当本机数据库为备数据库,对端数据库为主数据库时:
若备数据库的DBAgent连接数据库服务失败超出规定次数(比如10次,该次数可以是***预先设置的,也可以由用户根据实际使用情况进行修改),判定当前主数据库异常,继续执行连接检测操作。
然后,当本机数据库为主数据库,对端数据库为备数据库时:
若备数据库的DBAgent连接数据库服务失败超出规定次数(比如10次,该次数可以是***预先设置的,也可以由用户根据实际使用情况进行修改),判定当前主数据库异常,解析主数据库的日志文件,获取主数据库的最后位置,并根据最后位置执行主备切换操作,在具体实现时,可以采取如下方式:
1、通过解析数据库binlog日志文件的方式,获取主数据库最后的gtid_current_pos位置,记录为last_pos位置;
2、主数据库的DBAgent发送切换请求消息至备数据库的DBAgent,该消息中包括主数据库的last_pos位置;
3、主数据库的DBAgent继续定时检测数据库服务是否正常,直至数据库服务恢复;
4、主数据库的DBAgent根据切换请求中的主数据库的last_pos位置,发起主备切换流程,其中:
若主数据库的最后位置不为空,则对比主数据库的最后位置与备数据库当前位置,其中,若备数据库当前位置等于主数据库的最后位置,则执行自动切换操作,若备数据库当前位置小于主数据库的最后位置,则根据业务要求决策是否执行自动切换操作;
若主数据库的最后位置为空,则对比主数据库的当前位置与备数据库当前位置,其中,若备数据库当前位置大于或等于主数据库的当前位置, 则执行自动切换操作,否则,则根据业务要求决策是否执行自动切换操作。
通过上述方案,本公开提供了一种主备数据库切换装置,该方法通过在本机数据库异常时,主备数据库执行的不同处理方式,更好地实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
可选地,为了更好地保证贮备数据库切换时数据的一致性,上述执行模块300,还设置为若所述主数据库的最后位置不为空,则对比所述主数据库的最后位置与所述备数据库当前位置,其中,若所述备数据库当前位置等于所述主数据库的最后位置,则执行自动切换操作,若所述备数据库当前位置小于所述主数据库的最后位置,则根据业务要求决策是否执行所述自动切换操作;若所述主数据库的最后位置为空,则对比所述主数据库的当前位置与所述备数据库当前位置,其中,若所述备数据库当前位置大于或等于所述主数据库的当前位置,则执行所述自动切换操作,否则,则根据业务要求决策是否执行所述自动切换操作。
可选地,如果主数据库的last_pos位置不为空,则比较主数据库最后的GTID位置last_pos和备数据库的当前gtid_current_pos是否一致,如果备数据库gtid_current_pos等于主数据库last_pos则进行自动切换操作,如果备数据库gtid_current_pos小于主数据库last_pos说明主数据库的数据尚未完全同步至主数据库,主备数据库数据不一致,此时,可以根据业务要求决策是否需要自动切换并记录相关的日志信息。
其中,根据MariaDB的复制原理,不可能出现备数据库gtid_current_pos大于主数据库last_pos的情况。
然后,如果主数据库last_pos位置为空,则比较主数据库当前的GTID位置gtid_current_pos和备数据库的当前gtid_current_pos是否一致,如果备数据库大于等于主数据库gtid_current_pos位置,则进行自动切换操作,否则,则说明主数据库的数据尚未完全同步至备数据库,主备数据库数据 不一致,此时,可以根据业务要求决策是否需要自动切换并记录相关的日志信息。
通过上述方案,本公开提供了一种主备数据库切换装置,该方法通过根据不同情况执行相应的主备切换操作,更好地实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
可选地,为了更好地保证贮备数据库切换时数据的一致性,上述执行模块300,还设置为切换所述备数据库为主数据库,并在所述备数据库服务恢复后,重新恢复主备复制关系。
可选地,DBAgent切换备数据库为主数据库,将主原数据库设置为备数据库,待备数据库服务恢复后,DBAgent重新恢复主备数据库复制关系;当主备数据库数据不一致时,则需要解析原主数据库的binlog日志文件,从备数据库的gtid_current_pos位置处解析之后的所有GTID涉及的SQL语句,生成正向SQL语句后,在原备数据库补充执行完毕后使得原主备数据库数据恢复一致。
通过上述方案,本公开提供了一种主备数据库切换装置,该方法通过执行自动切换操作,更好地实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
可选地,为了更好地保证贮备数据库切换时数据的一致性,上述执行模块300,还设置为获取所述本机数据库的当前日志文件列表;从所述当前日志文件列表中的最后一个日志文件开始扫描,并从所述最后一个日志文件的最后一个事件中获取所述本机数据库的最后位置;若无法从所述最后一个日志文件找到所述最后一个事件,则扫描所述最后一个日志文件的上一个日志文件,直到找到所述最后一个事件。
可选地,当主机数据库服务异常时,DBAgent通过调用mysqlbinlog工具获取数据库最后的GTID位置last_pos。
其中,通过数据库binlog二进制日志文件夹下的index文件获取当前binlog文件列表。
然后,从最后一个binlog日志文件开始扫描,扫描找到这个binlog文件的最后一个gtid事件(GTID_LOG_EVENT),获取最后一个gtid即为last_pos。
然后,如果当前binlog没有找到gtid事件,即没有事务提交记录在这个binlog文件中,那么就扫描上一个binlog文件,循环往复,直到找到最后一个gtid。
可选地,通过binlog日志文件查找指定gtid_current_pos位置的方法同上述查找last_pos方法。
另外,如图8所示,为MariaDB主备切换操作前后,主备数据库相应的binlog日志位置变换情况。
其中,PosA是原主数据库最后一次上报的正常心跳消息中的gtid_current_pos位置;Last_pos是原主数据库最后一个写事务实际写入binlog二进制日志中的最大GTID位置;PosB为原备机数据库从主数据库复制binlog日志的最后一个事务对应的GTID位置;当Last_pos、PosB两者重合相等时,主备数据完全一致,可自动进行主备切换;当Last_pos未知(掉电断网等物理机异常情况),PosB大于等于PosA时主备数据是否一致未知;此时进行主备切换后,待原主机恢复异常后需要重新确认Last_pos位置与PosB的关系,如果Last_pos大于PosB,则主备机之间有差异化binlog,否则主备机数据一致;当Last_pos未知(掉电断网等物理机异常情况),PosB小于PosA时,原备机数据明显落后原主机,主备机数据不一致。
通过上述方案,本公开提供了一种主备数据库切换装置,更好地实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。
需要说明的是,上述各个模块是可以通过软件或硬件来实现的,对于 后者,可以通过以下方式实现,但不限于此:上述模块均位于同一处理器中;或者,上述各个模块以任意组合的形式分别位于不同的处理器中。
本公开的实施例还提供了一种存储介质,该存储介质包括存储的程序,其中,上述程序运行时执行上述任一项所述的方法。
可选地,在本实施例中,上述存储介质可以包括但不限于:U盘、只读存储器(Read-Only Memory,简称为ROM)、随机存取存储器(Random Access Memory,简称为RAM)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
本公开的实施例还提供了一种处理器,该处理器用于运行程序,其中,该程序运行时执行上述任一项方法中的步骤。
显然,本领域的技术人员应该明白,上述的本公开的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本公开不限制于任何特定的硬件和软件结合。
以上仅为本公开的优选实施例,并非因此限制本公开的专利范围,凡是利用本公开说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本公开的专利保护范围内。
工业实用性
如上所述,本公开实施例提供的一种主备数据库切换方法和装置具有以下有益效果:解决了现有技术中主备数据库进行切换时,数据精度差,操作复杂,稳定性低的问题。实现了实时监控掌握主备数据库同步差距情况,简化操作,保证数据一致性,同时避免误切换。

Claims (12)

  1. 一种主备数据库切换方法,所述方法包括:
    执行连接本机数据库服务操作;
    接收对端数据库发送的对端数据库当前位置;
    若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作,或者,若所述接收对端数据库发送的对端数据库当前位置的失败次数超过预设的次数,则执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作。
  2. 根据权利要求1所述的方法,其中,所述执行连接本机数据库服务操作的步骤包括:
    执行连接本机数据库服务操作,定时获取本机数据库当前位置;
    所述接收对端数据库发送的对端数据库当前位置的步骤包括:
    接收对端数据库发送的对端数据库当前位置,将所述本机数据库当前位置与所述对端数据库当前位置进行比对;
    所述接收对端数据库发送的对端数据库当前位置,将所述本机数据库当前位置与所述对端数据库当前位置进行比对的步骤之后,还包括:
    当所述本机数据库当前位置与所述对端数据库当前位置的差值大于预设的阈值时,执行告警操作。
  3. 根据权利要求2所述的方法,其中,所述若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作的步骤包括:
    若所述本机数据库为备数据库,所述对端数据库为主数据库,则 执行告警操作,并继续执行连接检测操作;
    若所述本机数据库为主数据库,所述对端数据库为备数据库,则解析所述本机数据库的日志文件,获取所述本机数据库的最后位置,并根据所述最后位置执行主备切换操作。
  4. 根据权利要求3所述的方法,其中,所述执行主备切换操作的步骤包括:
    若所述主数据库的最后位置不为空,则对比所述主数据库的最后位置与所述备数据库当前位置,其中,若所述备数据库当前位置等于所述主数据库的最后位置,则执行自动切换操作,若所述备数据库当前位置小于所述主数据库的最后位置,则根据业务要求决策是否执行所述自动切换操作;
    若所述主数据库的最后位置为空,则对比所述主数据库的当前位置与所述备数据库当前位置,其中,若所述备数据库当前位置大于或等于所述主数据库的当前位置,则执行所述自动切换操作,否则,则根据业务要求决策是否执行所述自动切换操作。
  5. 根据权利要求4所述的方法,其中,所述自动切换操作包括:
    切换所述备数据库为主数据库,并在所述备数据库服务恢复后,重新恢复主备复制关系。
  6. 根据权利要求3所述的方法,其中,所述获取所述本机数据库的最后位置的步骤包括:
    获取所述本机数据库的当前日志文件列表;
    从所述当前日志文件列表中的最后一个日志文件开始扫描,并从所述最后一个日志文件的最后一个事件中获取所述本机数据库的最后 位置;
    若无法从所述最后一个日志文件找到所述最后一个事件,则扫描所述最后一个日志文件的上一个日志文件,直到找到所述最后一个事件。
  7. 一种主备数据库切换装置,所述装置包括:
    连接模块,设置为执行连接本机数据库服务操作;
    位置模块,设置为接收对端数据库发送的对端数据库当前位置;
    执行模块,设置为若所述连接本机数据库服务操作的失败次数超过预设的次数,则判定所述本机数据库异常,并执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作,或者,若所述接收对端数据库发送的对端数据库当前位置的失败次数超过预设的次数,则执行告警操作或在所述本机数据库和所述对端数据库之间进行主备切换操作。
  8. 根据权利要求7所述的装置,其中,
    所述连接模块,还设置为执行连接本机数据库服务操作,定时获取本机数据库当前位置;
    所述位置模块,还设置为接收对端数据库发送的对端数据库当前位置,将所述本机数据库当前位置与所述对端数据库当前位置进行比对;
    所述装置还包括:
    告警模块,设置为当所述本机数据库当前位置与所述对端数据库当前位置的差值大于预设的阈值时,执行告警操作。
  9. 根据权利要求8所述的装置,其中,
    所述执行模块,还设置为若所述本机数据库为备数据库,所述对端数据库为主数据库,则执行告警操作,并继续执行连接检测操作;若所述本机数据库为主数据库,所述对端数据库为备数据库,则解析所述本机数据库的日志文件,获取所述本机数据库的最后位置,并根据所述最后位置执行主备切换操作。
  10. 根据权利要求9所述的装置,其中,
    所述执行模块,还设置为若所述主数据库的最后位置不为空,则对比所述主数据库的最后位置与所述备数据库当前位置,其中,若所述备数据库当前位置等于所述主数据库的最后位置,则执行自动切换操作,若所述备数据库当前位置小于所述主数据库的最后位置,则根据业务要求决策是否执行所述自动切换操作;若所述主数据库的最后位置为空,则对比所述主数据库的当前位置与所述备数据库当前位置,其中,若所述备数据库当前位置大于或等于所述主数据库的当前位置,则执行所述自动切换操作,否则,则根据业务要求决策是否执行所述自动切换操作。
  11. 根据权利要求10所述的装置,其中,
    所述执行模块,还设置为若所述用户为非指定用户,则执行指定定向信息绑卡操作。
  12. 根据权利要求9所述的装置,其中,
    所述执行模块,还设置为获取所述本机数据库的当前日志文件列表;从所述当前日志文件列表中的最后一个日志文件开始扫描,并从所述最后一个日志文件的最后一个事件中获取所述本机数据库的最后位置;若无法从所述最后一个日志文件找到所述最后一个事件,则扫描所述最后一个日志文件的上一个日志文件,直到找到所述最后一个 事件。
PCT/CN2017/080418 2016-04-13 2017-04-13 主备数据库切换方法和装置 WO2017177941A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610230656.1A CN107291787B (zh) 2016-04-13 2016-04-13 主备数据库切换方法和装置
CN201610230656.1 2016-04-13

Publications (1)

Publication Number Publication Date
WO2017177941A1 true WO2017177941A1 (zh) 2017-10-19

Family

ID=60042763

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/080418 WO2017177941A1 (zh) 2016-04-13 2017-04-13 主备数据库切换方法和装置

Country Status (2)

Country Link
CN (1) CN107291787B (zh)
WO (1) WO2017177941A1 (zh)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111258823A (zh) * 2020-01-17 2020-06-09 青梧桐有限责任公司 一种主从服务器的切换方法及***
CN112069018A (zh) * 2020-07-21 2020-12-11 上海瀚银信息技术有限公司 一种数据库高可用方法及***
CN112307054A (zh) * 2020-11-18 2021-02-02 太原理工大学 一种双活数据库主备服务器读写方法
CN113032477A (zh) * 2019-12-24 2021-06-25 中移在线服务有限公司 基于gtid的长距离数据同步方法、装置及计算设备
CN113792340A (zh) * 2021-09-09 2021-12-14 烽火通信科技股份有限公司 一种用于数据库逻辑日志审计的方法及装置
CN113836160A (zh) * 2021-09-28 2021-12-24 上海市大数据股份有限公司 一种基于主从同步的数据流状态监控告警***
CN115914418A (zh) * 2023-03-09 2023-04-04 北京全路通信信号研究设计院集团有限公司 一种铁路接口网关设备
CN115941451A (zh) * 2023-02-21 2023-04-07 浙江国利信安科技有限公司 工业控制网络中冗余切换的方法、设备和存储介质
CN115934428A (zh) * 2023-01-10 2023-04-07 湖南三湘银行股份有限公司 一种mysql数据库的主灾备切换方法、装置及电子设备

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108833164B (zh) * 2018-06-14 2021-10-08 杭州网易再顾科技有限公司 服务器控制方法、装置、电子设备及存储介质
CN108897641B (zh) * 2018-06-21 2020-08-18 武汉达梦数据库有限公司 一种数据库主备环境下的日志分析服务实时同步***
CN109308242B (zh) * 2018-09-06 2021-11-19 上海达梦数据库有限公司 一种动态监控方法、装置、设备和存储介质
CN109144790A (zh) * 2018-09-30 2019-01-04 广州鼎甲计算机科技有限公司 MySQL数据库的合成备份方法和装置
CN109857802A (zh) * 2018-12-12 2019-06-07 深圳前海微众银行股份有限公司 日志数据同步方法、装置、设备及计算机可读存储介质
CN109885344A (zh) * 2019-02-27 2019-06-14 四川航空股份有限公司 操作***切换方法及装置
CN110166524B (zh) * 2019-04-12 2023-04-07 未鲲(上海)科技服务有限公司 数据中心的切换方法、装置、设备及存储介质
CN111209140B (zh) * 2019-12-30 2023-01-06 苏州浪潮智能科技有限公司 一种主备双节点数据库崩溃的恢复方法及装置
CN111460029B (zh) * 2020-03-11 2024-04-19 中移动信息技术有限公司 数据同步方法和装置
CN111653052B (zh) * 2020-04-26 2022-06-21 北京三快在线科技有限公司 收银***及收银机切换方法
CN113761075A (zh) * 2020-09-01 2021-12-07 北京沃东天骏信息技术有限公司 切换数据库的方法、装置、设备和计算机可读介质
CN113830134B (zh) * 2021-08-25 2024-03-15 通号城市轨道交通技术有限公司 车载atp双系切换方法和车载atp的逻辑单元

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102194009A (zh) * 2011-06-09 2011-09-21 北京新媒传信科技有限公司 一种数据库托管方法和一种数据库托管平台***
CN102693171A (zh) * 2011-08-05 2012-09-26 新奥特(北京)视频技术有限公司 一种信息录入***的恢复方法及***
CN102955851A (zh) * 2012-10-30 2013-03-06 北京奇虎科技有限公司 一种数据库的切换方法和装置

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6778818B1 (en) * 2001-06-18 2004-08-17 At&T Corp. Enhanced 911 system for providing witness identification in a wireless communication system
CN100493017C (zh) * 2003-06-25 2009-05-27 华为技术有限公司 一种主备设备自动切换的方法
CN102013997B (zh) * 2010-11-22 2014-06-11 中兴通讯股份有限公司 电信网管***中的双机数据备份方法和***

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102194009A (zh) * 2011-06-09 2011-09-21 北京新媒传信科技有限公司 一种数据库托管方法和一种数据库托管平台***
CN102693171A (zh) * 2011-08-05 2012-09-26 新奥特(北京)视频技术有限公司 一种信息录入***的恢复方法及***
CN102955851A (zh) * 2012-10-30 2013-03-06 北京奇虎科技有限公司 一种数据库的切换方法和装置

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113032477B (zh) * 2019-12-24 2023-07-21 中移在线服务有限公司 基于gtid的长距离数据同步方法、装置及计算设备
CN113032477A (zh) * 2019-12-24 2021-06-25 中移在线服务有限公司 基于gtid的长距离数据同步方法、装置及计算设备
CN111258823A (zh) * 2020-01-17 2020-06-09 青梧桐有限责任公司 一种主从服务器的切换方法及***
CN112069018A (zh) * 2020-07-21 2020-12-11 上海瀚银信息技术有限公司 一种数据库高可用方法及***
CN112069018B (zh) * 2020-07-21 2024-05-31 上海瀚银信息技术有限公司 一种数据库高可用方法及***
CN112307054B (zh) * 2020-11-18 2023-02-28 太原理工大学 一种双活数据库主备服务器读写方法
CN112307054A (zh) * 2020-11-18 2021-02-02 太原理工大学 一种双活数据库主备服务器读写方法
CN113792340A (zh) * 2021-09-09 2021-12-14 烽火通信科技股份有限公司 一种用于数据库逻辑日志审计的方法及装置
CN113792340B (zh) * 2021-09-09 2023-09-05 烽火通信科技股份有限公司 一种用于数据库逻辑日志审计的方法及装置
CN113836160A (zh) * 2021-09-28 2021-12-24 上海市大数据股份有限公司 一种基于主从同步的数据流状态监控告警***
CN113836160B (zh) * 2021-09-28 2024-01-23 上海市大数据股份有限公司 一种基于主从同步的数据流状态监控告警***
CN115934428A (zh) * 2023-01-10 2023-04-07 湖南三湘银行股份有限公司 一种mysql数据库的主灾备切换方法、装置及电子设备
CN115934428B (zh) * 2023-01-10 2023-05-23 湖南三湘银行股份有限公司 一种mysql数据库的主灾备切换方法、装置及电子设备
CN115941451A (zh) * 2023-02-21 2023-04-07 浙江国利信安科技有限公司 工业控制网络中冗余切换的方法、设备和存储介质
CN115941451B (zh) * 2023-02-21 2023-05-09 浙江国利信安科技有限公司 工业控制网络中冗余切换的方法、设备和存储介质
CN115914418B (zh) * 2023-03-09 2023-06-30 北京全路通信信号研究设计院集团有限公司 一种铁路接口网关设备
CN115914418A (zh) * 2023-03-09 2023-04-04 北京全路通信信号研究设计院集团有限公司 一种铁路接口网关设备

Also Published As

Publication number Publication date
CN107291787A (zh) 2017-10-24
CN107291787B (zh) 2020-08-28

Similar Documents

Publication Publication Date Title
WO2017177941A1 (zh) 主备数据库切换方法和装置
WO2016173179A1 (zh) 一种数据库主备切换的方法及装置
EP3617886B1 (en) Hot backup system, hot backup method, and computer device
WO2016070375A1 (zh) 一种分布式存储复制***和方法
US20070083641A1 (en) Using a standby data storage system to detect the health of a cluster of data storage servers
CN106933843B (zh) 数据库心跳检测方法以及装置
US11892922B2 (en) State management methods, methods for switching between master application server and backup application server, and electronic devices
WO2021226905A1 (zh) 一种数据存储方法、***及存储介质
WO2019020081A1 (zh) 分布式***及其故障恢复方法、装置、产品和存储介质
GB2484086A (en) Reliability and performance modes in a distributed storage system
US9164864B1 (en) Minimizing false negative and duplicate health monitoring alerts in a dual master shared nothing database appliance
CN102394914A (zh) 集群脑裂处理方法和装置
US20220229822A1 (en) Data processing method and device for distributed database, storage medium, and electronic device
WO2022088861A1 (zh) 数据库故障处理方法和装置
CN114138732A (zh) 一种数据处理方法及装置
CN113326251B (zh) 数据管理方法、***、设备和存储介质
EP3896571B1 (en) Data backup method, apparatus and system
CN108733808B (zh) 大数据软件***切换方法、***、终端设备及存储介质
CN116781488A (zh) 数据库高可用实现方法、装置、数据库架构、设备和产品
CN105323271B (zh) 一种云计算***以及云计算***的处理方法和装置
CN116185697B (zh) 容器集群管理方法、装置、***、电子设备及存储介质
CN112650629A (zh) 区块链索引数据恢复方法、装置、设备和计算机存储介质
CN116389233B (zh) 容器云管理平台主备切换***、方法、装置和计算机设备
CN112887367A (zh) 实现分布式集群高可用的方法、***及计算机可读介质
CA2619778C (en) Method and apparatus for sequencing transactions globally in a distributed database cluster with collision monitoring

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17781917

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 17781917

Country of ref document: EP

Kind code of ref document: A1