Database cluster failover methods, media, and products
By obtaining database cluster information, selecting the optimal backup library and calculating recovery point targets, the problem of excessive RPO or asynchronous backup library in the existing technology cannot be failed over, and high success rate failover and effective data loss control are achieved.
Patent Information
- Application Number
- CN202411945315.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-04
AI Technical Summary
During the failover of existing primary and secondary database clusters, there are problems such as excessive RPO or asynchronous backup databases being unable to failover, resulting in uncontrollable data loss or unavailable database cluster.
By obtaining all database information in the database cluster, selecting the optimal backup library, and computing the recovery point target (RPO) to determine whether it is less than or equal to the data loss threshold, and if so, promote the optimal backup library to the new master library, and update its role to ensure the failover is successful.
It improves the success rate of database cluster failover, improves the availability of database clusters, and effectively controls the amount of data loss, ensuring that the recovery point target does not be too large.
Smart Images

Figure CN119759664A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a failover method, medium and product of a database cluster. Background Art
[0002] In the existing master-slave database cluster, after the master database fails, the standby database can be promoted to the master database to continue to provide external services. This process is called failover. There are currently two mainstream failover solutions: Solution 1 is failover in a synchronous cluster. After the master database fails, the synchronous standby database is promoted to the master database to ensure that the recovery point object (RPO) is 0 and there is no data loss. Solution 2 is failover in an asynchronous cluster. After the master database fails, the asynchronous standby database is promoted to the master database to ensure that the recovery time object (RTO) is as short as possible, so that users can use the database quickly, and the amount of data loss cannot be controlled.
[0003] Both of the above solutions have related disadvantages: In solution 1, in order to ensure database performance, not all nodes are synchronous standby databases, and some asynchronous standby databases exist. Once the primary database and the synchronous standby database fail, in order to ensure that the RPO is 0, the remaining asynchronous standby databases cannot fail over, and the entire database cluster cannot be used. In solution 2, there is no synchronous standby database in the entire database cluster. The main purpose is to ensure a successful failover. After the failover, the RPO may be very large, and there is an unacceptable amount of data loss. Summary of the invention
[0004] An object of the present invention is to provide a failover method, medium and product for a database cluster that can solve any of the above problems.
[0005] A further object of the present invention is to increase the success rate of database cluster failover and improve the availability of the database cluster.
[0006] Another further object of the present invention is to ensure that the recovery point objective is not too large and to effectively control the amount of data loss.
[0007] In particular, the present invention provides a failover method for a database cluster, comprising: obtaining database information of all databases in the recorded database cluster; selecting an optimal standby database among all databases; determining whether an optimal standby database exists; if so, calculating a recovery point objective; determining whether the recovery point objective is less than or equal to a data loss threshold; and if so, promoting the optimal standby database to a new primary database, updating the database role of the optimal standby database to the primary database, and updating the database role of the original primary database to the standby database.
[0008] Optionally, the database information includes: database status and whether it is a synchronous standby database, and the step of selecting the optimal standby database from all databases includes: selecting a database whose database status is running from all databases as a candidate database; judging whether there is a synchronous standby database in the candidate database, and if so, selecting all synchronous standby databases as pre-selected databases; if not, selecting an asynchronous standby database as the pre-selected database.
[0009] Optionally, the database information also includes: a database number and a write-ahead log sequence number, and the step of selecting the optimal standby database from the pre-selected databases includes: selecting the database with the largest write-ahead log sequence number from the pre-selected databases; if there is only one database with the largest write-ahead log sequence number, using the database as the optimal standby database; if there are multiple databases with the largest write-ahead log sequence number, selecting the database with the smallest database number as the optimal standby database.
[0010] Optionally, the step of calculating the recovery point objective includes: determining whether the optimal standby database is a synchronous standby database, and if so, determining that the recovery point objective is 0.
[0011] Optionally, when the optimal standby database is an asynchronous standby database, the recorded write-ahead log sequence number of the original primary database is obtained, and the recovery point target is determined to be the difference between the write-ahead log sequence number of the original primary database and the write-ahead log sequence number of the optimal standby database.
[0012] Optionally, when there is no optimal standby database or the recovery point objective is greater than the data loss threshold, the failover process is interrupted and it is determined that there is no primary database in the database cluster.
[0013] Optionally, cluster management software of the database cluster records database information of all databases at preset time intervals.
[0014] Optionally, the step of the cluster management software recording the database information of all databases at preset time intervals includes: querying all databases in parallel according to the database number: recording the database information after all database queries are completed; and when the main database is running, after waiting for a preset time, returning to execute the step of querying all databases in parallel according to the database number.
[0015] Optionally, the step of querying all databases in parallel according to the database number includes: when the database is operating normally, querying the database role, the write-ahead log sequence number, and whether the standby database is a synchronous standby database; when the database is abnormal or unresponsive, setting its database status to not running.
[0016] Optionally, after all database queries are completed, the step of recording database information includes: when the database is operating normally, recording the current information of the queried database under the corresponding database number; when the database is not operating, recording the database status of the database number corresponding to the database as not operating, and other information of the database is not recorded.
[0017] Optionally, when the master database is not running, the cluster management software initiates a failover and the failover process begins.
[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the failover method of a database cluster described above is implemented.
[0019] According to yet another aspect of the present invention, there is further provided a computer program product, comprising a computer program, wherein the computer program implements any of the above-mentioned database cluster failover methods when executed by a processor.
[0020] The failover method of a database cluster of the present invention obtains database information of all recorded databases, selects an optimal standby database from all databases, calculates a recovery point target if an optimal standby database exists, and, when the recovery point target is less than or equal to a data loss threshold, promotes the optimal standby database to a new primary database, updates the database role of the optimal standby database to the primary database, and updates the database role of the original primary database to the standby database, thereby improving the success rate of failover of the database cluster and improving the availability of the database cluster.
[0021] Furthermore, the failover method for a database cluster of the present invention, when the optimal standby database is a synchronous standby database, determines the recovery point target to be 0; when the optimal standby database is an asynchronous standby database, obtains the recorded write-ahead log sequence number of the original primary database, determines the recovery point target to be the difference between the write-ahead log sequence number of the original primary database and the write-ahead log sequence number of the optimal standby database, ensures that when the recovery point target is less than or equal to the data loss threshold, the optimal standby database is promoted to the new primary database, can ensure that the recovery point target is not too large, and effectively control the amount of data loss.
[0022] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0024] Figure 1 is a schematic flow chart of a failover method for a database cluster according to an embodiment of the present invention;
[0025] Figure 2 is a schematic flow chart of recording database information in a failover method of a database cluster according to an embodiment of the present invention;
[0026] Figure 3 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention;
[0027] Figure 4 is a schematic diagram of a computer program product according to an embodiment of the present invention; and
[0028] Figure 5 is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.
[0030] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0031] The purpose of the failover method of the database cluster in this embodiment is to improve the success rate of the failover of the database cluster and enhance the availability of the database cluster. Figure 1 FIG. 1 is a schematic flow chart of a failover method for a database cluster according to an embodiment of the present invention. Figure 1 As shown, in one embodiment, the failover method of a database cluster may generally include the following steps:
[0032] Step S102, obtaining database information of all databases in the recorded database cluster. Specifically, the cluster management software of the database cluster records the database information of all databases at preset intervals, and after discovering a failure in the main database, the cluster management software initiates a failover. After the database information is queried, it is saved in the cluster management software, and the information is used as a reference during failover, that is, the database information can provide a basis for judging failover.
[0033] Specifically, the database information may include: database number, database role, database status, whether it is a synchronous standby database, and the write-ahead log sequence number. Among them, the database number (DB ID) is a unique and unchanging positive integer number for each database, which is generated when the database cluster is deployed. The database role (DB Role) includes: primary or standby. The database status (DB Status) includes: running (Running) or not running (Not Running). Whether it is a synchronous standby database (Sync Standby) includes: yes (Sync Standby is True) or no (Sync Standby is False). The database write-ahead log sequence number (WAL Number) is the log sequence number of the latest disk of the current database query. The log sequence number can represent the latest data of the database.
[0034] Write-Ahead Log (WAL) is used to record data changes in the database. Each time a log is recorded, a corresponding WAL number is generated, and the WAL number is incremented. The master database refers to the main database, which can be read and written. In the master-slave database cluster, only one node is the main database. The standby database refers to the standby database, which can only be read. In the master-slave database cluster, the standby database synchronizes data from the main database.
[0035] Regarding synchronous standby databases, the data of the primary database needs to be transferred to the synchronous standby database and wait for other data to be written to disk before it can be committed. After the primary database fails, the synchronous standby database has all the data that has been committed before the primary database fails. Regarding asynchronous standby databases, the data of the primary database does not need to wait for the asynchronous standby database to be written to disk. After the primary database fails, the asynchronous standby database may lack data.
[0036] Step S104, select the best standby database from all databases. Specifically, a database in the running state can be selected from all databases as a candidate database; determine whether there is a synchronous standby database in the candidate database, if so, select all synchronous standby databases as pre-selected databases; if not, select an asynchronous standby database as the pre-selected database.
[0037] The step of selecting the optimal standby database from the pre-selected databases may include: selecting the database with the largest write-ahead log sequence number from the pre-selected databases; if there is only one database with the largest write-ahead log sequence number, using the database as the optimal standby database; if there are multiple databases with the largest write-ahead log sequence number, selecting the database with the smallest database number as the optimal standby database.
[0038] That is, the following filters are performed in sequence, each time filtering again from the results of the previous step: (1) Select all databases whose database status (DB Status) is Running; (2) If there is a synchronous standby database (Sync Standby is True), select all synchronous standby databases; otherwise, select an asynchronous standby database (Sync Standby is False); (3) Select the database with the largest write-ahead log number (WAL Number); (4) Select the database with the smallest database number (DB ID); (5) Finally, the optimal standby database is obtained.
[0039] Step S106, determine whether there is an optimal backup database. If so, execute step S110. If not, execute step S108. Specifically, if the result of step S106 is yes, that is, if there is an optimal backup database, execute step S110. If the result of step S106 is no, that is, if there is no optimal backup database, execute step S108.
[0040] Step S108, interrupting the failover process, and determining that there is no master database in the database cluster. Specifically, interrupting the failover process can be considered as a failover failure.
[0041] Step S110, calculate the recovery point objective. In the case of an optimal standby database, calculate the recovery point objective (RPO). Specifically, it can be determined whether the optimal standby database is a synchronous standby database. If so, the recovery point objective is determined to be 0. In the case that the optimal standby database is an asynchronous standby database, obtain the recorded write-ahead log sequence number of the original primary database, and determine the recovery point objective as the difference between the write-ahead log sequence number of the original primary database and the write-ahead log sequence number of the optimal standby database.
[0042] That is, if the optimal standby database is a synchronous standby database (Sync Standby is True), RPO = 0. If the optimal standby database is an asynchronous standby database (Sync Standby is False), the WAL Number of the recorded primary database can be obtained, then RPO = primary database WAL Number - optimal standby database WAL Number.
[0043] Step S112, determine whether the recovery point objective is less than or equal to the data loss threshold, if so, execute step S114, if not, execute step S108. Specifically, if the judgment result of step S112 is yes, that is, if the recovery point objective is less than or equal to the data loss threshold, execute step S114. If the judgment result of step S112 is no, that is, if the recovery point objective is greater than the data loss threshold, execute step S108, interrupt the failover process, and it can be considered that the failover has failed.
[0044] The data loss threshold may be an integer greater than or equal to 0. In a specific embodiment, if the user does not set the data loss threshold, the data loss threshold defaults to 0. Since the recovery point objective (RPO) is an indicator of how much production data will be lost after a disaster occurs, it can be simply described as the maximum amount of data loss that the facility can tolerate. The definition of RPO determines that it cannot be less than 0. Therefore, when the data loss threshold is 0, if the recovery point objective is less than or equal to the data loss threshold, the recovery point objective RPO = 0 can be guaranteed.
[0045] Step S114: Promote the optimal standby database to the new primary database, update the database role of the optimal standby database to the primary database, and update the database role of the original primary database to the standby database. Specifically, when the recovery point objective is less than or equal to the data loss threshold, the optimal standby database is promoted to the new primary database, and the failover can be considered successful.
[0046] For example, when the data loss threshold is 0, and the recovery point objective RPO = 0, the optimal standby database is promoted to the primary database, the database role DB Role of the optimal standby database is updated to primary, and the database role DBRole of the original primary database is updated to standby.
[0047] In the solution of this embodiment, database information of all databases in the recorded database cluster is obtained, and the optimal standby database is selected from all databases. If an optimal standby database exists, the recovery point target is calculated, and when the recovery point target is less than or equal to the data loss threshold, the optimal standby database is promoted to the new primary database, and the database role of the optimal standby database is updated to the primary database, and the database role of the original primary database is updated to the standby database, which can improve the success rate of database cluster failover and improve the availability of the database cluster.
[0048] When the optimal standby database is a synchronous standby database, the recovery point target is determined to be 0; when the optimal standby database is an asynchronous standby database, the recorded write-ahead log sequence number of the original primary database is obtained, and the recovery point target is determined to be the difference between the write-ahead log sequence number of the original primary database and the write-ahead log sequence number of the optimal standby database. When the recovery point target is less than or equal to the data loss threshold, the optimal standby database is promoted to the new primary database, which can ensure that the recovery point target is not too large and effectively control the amount of data loss.
[0049] As mentioned above, the cluster management software of the database cluster records the database information of all databases at preset intervals to provide a basis for subsequent failover. Figure 2 FIG. 1 is a schematic flow chart of recording database information in a failover method of a database cluster according to an embodiment of the present invention. Figure 2 As shown, recording database information may generally include the following steps:
[0050] Step S202, query all databases in parallel according to the database number. Specifically, if the database is running normally, query the database role, write-ahead log sequence number, and whether the standby database is a synchronous standby database. If the database is abnormal or unresponsive, set its database status DB Status to not running.
[0051] Step S204, after all database queries are completed, the database information is recorded. Specifically, if the database is running normally, the current information of the queried database is recorded under the corresponding database number (DB ID). If the database is not running, the database status DB Status of the database number (DB ID) corresponding to the database is recorded as Not Running, and other information of the database is not recorded.
[0052] Step S206, determine whether the main library is running, if yes, execute step S210, if no, execute step S208. Specifically, if the judgment result of step S206 is yes, that is, if the main library is running, execute step S210. If the judgment result of step S206 is no, that is, if the main library is not running, execute step S208.
[0053] Step S208: The cluster management software initiates a failover, and the failover process begins. When the master database is not running, the cluster management software of the database cluster initiates a failover, and the failover process begins. That is, the above embodiment can be executed. Figure 1 Steps for failover in .
[0054] Step S210, after waiting for a preset time, return to step S202. When the main database is running, after waiting for a preset time, return to step S202, restart parallel query of all databases according to database numbers, and perform a new round of query and record of databases.
[0055] The shorter the preset time interval for obtaining database information, the better. In this way, when the main database fails, the previously obtained information can more accurately represent the amount of data before the main database fails. Specifically, the preset time can be set in the range of 1ms to 1s, preferably, it can be set in the range of 200ms to 500ms.
[0056] In the solution of this embodiment, after the failure of the database master database, the data volume of the database master database and the database standby database can be monitored in real time. As long as the data volume of the remaining standby database and the failed main database are within the specified range, failover can be initiated: in a synchronous cluster, an asynchronous standby database that meets the conditions can also failover; in an asynchronous cluster, only an asynchronous standby database that meets the conditions can initiate failover, ensuring that the RPO is within an acceptable range.
[0057] It should be noted that the flowchart provided by the above embodiment is not intended to indicate that the operations of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical ideas provided by the above embodiment method, additional changes may be made to the above method.
[0058] This embodiment also provides a computer-readable storage medium, a computer program product, and a computer device. Figure 3 is a schematic diagram of a computer-readable storage medium 300 according to one embodiment of the present invention. Figure 4 is a schematic diagram of a computer program product 500 according to one embodiment of the present invention. Figure 5 is a schematic diagram of a computer device 400 according to one embodiment of the present invention.
[0059] The computer program product 500 includes a computer program 310, which implements any of the above-mentioned database cluster failover methods when executed by a processor 410. The computer-readable storage medium 300 stores the above-mentioned computer program 310, which implements any of the above-mentioned database cluster failover methods when executed by the processor 410. The computer device 400 may include a memory 420, a processor 410, and a computer program 310 stored in the memory 420 and running on the processor 410.
[0060] The computer program 310 used to perform the operations of the present invention can be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, configuration data of an integrated circuit, or source code or object code written in any combination of one or more programming languages and procedural programming languages.
[0061] The computer program 310 may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet Service Provider).
[0062] In some embodiments, in order to perform various aspects of the present invention, electronic circuits including, for example, programmable logic circuits, field programmable gate arrays (FPGAs) or programmable logic arrays (PLAs) can execute computer-readable program instructions by utilizing state information of the computer-readable program instructions to personalize the electronic circuits.
[0063] For the description of this embodiment, the computer program product 500 is a related product including the computer program 310. For the description of this embodiment, the computer-readable storage medium 300 is a tangible device capable of retaining and storing the computer program 310, which can be any device that can contain, store, communicate, propagate or transmit the program 310 for use in an instruction execution system, device or apparatus or in conjunction with these instruction execution systems, devices or apparatuses.
[0064] More specific examples (a non-exhaustive list) of computer-readable storage media 300 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the foregoing.
[0065] The computer device 400 may include a memory 420 , a processor 410 , and a computer program 310 stored in the memory 420 and running on the processor 410 , and the processor 410 implements the failover method of the database cluster in any of the above embodiments when executing the computer program 310 .
[0066] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any machine-readable storage medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0067] It should be understood that each part of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0068] Computer device 400 can be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, computer device 400 can be a cloud computing node. Computer device 400 can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module can include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. Computer device 400 can be implemented in a distributed cloud computing environment where remote processing devices linked through a communication network perform tasks. In a distributed cloud computing environment, program modules can be located on a local or remote computing system storage medium including a storage device.
[0069] The computer device 400 may include a processor 410 adapted to execute stored instructions, and a memory 420 providing temporary storage space for the operation of instructions during operation. The processor 410 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 420 may include a random access memory (RAM), a read-only memory, a flash memory, or any other suitable storage system.
[0070] The processor 410 may be connected to an I / O interface (input / output interface) suitable for connecting the computer device 400 to one or more I / O devices (input / output devices) through a system interconnect (e.g., PCI, PCI-Express, etc.). The I / O devices may include, for example, a keyboard and a pointing device, wherein the pointing device may include a touch pad or a touch screen, etc. The I / O devices may be built-in components of the computer device 400, or may be devices externally connected to the computing device.
[0071] Processor 410 may also be linked to a display interface suitable for connecting computer device 400 to a display device through a system interconnect. Display device may include a display screen as a built-in component of computer device 400. Display device may also include a computer monitor, a television or a projector, etc., externally connected to computer device 400. In addition, a network interface controller (NIC) may be suitable for connecting computer device 400 to a network through a system interconnect. In some embodiments, NIC may use any suitable interface or protocol (such as an Internet small computer system interface, etc.) to transmit data. The network may be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN) or the Internet, etc. A remote device may be connected to a computing device through a network.
[0072] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A failover method for a database cluster, comprising: Obtaining the recorded database information of all databases in the database cluster; Selecting the best backup database from all the databases; Determine whether the optimal backup database exists; If yes, calculate the recovery point objective; Determining whether the recovery point objective is less than or equal to a data loss threshold; as well as If so, the optimal standby database is promoted to a new primary database, the database role of the optimal standby database is updated to the primary database, and the database role of the original primary database is updated to the standby database.
2. The method according to claim 1, wherein: The database information includes: database status and whether it is a synchronous standby database, and The steps of selecting the optimal standby database from all the databases include: Selecting a database whose database status is running from among all the databases as a candidate database; Determine whether there is the synchronous standby database in the candidate database, and if so, select all the synchronous standby databases as pre-selected databases; if not, select the asynchronous standby database as the pre-selected database; and The optimal standby database is selected from the pre-selected database.
3. The method according to claim 2, wherein: The database information also includes: a database number and a write-ahead log sequence number, and The step of selecting the optimal standby database from the pre-selected database comprises: Select the database with the largest write-ahead log sequence number among the pre-selected databases; If there is only one database with the largest write-ahead log sequence number, use this database as the optimal standby database; If there are multiple databases with the largest write-ahead log serial number, the database with the smallest database serial number is selected as the optimal standby database.
4. The method of claim 3, wherein the step of calculating the recovery point objective comprises: Determine whether the optimal standby database is the synchronous standby database, If so, the recovery point objective is determined to be 0.
5. The method according to claim 4, wherein: When the optimal standby database is the asynchronous standby database, the recorded write-ahead log sequence number of the original primary database is obtained, and the recovery point target is determined to be the difference between the write-ahead log sequence number of the original primary database and the write-ahead log sequence number of the optimal standby database.
6. The method according to claim 1, wherein: In the case where the optimal standby database does not exist or the recovery point objective is greater than the data loss threshold, the failover process is interrupted and it is determined that there is no primary database in the database cluster.
7. The method according to claim 3, wherein the step of recording the database information of all the databases comprises: The cluster management software of the database cluster records the database information of all the databases at preset time intervals.
8. The method according to claim 7, wherein the step of the cluster management software of the database cluster recording the database information of all the databases at preset intervals comprises: Query all the databases in parallel according to the database number: After all the database queries are completed, recording the database information; as well as When the main database is running, after waiting for the preset time, the process returns to execute the step of querying all the databases in parallel according to the database numbers.
9. The method according to claim 8, wherein the step of querying all the databases in parallel according to the database numbers comprises: When the database is running normally, query the database role, write-ahead log sequence number, and whether the standby database is a synchronous standby database of the database; When the database is abnormal or unresponsive, its database status is set to not running.
10. The method according to claim 9, wherein after all the database queries are completed, the step of recording the database information comprises: When the database is operating normally, the current information of the queried database is recorded under the corresponding database number; When the database is not running, the database status of the database number corresponding to the database is recorded as not running, and other information of the database is not recorded.
11. The method according to claim 8, wherein: When the master database is not running, the cluster management software initiates a failover and the failover process begins.
12. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the failover method for a database cluster according to any one of claims 1 to 11 is implemented.
13. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the failover method for a database cluster according to any one of claims 1 to 11 is implemented.