Fragmentation defragmentation method, device, equipment and storage medium based on master-slave database
By defragmenting the slave database in the master-slave database structure and switching the database master-slave database, the problem of business interruption during the database defragmentation process is solved, and business continuity is protected.
Patent Information
- Application Number
- CN202110300938.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-22
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2041-03-22
AI Technical Summary
During the defragmentation process of databases, existing technologies are prone to business interruptions and affect business continuity.
The defragmentation method based on the master-slave database is adopted. First, the slave database is defragmented, and the database master-slave switch is performed after completion. The slave database is replaced with a database that provides external services, and then the master database is defragmented.
Through this method, it is ensured that there is always a database to provide services to the outside world during the defragmentation process, which reduces business interruption time and only exists in the instantaneous impact during the database switching process.
Smart Images

Figure CN113051248B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of database technology, and particularly to a fragmentation reorganization method, apparatus, device, and storage medium based on a master-slave database. Background Art
[0002] With the development of Internet services and the increasing requirement for 7*24-hour uninterrupted services, any operation and maintenance operation must minimize the impact on the in-transit services of the system itself. However, the fragmentation reorganization module built into the database is likely to cause in-transit transactions to be unavailable for a short time during the fragmentation reorganization of large database tables, which may have a significant impact on business continuity. Summary of the Invention
[0003] The purpose of the embodiments of this specification is to provide a fragmentation reorganization method, apparatus, device, and storage medium based on a master-slave database to reduce the impact of database fragmentation reorganization on business continuity.
[0004] To achieve the above purpose, on the one hand, the embodiments of this specification provide a fragmentation reorganization method based on a master-slave database, including:
[0005] Determine the master database and its corresponding slave database;
[0006] When the master database is the database providing services externally, perform fragmentation reorganization on the slave database;
[0007] After completing the fragmentation reorganization of the slave database, perform a master-slave switch of the database to replace the database providing services externally with the slave database;
[0008] Perform fragmentation reorganization on the master database.
[0009] In the embodiments of this specification, the determination of the slave database corresponding to the master database includes:
[0010] Determine the master database and its corresponding first slave database and second slave database.
[0011] In the embodiments of this specification, when the master database is the database providing services externally, performing fragmentation reorganization on the slave database includes:
[0012] When the master database is the database providing services externally, perform fragmentation reorganization on the first slave database and the second slave database.
[0013] In the embodiments of this specification, the fragmentation reorganization of the first slave database and the second slave database includes:
[0014] Perform fragmentation reorganization on the first slave database;
[0015] After finishing the defragmentation of the first slave database, perform defragmentation on the second slave database.
[0016] In the embodiments of this specification, after finishing the defragmentation of the slave database, performing master-slave database switching includes:
[0017] After finishing the defragmentation of the first slave database and the second slave database, perform master-slave database switching on the first slave database and the master database.
[0018] In the embodiments of this specification, the method further includes:
[0019] During the process of defragmenting the second slave database, enable the first slave database to synchronize data from the master database.
[0020] In the embodiments of this specification, performing master-slave database switching on the first slave database and the master database includes:
[0021] After finishing the synchronization of data from the master database by the first slave database, perform master-slave database switching on the first slave database and the master database.
[0022] On the other hand, the embodiments of this specification further provide a defragmentation device based on a master-slave database, which includes:
[0023] A database determination module, configured to determine a master database and its corresponding slave database;
[0024] A first defragmentation module, configured to defragment the slave database when the master database is the database providing services externally;
[0025] A database switching module, configured to perform master-slave database switching after finishing the defragmentation of the slave database, so as to replace the database providing services externally with the slave database;
[0026] A second defragmentation module, configured to defragment the master database.
[0027] On the other hand, the embodiments of this specification further provide a computer device, including a memory, a processor, and a computer program stored on the memory. When the computer program is run by the processor, it executes the instructions of the above method.
[0028] On the other hand, the embodiments of this specification further provide a computer storage medium, on which a computer program is stored. When the computer program is run by the processor of a computer device, it executes the instructions of the above method.
[0029] As can be seen from the technical solutions provided in the embodiments of this specification above, in the embodiments of this specification, a master-slave database structure for real-time synchronization is pre-established. When fragmentation needs to be performed, when the master database is the database providing external services, the slave database is first fragmented. After the fragmentation of the slave database is completed, a database master-slave switch is executed to replace the database providing external services with the slave database, and then the master database is fragmented. During the entire fragmentation process, it is ensured that one database can provide external services, thereby greatly reducing the interruption time of the business system during the database fragmentation process. The business impact generally only exists in the instantaneous impact during the database switch. Therefore, the embodiments of this specification can significantly reduce the impact on business continuity during the database fragmentation process and improve the stability and reliability of the business system. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions in the embodiments of this specification or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments recorded in this specification. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings. In the drawings:
[0031] Figure 1 Shows the flowchart of the fragmentation method based on the master-slave database in some embodiments of this specification;
[0032] Figure 2 Shows the structural schematic diagram of the master-slave database in some embodiments of this specification;
[0033] Figure 3 Shows the flowchart of the fragmentation method based on the master-slave database in some other embodiments of this specification;
[0034] Figure 4 Shows the structural block diagram of the fragmentation device based on the master-slave database in some embodiments of this specification;
[0035] Figure 5 Shows the structural block diagram of a computer device in some embodiments of this specification.
[0036]
DESCRIPTION OF THE REFERENCE NUMERALS
[0037] 41. Database determination module;
[0038] 42. First fragmentation module;
[0039] 43. Database switch module;
[0040] 44. Second defragmentation module;
[0041] 502. Computer device;
[0042] 504. Processor;
[0043] 506. Memory;
[0044] 508. Driving mechanism;
[0045] 510. Input / output module;
[0046] 512. Input device;
[0047] 514. Output device;
[0048] 516. Presentation device;
[0049] 518. Graphical user interface;
[0050] 520. Network interface;
[0051] 522. Communication link;
[0052] 524. Communication bus. Detailed implementation
[0053] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of this specification. Obviously, the described embodiments are only a part of the embodiments of this specification, rather than all of the embodiments.
[0054] In the production environment of the database, operations such as inserting, deleting, and modifying the data in the table are continuously performed, which will gradually form more and more discrete, separated, and smaller free spaces, that is, fragments. A large number of fragments will cause the performance of the database system to weaken and waste a large amount of table space. Therefore, the database also needs to be defragmented. The traditional database defragmentation is to suspend the database from providing services externally during the off-peak business period (such as at night), and use the built-in defragmentation module of the database to defragment the database. However, during the process of defragmenting the database (especially large tables with a data volume of more than ten million), it often causes the database to be unable to provide services externally normally for more than 30 minutes, which will have a greater impact on business continuity.
[0055] In view of this, in order to reduce the impact of database defragmentation on business continuity, this specification provides embodiments of a defragmentation method based on a master-slave database, which can be applied to any suitable computer device. Refer to Figure 1As shown, in some embodiments of this specification, the fragmentation method based on the master-slave database may include the following steps:
[0056] S101. Determine the master database and its corresponding slave database.
[0057] S102. When the master database is the database providing services externally, perform fragmentation on the slave database.
[0058] S103. After completing the fragmentation of the slave database, perform a master-slave database switch to replace the database providing services externally with the slave database.
[0059] S104. Perform fragmentation on the master database.
[0060] In the embodiments of this specification, a real-time synchronized master-slave database structure is pre-established. When fragmentation needs to be performed, when the master database is the database providing services externally, first perform fragmentation on the slave database. After completing the fragmentation of the slave database, perform a master-slave database switch to replace the database providing services externally with the slave database, and then perform fragmentation on the master database. During the entire fragmentation process, ensure that one database can provide services externally, thereby greatly reducing the interruption time of the business system during the database fragmentation process. The business impact generally only exists in the instantaneous impact during the database switch. Therefore, the embodiments of this specification can significantly reduce the impact on business continuity during the database fragmentation process and improve the stability and reliability of the business system.
[0061] The above determination of the master database and its corresponding slave database is to determine the object to be fragmented (this object is the master-slave database structure). In some embodiments of this specification, the above master-slave database structure may be a master-slave database structure with one master and two slaves, that is, a structure with one master database plus two slave databases. When the master database provides services externally and one of the slave databases is undergoing fragmentation, once the master database fails, another slave database can be used to perform a master-slave switch with the master database (i.e., the master-slave switch) to maintain the normal operation of the business. Obviously, for the above master-slave database structure with one master and two slaves, during the process where any one database provides services externally and the second database is undergoing fragmentation, once the currently externally providing service database fails, the currently externally providing service database can be quickly switched with the third database for master-slave (i.e., perform a master-slave switch). In this way, it is beneficial to further reduce the impact on business continuity during the fragmentation process.
[0062] For example, in Figure 2The structure of one master database (Database A) plus two slave databases (Database B and Database C) is shown in the illustrated embodiment. If Database A provides services externally through the server, and Database B is in the process of defragmentation, if Database A fails at this time, the master-slave switch between Database A and Database C can be performed. In this way, both the normal operation of the service can be ensured, and the defragmentation of Database B is not affected. Similarly, if Database A provides services externally through the server, and Database C is in the process of defragmentation, if Database A fails at this time, the master-slave switch between Database A and Database B can be performed. In this way, both the normal operation of the service can be ensured, and the defragmentation of Database C is not affected.
[0063] In the master-slave database structure of one master and two slaves, when the master database is the database providing services externally, defragmenting the slave databases may include:
[0064] When the master database is the database providing services externally, defragmenting the first slave database and the second slave database. Specifically, in order to further reduce the impact on service continuity during the defragmentation process, the first slave database and the second slave database can be defragmented sequentially. For example, the first slave database can be defragmented first; after the defragmentation of the first slave database is completed, the second slave database can be defragmented. Of course, the second slave database can also be defragmented first; after the defragmentation of the second slave database is completed, the first slave database can be defragmented.
[0065] In some embodiments of this specification, performing a master-slave switch of the database after completing the defragmentation of the slave database includes:
[0066] After completing the defragmentation of the first slave database and the second slave database, performing a master-slave switch of the first slave database and the master database. It should be noted that this is based on the premise that the first slave database completes the defragmentation first. Of course, if the second slave database completes the defragmentation before the first slave database, the master-slave switch will become the master-slave switch between the master database and the second slave database.
[0067] In the embodiments of this specification, the master-slave databases are all synchronized with real-time data, that is, when the master database has data updates, the updated data will be synchronized to the slave databases in real time. When a database is in the process of defragmentation, it cannot perform data synchronization and needs to perform data synchronization after completing the defragmentation. For example, for the above Figure 2For the databases B and C shown, when database B finishes defragmentation first and during the process of defragmenting database C, database B can synchronize data from database A. In this case, since database C also needs to synchronize data with database A after completing defragmentation, database B will be better prepared for the switch with database A earlier. Therefore, after completing the defragmentation of databases B and C (actually including the synchronization of database B from database A), the master-slave switch of databases A and B can be performed so that database A can perform defragmentation subsequently. That is, when database B finishes defragmentation first and during the defragmentation of database C, it can be regarded as a buffer period and observation period for database B after defragmentation to ensure the stability of the master-slave structure of databases A and B.
[0068] Reference Figure 3 As shown, in some other embodiments of this specification, the defragmentation method based on master-slave databases (taking Figure 2 the master-one-slave-two master-slave database structure shown as an example) may include the following steps:
[0069] S301. Trigger defragmentation.
[0070] In an embodiment of this specification, a scheduled task can be set in advance for the defragmentation of the database. When the scheduled time arrives, the defragmentation of the database can be triggered. This is only an exemplary example. In other embodiments of this specification, the triggering condition of defragmentation can be set according to actual needs, and this specification does not make a unique limitation on this.
[0071] S302. Database B starts defragmentation.
[0072] S303. Determine whether database B has completed defragmentation. If it has been completed, adjust to execute step S304, otherwise continue to judge.
[0073] S304. Database C starts defragmentation.
[0074] Among them, during the defragmentation of database C, database B can also synchronize data with database A.
[0075] S305. Determine whether database C has completed defragmentation. If it has been completed, adjust to execute step S306, otherwise continue to judge.
[0076] S306. The master-slave switch of databases A and B is performed.
[0077] S307. Database A starts defragmentation.
[0078] S308. Complete defragmentation.
[0079] When database A finishes defragmentation, it can be regarded as completing the defragmentation of the entire master-slave database structure with one master and two slaves. Of course, after database A finishes defragmentation, it also needs to synchronize data with database B, which is currently the master database.
[0080] In this way, in the entire master-slave database structure with one master and two slaves, when any one database is in the process of defragmentation, not only does one other database provide services externally, but another database serves as a backup. If the database providing services externally fails, the other database can be used to continue providing services externally. In this way, it can not only ensure the normal operation of the business but also not affect the defragmentation of the database.
[0081] Those skilled in the art can understand that in the embodiments of this specification, for the specific implementation of defragmentation in the above steps, any existing suitable defragmentation algorithm can be used. This specification does not make any limitations in this regard, and it can be specifically selected according to the specific application scenario and actual needs.
[0082] For example, in the case of a database based on Oracle database technology, database defragmentation can include: calculating the fragmentation of free extents within a tablespace, defragmenting free extents, and defragmenting segments.
[0083] In the calculation of free extent fragmentation, since free space fragmentation consists of several parts, such as the number of extents and the maximum extent size. It can be intuitively reflected by the Free Space Fragmentation Index (FSFI). Specifically, the maximum possible value of FSFI is 100 (an ideal single-file tablespace). As the number of extents increases, the FSFI value decreases slowly, while as the maximum extent size decreases, the FSFI value will decrease rapidly. After calculating the FSFI value of the database, it can be used as a comparable parameter. In a tablespace with sufficient effective free space and an FSFI value exceeding 30, problems with effective free space are rarely encountered. When a tablespace is about to approach or fall below the comparable parameter (such as 30), defragmentation is required. In this way, the objects in the database that need to be defragmented can be located.
[0084] In an embodiment of this specification, the defragmentation of free extents can be, for example: changing the default storage parameter pctincrease of the tablespace to non-zero (for example, setting it to 1). In this way, the background system monitoring process will automatically merge the free extents, thus completing the defragmentation of free extents.
[0085] When generating a database object (a table or an index), a tablespace is specified for it using the user default value or a specified value. A segment generated in the tablespace is used to store the relevant data of the object. The space allocated to the segment will not be released until the segment is closed, shrunk, or truncated. A segment is composed of extents. Once the existing extents can no longer store new data, the segment will acquire new extents, but these extents are not required to be adjacent to each other. Such extensions will continue until the data files in the tablespace cannot provide more free space or the number of extents has reached the limit. Therefore, a data segment with too much fragmentation will not only affect performance but also cause space management problems in the tablespace. So, it is very beneficial for each data segment to contain only one extent. With the help of the system monitoring process, it is possible to determine which database objects contain segments with too many extents (for example, more than 10) and identify the fragmentation of their data segments by checking the DBA_SEGMENTS data dictionary view.
[0086] If a segment has too much fragmentation, there are two ways to solve it: (1) Create a new table with the correct storage parameters, insert the data from the old table into the new table, and then delete the old table; (2) Use tools such as oracle Export / Import to defragment the segment. Among them, the oracle Export / Import tool is a simple, convenient, and flexible backup recovery and data migration tool. It can perform full database-level, user-level, and table-level data backup and recovery. For database systems with data volume at the G level or below, emphasizing high availability and tolerating a small amount of data loss, Export / Import is a commonly used logical backup method. Export: Export data from the database to a dump file (the in-memory image file of the process); Import: Import data from the dump file into the database.
[0087] Although the process flow described above includes multiple operations that occur in a specific order, it should be clearly understood that these processes can include more or fewer operations, and these operations can be executed sequentially or in parallel (for example, using a parallel processor or a multi-threaded environment).
[0088] Corresponding to the above-described method for defragmenting a master-slave database, this specification also provides an embodiment of a device for defragmenting a master-slave database. Refer to Figure 4 As shown, in some embodiments of this specification, the device for defragmenting a master-slave database may include:
[0089] A database determination module 41, which can be used to determine the master database and its corresponding slave database;
[0090] The first fragmentation reorganization module 42 can be used to reorganize the slave database when the master database serves as the database for external services;
[0091] The database switching module 43 can be used to perform a master-slave database switch after the fragmentation reorganization of the slave database is completed, so as to replace the database for external services with the slave database;
[0092] The second fragmentation reorganization module 44 can be used to reorganize the master database.
[0093] In an apparatus embodiment of this specification, determining the slave database corresponding to the master database may include:
[0094] Determine the master database and its corresponding first slave database and second slave database.
[0095] In an apparatus embodiment of this specification, when the master database serves as the database for external services, reorganizing the slave database may include:
[0096] When the master database serves as the database for external services, reorganize the first slave database and the second slave database.
[0097] In an apparatus embodiment of this specification, reorganizing the first slave database and the second slave database may include:
[0098] Reorganize the first slave database;
[0099] After the fragmentation reorganization of the first slave database is completed, reorganize the second slave database.
[0100] In an apparatus embodiment of this specification, performing a master-slave database switch after the fragmentation reorganization of the slave database is completed may include:
[0101] After the fragmentation reorganizations of the first slave database and the second slave database are completed, perform a master-slave database switch on the first slave database and the master database.
[0102] In an apparatus embodiment of this specification, the master-slave database-based fragmentation reorganization apparatus may further include:
[0103] The data synchronization module can be used to enable the first slave database to synchronize data from the master database during the process of reorganizing the second slave database. Of course, this data synchronization module can also be used for data synchronization between other databases in a one-master-two-slave master-slave database structure.
[0104] In an apparatus embodiment of this specification, the database master-slave switchover for the first slave database and the master database may include:
[0105] After the first slave database synchronizes data from the master database, perform database master-slave switchover on the first slave database and the master database.
[0106] For convenience of description, when describing the above apparatus, various units are described separately according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware.
[0107] An embodiment of this specification also provides a computer device. As Figure 5 shown, in some embodiments of this specification, the computer device 502 may include one or more processors 504, such as one or more central processing units (CPUs) or graphics processing units (GPUs), and each processing unit may implement one or more hardware threads. The computer device 502 may also include any memory 506 for storing any kind of information such as code, settings, data, etc. In a specific implementation, a computer program stored on the memory 506 and executable on the processor 504, when run by the processor 504, may execute instructions according to the above method. Non-limiting examples include that the memory 506 may include any one or a combination of the following: any type of RAM, any type of ROM, flash memory devices, hard disks, optical discs, etc. More generally, any memory may use any technology to store information. Further, any memory may provide volatile or non-volatile retention of information. Further, any memory may represent a fixed or removable component of the computer device 502. In one case, when the processor 504 executes associated instructions stored in any memory or combination of memories, the computer device 502 may perform any operation of the associated instructions. The computer device 502 also includes one or more drive mechanisms 508 for interacting with any memory, such as a hard disk drive mechanism, an optical disc drive mechanism, etc.
[0108] The computer device 502 may also include an input / output module 510 (I / O) for receiving various inputs (via the input device 512) and for providing various outputs (via the output device 514). A specific output mechanism may include a presentation device 516 and an associated graphical user interface 518 (GUI). In other embodiments, the input / output module 510 (I / O), the input device 512, and the output device 514 may not be included, and it may only be a computer device in the network. The computer device 502 may also include one or more network interfaces 520 for exchanging data with other devices via one or more communication links 522. One or more communication buses 524 couple the components described above together.
[0109] The communication link 522 may be implemented in any way, for example, through a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 522 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc. governed by any protocol or combination of protocols.
[0110] This application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to some embodiments of this specification. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processors to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processors generate a device for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0111] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processors to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device that implements the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0112] These computer program instructions can also be loaded onto a computer or other programmable data processors, such that a series of operation steps are executed on the computer or other programmable devices to generate a computer-implemented process, so that the instructions executed on the computer or other programmable devices provide for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1Steps of functions specified in one or more boxes.
[0113] In a typical configuration, a computer device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0114] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
[0115] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can store information by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices, or any other non-transitory media that can be used to store information accessible by a computer device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0116] Those skilled in the art should understand that the embodiments of this specification can be provided as a method, a system, or a computer program product. Therefore, the embodiments of this specification can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the embodiments of this specification can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0117] The embodiments of this specification can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The embodiments of this specification can also be practiced in a distributed computing environment where tasks are performed by remote processors connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0118] The various embodiments in this specification are described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other, and the key point of each embodiment is to illustrate the differences from other embodiments. In particular, for system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and for the relevant parts, reference can be made to the description of the method embodiments. In the description of this specification, the description referring to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the embodiments of this specification. In this specification, the schematic expression of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0119] The above are only the embodiments of the present application and are not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A method for defragmenting based on a master-slave database, characterized in that, it includes: Determine the master database and its corresponding first slave database and second slave database; When the master database is the database providing services externally; Trigger defragmentation; The first slave database starts defragmentation; If the first slave database completes defragmentation, the second slave database starts defragmentation; During the defragmentation of the second slave database, make the first slave database synchronize data from the master database; If the second slave database completes defragmentation, perform a master-slave switch between the master database and the first slave database; The master database starts defragmentation; After completing defragmentation, the master database synchronizes data with the first slave database after completing defragmentation.
2. A defragmentation device based on a master-slave database, characterized in that, it includes: A database determination module for determining the master database and its corresponding first slave database and second slave database; A first defragmentation module for triggering defragmentation; The first slave database starts defragmentation; If the first slave database completes defragmentation, the second slave database starts defragmentation; During the defragmentation of the second slave database, make the first slave database synchronize data from the master database; A database switching module for performing a master-slave switch between the master database and the first slave database if the second slave database completes defragmentation; A second defragmentation module for the master database to start defragmentation; After completing defragmentation, the master database synchronizes data with the first slave database after completing defragmentation.
3. A computer device, including a memory, a processor, and a computer program stored on the memory, characterized in that, When the computer program is run by the processor, it executes the instructions of the method according to claim 1.
4. A computer storage medium, on which a computer program is stored, characterized in that, When the computer program is run by the processor of a computer device, it executes the instructions of the method according to claim 1.
Citation Information
Patent Citations
Database operation method, system and device and medium
CN110362556A