Database upgrading method and device, electronic equipment and readable storage medium

By gradually upgrading the database in the master-slave database environment, we ensure that the main database is running normally, and the problem of service interruption during the database upgrade is solved, and the stability and operation and maintenance efficiency of the database are improved.

CN119718368APending Publication Date: 2025-03-28CHINA TELECOM CLOUD TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411754498.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

During the database upgrade process, the existing technology causes the database to be unable to provide services, affecting the access, storage and processing of data, resulting in low database stability.

Method used

By obtaining the status information of both in the master-slave database environment, determining whether the preset conditions are met, gradually upgrading the database to ensure that the master database always runs normally, and only upgrading the slave database, and then upgrading the master-slave switch is completed.

Benefits of technology

It realizes rolling upgrade of the database, identify and evaluate upgrade risks in real time, ensures data integrity and business continuity, and improves the stability and operation and maintenance efficiency of the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718368A_ABST
    Figure CN119718368A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a database upgrading method and device, electronic equipment and a readable storage medium. The method comprises the steps of obtaining first state information of a first database and a second database under the condition that the first database is a slave database and the second database is a master database; under the condition that the first state information meets a preset first condition, the first database is upgraded based on an update installation file; acquiring second state information of the first database and the second database; under the condition that the second state information meets a preset second condition, the upgraded first database is set as a master database, and the second database is set as a slave database; and under the condition that the first database is the master database and the second database is the slave database, upgrading the second database based on the update installation file. The stability of the database can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of data processing, and in particular relates to a database upgrading method, device, electronic equipment and readable storage medium. Background Art

[0002] Databases can store massive amounts of data in a centralized and orderly manner, which facilitates convenient data management and query, and avoids scattered data storage and loss. With the development of database technology, databases also need to be continuously upgraded and updated to provide users with more convenient and rich functions.

[0003] In the related art, when upgrading a database, it is necessary to manually stop the database from running in order to complete the upgrade.

[0004] However, in the related art, during the upgrade period, the database cannot provide services, which will affect normal business processes such as data access, storage and processing, resulting in low database stability. Summary of the invention

[0005] The present invention provides a database upgrading method, device, electronic device and readable storage medium to solve the problem of low stability of database in related technologies.

[0006] In a first aspect, the present invention provides a database upgrading method, comprising:

[0007] In a case where the first database is a slave database and the second database is a master database, first status information of the first database and the second database is acquired; the first status information indicates the running status of the first database and the second database before the first database is upgraded;

[0008] When the first status information meets a preset first condition, upgrading the first database based on an updated installation file;

[0009] Acquire second status information of the first database and the second database; the second status information indicates the running status of the first database and the second database after the first database is upgraded;

[0010] When the second status information meets a preset second condition, setting the upgraded first database as a master database and setting the second database as a slave database;

[0011] In a case where the first database is a master database and the second database is a slave database, the second database is upgraded based on the update installation file.

[0012] In a second aspect, the present invention provides a database upgrading device, comprising:

[0013] A first information module is used to obtain first status information of the first database and the second database when the first database is a slave database and the second database is a master database; the first status information indicates the running status of the first database and the second database before the first database is upgraded;

[0014] A first upgrading module, configured to upgrade the first database based on an updated installation file when the first status information meets a preset first condition;

[0015] A second information module is used to obtain second status information of the first database and the second database; the second status information indicates the operating status of the first database and the second database after the first database is upgraded;

[0016] a master-slave switching module, configured to set the upgraded first database as the master database and set the second database as the slave database when the second state information meets a preset second condition;

[0017] The second upgrade module is used to upgrade the second database based on the update installation file when the first database is a master database and the second database is a slave database.

[0018] In a third aspect, the present invention provides an electronic device comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the database upgrade method described in the first aspect when executing the program.

[0019] In a fourth aspect, the present invention provides a readable storage medium, when instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the database upgrade method described in the first aspect.

[0020] In summary, in the embodiment of the present invention, when the first database is a slave database and the second database is a master database, the first state information of the first database and the second database is obtained, when the first state information before the upgrade meets the first condition, the first database is upgraded based on the updated installation file, when the second state information after the upgrade meets the second condition, the upgraded first database is set as the master database, and the second database is set as the slave database, and when the second database is a slave database, the second database is upgraded based on the updated installation file. It is possible to first determine whether there is an environment suitable for upgrading the database based on the first state information, and upgrade the first database (slave database), and then continue to make environmental judgments based on the second state information. After completing the master-slave switching, the second database (slave database) is upgraded to achieve rolling upgrades of the first database and the second database, and it is possible to identify and evaluate upgrade risks in real time. When the upgrade conditions are met, only the slave database is always upgraded, and the master database is always in normal operation, minimizing the impact of the upgrade on the business, improving the stability of the database, ensuring data integrity and business continuity, greatly improving operation and maintenance efficiency and response speed, and being suitable for large-scale database systems. When facing a complex and large data environment, efficient and reliable upgrades without stopping business can also be achieved. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0022] Figure 1 is a step diagram of a database upgrade method provided by an embodiment of the present invention;

[0023] Figure 2 is a step diagram of another database upgrade method provided by an embodiment of the present invention;

[0024] Figure 3 is a schematic diagram of a database rolling upgrade architecture provided by an embodiment of the present invention;

[0025] Figure 4 is a flowchart of a database upgrade provided by an embodiment of the present invention;

[0026] Figure 5 is a flowchart of another database upgrade provided by an embodiment of the present invention;

[0027] Figure 6 is a structural diagram of a database upgrading device provided by an embodiment of the present invention;

[0028] Figure 7 It is a structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0030] The following is a further description of the database upgrade method of the present application in conjunction with the relevant drawings and embodiments:

[0031] Figure 1 1 is a flowchart of a method for upgrading a database provided by an embodiment of the present invention. Figure 1 , the method may include:

[0032] Step 101, when the first database is a slave database and the second database is a master database, first status information of the first database and the second database is obtained; the first status information indicates the running status of the first database and the second database before the first database is upgraded.

[0033] In an embodiment of the present invention, the first database and the second database may correspond to different servers respectively, the servers corresponding to the first database and the second database may serve as a node, and the steps of the database upgrade method may be executed by other servers other than the database server.

[0034] The first database can be a slave database, and the second database can be a master database. The master database is the source of data updates, and all write operations (such as inserting, updating, and deleting data) can be performed on the master database first. For example, in an e-commerce system, when a new order is generated, the insertion operation of the order information will be performed on the master database first.

[0035] The data update of the slave database is obtained by copying data from the master database. It is mainly used for read operations and may not accept direct write operations. For example, the database server used to query product information in an e-commerce system may be a slave database. When a user queries a product, data may be read from the slave database to reduce the reading pressure of the master database.

[0036] First state information of the first database and the second database is obtained, where the first state information is used to indicate the current running state of the first database (slave database) and the second database (master database) before the upgrade. The first state information may include the time delay between the first database and the second database, their respective database versions, their respective disk capacities, their respective database component state information, and other information.

[0037] The time delay refers to the process in which data is copied from the master database to the slave database. Due to factors such as network delay and replication mechanism, there may be a short delay, resulting in temporary inconsistency of data in the master and slave databases.

[0038] The database component may provide specific functions such as visualization, management, etc. The database component may be Oracle Real Application Clusters (Oracle RAC), Oracle Data Pump (ODP), Analysis Services, etc. The database component status information in the first status information may refer to information such as the CPU usage rate, memory usage, and whether an exception occurs.

[0039] Step 102: When the first status information meets a preset first condition, the first database is upgraded based on an updated installation file.

[0040] In an embodiment of the present invention, a judgment may be made as to whether the first condition is met with respect to the first state information, and the first conditions of different first state information may be different. For example, if the first state information is a database version, the first condition may include specific database version information, and when the database version information in the first state information is consistent with the database version information in the first condition, it is considered that the first condition is met; if the first state information is a disk capacity, the first condition may be "the disk capacity is greater than a specific threshold", and when the disk capacity in the first state information reaches the capacity corresponding to the specific threshold, it is considered that the first condition is met. The content of the first state information and the first condition is not specifically limited herein.

[0041] If the first state information meets the preset first condition, it can be considered that the current master-slave database is suitable for upgrading, and the first database can be upgraded based on the update installation file. The update installation file may include: library files, which provide basic support for database functions, such as implementation codes for functions such as data storage, index management, and transaction processing; main configuration files, which contain basic configuration parameters of the database system, such as the listening port of the database server, the selection of the storage engine, the setting of the cache size, etc.; log configuration files and other data.

[0042] Based on the updated installation file including the above data, the query optimizer, storage engine and other parts of the database can be updated to improve performance, fix bugs or add new functions. The database management interface, command line tools, etc. can be modified. The database configuration file can also be modified to adjust performance parameters, security settings, etc. The CPU, memory, storage and other resources of the database server can also be reallocated. The specific content of upgrading the database based on the updated installation file is not specifically limited here.

[0043] Step 103: Acquire second status information of the first database and the second database; the second status information indicates the operating status of the first database and the second database after the first database is upgraded.

[0044] In the embodiment of the present invention, after the first database as the slave database completes the upgrade, the state information of the first database and the second database, namely the second state information, is continuously obtained. The second state information may indicate the operation states of the first database and the second database after the first database is upgraded.

[0045] It is understandable that the second status information and the first status information may be similar, for example including similar information such as whether the master and slave databases have completed data synchronization, CPU usage, memory usage, disk capacity, etc., which will not be repeated here.

[0046] Step 104: When the second status information meets a preset second condition, the upgraded first database is set as a master database, and the second database is set as a slave database.

[0047] In the embodiment of the present invention, similar to determining whether the first state information meets the first condition, for the second state information, determining whether it meets the second condition, the specific process is not repeated here.

[0048] When the second state information meets the preset second condition, the master-slave switching is performed, that is, the upgraded first database is set as the master database, and the second database is set as the slave database. Since the first database has been upgraded, it can run as the master database to provide data services to users.

[0049] After the master-slave switch is completed, so that the first database is the master database and the second database is the slave database, the second database as the slave database is upgraded. Upgrading the slave database will not affect normal data services. Therefore, the second database can be upgraded based on the updated installation file, and the upgrade process will not be repeated.

[0050] It is understandable that after the first database and the second database are upgraded, the corresponding database components (such as XtraBackup) may be upgraded or installed overwritten to make the database components compatible with the new version of the database.

[0051] In summary, in the embodiment of the present invention, when the first database is a slave database and the second database is a master database, the first state information of the first database and the second database is obtained, when the first state information before the upgrade meets the first condition, the first database is upgraded based on the updated installation file, when the second state information after the upgrade meets the second condition, the upgraded first database is set as the master database, and the second database is set as the slave database, and when the second database is a slave database, the second database is upgraded based on the updated installation file. It is possible to first determine whether there is an environment suitable for upgrading the database based on the first state information, and upgrade the first database (slave database), and then continue to make environmental judgments based on the second state information. After completing the master-slave switching, the second database (slave database) is upgraded to achieve rolling upgrades of the first database and the second database, and it is possible to identify and evaluate upgrade risks in real time. When the upgrade conditions are met, only the slave database is always upgraded, and the master database is always running normally, which improves the stability of the database, can ensure data integrity and business continuity, greatly improve operation and maintenance efficiency and response speed, and is suitable for large-scale database systems. When facing a complex and large data environment, it is also possible to achieve efficient and reliable database upgrades that are automatically executed unattended during business off-peak periods.

[0052] Figure 2 A step diagram of another database upgrade method provided in an embodiment of the present application:

[0053] Step 201, when the first database is a slave database and the second database is a master database, first status information of the first database and the second database is obtained; the first status information indicates the running status of the first database and the second database before the first database is upgraded;

[0054] Step 202: when the first status information meets a preset first condition, the first database is upgraded based on an updated installation file;

[0055] Step 203, obtaining second status information of the first database and the second database; the second status information indicates the operating status of the first database and the second database after the first database is upgraded;

[0056] Step 204: if the second state information meets a preset second condition, setting the upgraded first database as a master database and setting the second database as a slave database;

[0057] Step 205: When the first database is a master database and the second database is a slave database, the second database is upgraded based on the update installation file.

[0058] For details of the above steps 201 to 205, please refer to Figure 1 The embodiments are not described in detail here.

[0059] Optionally, before the step of upgrading the second database based on the updated installation file 205, the method further includes:

[0060] Step A1, determining the disaster recovery configuration of the second database; the disaster recovery configuration includes a consistent disaster recovery configuration and an inconsistent disaster recovery configuration;

[0061] Step A2: when the disaster recovery configuration is the consistent disaster recovery configuration, modify the disaster recovery configuration to the inconsistent disaster recovery configuration.

[0062] In the embodiment of the present invention, the consistent disaster recovery configuration means that the data of the master and slave databases maintain strict consistency at any time, and when performing data replication and synchronization, it ensures that all transactions and operations are accurately replicated to the slave database in order. The inconsistent disaster recovery configuration has relatively loose requirements on data consistency, and allows temporary data inconsistency to exist to a certain extent.

[0063] To achieve a specific disaster recovery configuration, you can set the parameters of synchronous replication in the storage management interface, including the source volume (primary database), target volume (slave database), replication time interval, replication priority, etc. You can also set relevant parameters in the configuration file to achieve consistent or inconsistent disaster recovery configuration. How to achieve different disaster recovery configurations is not specifically limited here.

[0064] Relevant disaster recovery configuration parameters can be queried through the database management system. For example, the current disaster recovery configuration can be determined based on parameters such as the source volume and target volume of the replication, the replication time interval, and the replication priority.

[0065] When the disaster recovery configuration is consistent, change the disaster recovery configuration to inconsistent. As described above, the data of the master and slave databases in the consistent disaster recovery configuration needs to maintain strict consistency, which means that all transactions and operations must be replicated in order, which may prevent the update from being performed normally. Therefore, the disaster recovery configuration needs to be changed to inconsistent to avoid strict transactions and replication processes affecting the upgrade.

[0066] By implementing an embodiment of the present invention, by determining the disaster recovery configuration of the second database, and when the disaster recovery configuration is a consistent disaster recovery configuration, modifying the disaster recovery configuration to an inconsistent disaster recovery configuration, the impact of the consistent disaster recovery configuration on the upgrade of the second database can be avoided, thereby improving the efficiency of the database upgrade.

[0067] Optionally, after the step 205 of upgrading the second database based on the update installation file, the method further includes:

[0068] Step B1, determining first available zone information corresponding to the first database, and determining second available zone information corresponding to the second database; wherein the available zone information is used to indicate the physical area where the database is located;

[0069] Step B2: When there is a difference between the first availability zone information and the second availability zone information, reset the upgraded second database as the master database, and reset the second database as the slave database.

[0070] In the embodiment of the present invention, the availability zone of the database is an independent physical area where the database is located, and each availability zone has independent power, network and other infrastructure. The master database and the slave database may be in the same availability zone or not, and can be set according to specific needs.

[0071] For example, if the business requires extremely high availability, you can deploy databases in different availability zones. For example, in order to avoid service interruptions due to failures in a certain availability zone (such as power outages, network failures, etc.), you can place the master database in one availability zone and the slave database in another availability zone. When problems occur in the master availability zone, you can quickly switch to the slave availability zone to continue providing services. If the data transmission costs between different availability zones are considered, for example, data transmission across availability zones may incur higher costs, you can deploy the master and slave databases in the same availability zone. In addition, distributing databases in availability zones close to users can reduce data access latency. For example, for a global company, you can choose appropriate availability zones in Asia, Europe, and America to deploy databases to meet the low latency requirements of users in different regions.

[0072] You can view detailed information about a database through the database management console, which may include the availability zone where the database is located. Some databases may be associated with labels or metadata about availability zone information, which can be queried to determine the availability zone to which the database belongs. For example, you can use a command line tool or interface to query the database metadata, and the query results may include the "available-zone" field to indicate the availability zone. You can also obtain location-related information about the database based on specific commands or functions. For example, the "get_instance_location()" function can return an availability zone information value.

[0073] The available zone to which the first data zone belongs can be determined through the first available zone information of the first database, and the available zone to which the first data zone belongs can be determined through the second available zone information of the second database.

[0074] When the first availability zone information and the second availability zone information are consistent, it means that the first database and the second database are in the same availability zone. If the two are in the same availability zone, for users, whether the first database or the second database is the primary database, it will not cause obvious difference to the user. Therefore, there is no need to reset the upgraded second database as the primary database and reset the second database as the slave database.

[0075] If there is a difference between the first availability zone information and the second availability zone information, it means that the first database and the second database are not in the same availability zone. Before the master-slave switch, for a specific user, the second database, as the master database, can have a better user experience, such as low data operation latency. After the master-slave switch, since the first database and the second database, which was originally the master database, are no longer in the same availability zone, the first database, which is now the master database, is in another availability zone, which can easily lead to a poor user experience. Therefore, it is necessary to perform another master-slave switch, that is: reset the upgraded second database as the master database, and reset the second database as the slave database.

[0076] After the second database is upgraded based on the updated installation file, the first availability zone information corresponding to the first database is determined, and the second availability zone information corresponding to the second database is determined. If there is a difference between the first availability zone information and the second availability zone information, the upgraded second database is reset as the master database, and the second database is reset as the slave database. This can avoid changes in the availability zone where the master database is located when implementing a rolling upgrade without stopping business through master-slave switching, thereby avoiding the problem of poor user experience and improving the stability of the database.

[0077] Optionally, the step of upgrading the first database based on updating the installation file includes:

[0078] Acquire the existing configuration data in the first database, and add the configuration data to the update installation file;

[0079] Controlling the first database to stop running, and storing the update installation file in a preset directory of a server corresponding to the first database;

[0080] The second database is controlled to start running, so that the upgrade program running on the server upgrades the first database based on the update installation file.

[0081] In an embodiment of the present invention, the update installation file may refer to an installation package of a database management system, such as an installation package of a MySQL database management system, an Oracle database management system, and other database management systems. The update installation file may first be uploaded to a designated directory of a server where the database to be upgraded is located, and then decompressed for subsequent use.

[0082] Even if you upgrade the database version, you need to retain the original database configuration data. The configuration data of the original database instance may contain parameter settings optimized for specific application scenarios. For example, the parameter "innodb_buffer_pool_size" affects the memory size used by the InnoDB storage engine to cache data and indexes. These parameters may have been adjusted to appropriate values ​​in the existing configuration data based on the database load, data volume, etc. By adding the configuration data to the update installation file, you can continue to use the optimized parameters, avoid the trouble of re-adjustment, and make the upgraded database have similar performance.

[0083] The configuration data may also include information about user permissions, authorized users, and what permissions each user has (read, write, manage, etc.). By adding the configuration data to the update installation file, the same user permission system can be quickly rebuilt in the newly upgraded database to ensure consistency in security and access control. The configuration data may also include more other information, which is not specifically limited here.

[0084] In addition to the original configuration data, you can also add upgrade parameters to the configuration data. The upgrade parameters can include the following:

[0085] [upgrade]

[0086] upgrade-check=ON

[0087] upgrade-user=upgradeuser

[0088] upgrade-password="XXXXX"

[0089] Among them, the upgrade parameters may include "ON" or 1 to trigger subsequent upgrades, may include the name of the current upgraded user "upgradeuser", and the upgraded password "XXXXX", and may also include other or more parameters, and the specific content of the upgrade parameters is not specifically limited here.

[0090] It is understandable that the configuration data and upgrade parameters such as passwords that existed before this upgrade can be deleted after this upgrade to make the new configuration effective.

[0091] For the first database that needs to be upgraded, the instance of the first database and related proxy services need to be shut down in sequence to ensure that the first database is in a shutdown state. The update installation file is stored in the preset directory of the server corresponding to the first database, and then the database management system can be started to trigger the upgrade program running on the server. The upgrade program upgrades the first database based on the update installation file. After the upgrade is completed, the instance and service of the first database can be reopened.

[0092] Optionally, the update installation file carries target version information; the method further includes:

[0093] Respectively obtain initial installation files of the first database and the second database;

[0094] When the target database is upgraded, obtaining current version information of the target database; the target database includes at least one of the first database and the second database;

[0095] In the case where there is a difference between the current version information and the target version information, the target database is updated based on the initial installation file to complete the rollback.

[0096] In an embodiment of the present invention, the update installation file may carry target version information, such as 1.1.001, 2.3.401, etc. Before the first database and the second database are updated, it is necessary to obtain the current initial installation files of the first database and the second database respectively. The initial installation files may be stored in other servers for safe backup. The current initial installation files of the first database and the second database may be the same or different.

[0097] When the target database is upgraded, the current version information of the target database is obtained, wherein the target database may be at least one of the first database and the second database. The current version information is compared with the target version information of the update installation file. Generally speaking, when the database is upgraded normally, the current version information and the target version information are consistent.

[0098] If there is a difference between the current version information and the target version information, it means that an error occurred during the upgrade and the upgrade was not performed correctly based on the updated installation file. You need to re-update the target database based on the initial installation file corresponding to the target database to complete the rollback and restore the target database to the state before the upgrade. In addition, an alarm message can be issued to inform the user that an upgrade problem has occurred.

[0099] It is understandable that after the upgrade is successful, you can also back up the current update installation file (after the upgrade is successful, it is also the initial installation file relative to the next upgrade) and back up related configuration data to prevent the database from becoming unavailable after restoring the old version of the initial installation file.

[0100] In the implementation of the embodiment of the present invention, the initial installation files of the first database and the second database are obtained respectively, and when the target database is upgraded, the current version information of the target database is obtained. When there is a difference between the current version information and the target version information, the target database is updated based on the initial installation file to complete the rollback. It is possible to determine whether the upgrade is completed normally by comparing the version information, and trigger a rollback if there is a problem, so that the target database is restored to the state before the upgrade, thereby ensuring that the target database can still operate normally with the version before the upgrade, thereby improving the stability of the database and the security of the upgrade.

[0101] Optionally, the first condition includes multiple sub-conditions; the first state information includes multiple sub-state information; and the method further includes:

[0102] When any sub-state information in the first state information does not meet the corresponding sub-condition, continuously acquiring the first state information of the first database and the second database based on a preset time interval;

[0103] Each time the first state information is acquired, the compliance of each sub-state information with the corresponding sub-condition is determined until each sub-state information complies with the corresponding sub-condition.

[0104] In an embodiment of the present invention, the first status information of the first database and the second database may include a large number of various types of information, such as the CPU usage of different components in different databases, memory occupancy, time delay between master and slave databases, disk capacity of different databases, and other sub-status information mentioned above.

[0105] Different sub-conditions may be configured for different sub-status information. For example, a corresponding delay threshold condition may be set for time delay, and the same or different capacity threshold conditions may be set for disk capacities corresponding to different databases, etc., which are not specifically limited here.

[0106] It is necessary to determine whether each sub-state information in the first state information meets the corresponding sub-condition. If each sub-state information meets the corresponding sub-condition, it can be considered that the first state information meets the first condition, and subsequent upgrade operations can be performed.

[0107] If there is any sub-state information that does not meet the corresponding sub-condition, the next first state information can be continuously obtained based on a preset time interval, and a judgment can be made whether it meets the condition until each sub-state information meets the corresponding sub-condition.

[0108] By implementing an embodiment of the present invention, when any sub-state information in the first state information does not meet the corresponding sub-condition, the first state information of the first database and the second database is continuously obtained based on a preset time interval, and each time the first state information is obtained, the compliance of each sub-state information and the corresponding sub-condition is determined until each sub-state information meets the corresponding sub-condition. This enables detailed real-time identification and upgrade risk assessment of the database environment, thereby improving the security of database upgrades and the stability of the database.

[0109] Optionally, the step of setting the upgraded first database as a master database and setting the second database as a slave database includes:

[0110] Deleting the master-slave information of the first database, closing the replication thread of the first database, and setting the first database to a read-write mode to set the first database as a master database;

[0111] The master-slave information of the second database is configured, the replication thread of the second database is started, and the first database is set to read-only mode to set the second database as a slave database.

[0112] In the embodiment of the present invention, when performing the master-slave switching, for the first database which is currently the slave database, the master-slave information of the first database can be deleted, the replication thread of the first database can be closed, and the first database can be set to the read-write mode. At the same time, the master-slave information of the second database can be configured, the replication thread of the second database can be opened, and the first database can be set to the read-only mode to set the second database as the slave database.

[0113] In addition, it may also include checking whether the data of the master and slave databases are consistent, setting the master and slave databases to read-only, cutting off the traffic of the application to the original master database, and switching the traffic of the application to the new master database. Other specific operations when performing the master-slave switch are not specifically limited here.

[0114] Figure 3 is a schematic diagram of a database rolling upgrade architecture provided by an embodiment of the present invention; Figure 3 The control server 301 is included. The control server 301 runs a control service for controlling the version upgrade process of the database in other servers. The control server 301 includes zookeeper (ZK) and keeper. ZK is a distributed coordination service for ensuring metadata consistency and high-availability component master selection function. Keeper is a high-availability component for scheduling tasks and sovereignty switching scheduling. Figure 3 The system also includes database server 302 and database server 303 that need to be upgraded, which respectively include a gateway database management system mysql and an agent tool. Database server 302 and database server 303 can be database servers in a virtual private cloud (VPC). VPC can provide users with isolated network environments, customized network configurations and other functions.

[0115] Among them, the control server 301 obtains the status information of the database server 302 and the database server 303, and checks the status information to determine whether it meets the upgrade conditions; the control server 301 sends the update installation file to the database server 302 and the database server 303 for upgrading, and performs operations such as master-slave switching. For detailed operations, refer to the above Figure 1-2 The contents of the embodiments are not described in detail.

[0116] Figure 4 is a flowchart of a database upgrade provided by an embodiment of the present invention;

[0117] Step 401, start; step 402, detect whether the database is suitable for upgrading; step 403, if not suitable, output the result of detection as unsuitable; step 404, if suitable, upgrade the database (two upgrade methods may be included: 1, upgrade immediately; 2, upgrade during the maintenance time period, such as upgrading during the low business peak at night; step 405, end.

[0118] Figure 5 is a flowchart of another database upgrade provided by an embodiment of the present invention;

[0119] Step 501, start; step 502, check whether the database is suitable for upgrading; step 503, if suitable, determine whether it is consistent disaster recovery; step 504, if it is consistent disaster recovery, change it to inconsistent disaster recovery; step 505, if it is not consistent disaster recovery, upgrade the slave database; step 506, master-slave switching; step 507, upgrade the master database; step 508, whether the available zones are different; step 509, if different, switch the master-slave again; step 510, if the same, end.

[0120] Figure 6 60 is a structural diagram of a database upgrade device provided by an embodiment of the present invention. The device 60 may include:

[0121] A first determination module 601 is used for a first information module, and is used to obtain first status information of the first database and the second database when the first database is a slave database and the second database is a master database; the first status information indicates the running status of the first database and the second database before the first database is upgraded;

[0122] A first upgrading module 602, configured to upgrade the first database based on an updated installation file when the first status information meets a preset first condition;

[0123] The second information module 603 is used to obtain second status information of the first database and the second database; the second status information indicates the operating status of the first database and the second database after the first database is upgraded;

[0124] A master-slave switching module 604, configured to set the upgraded first database as the master database and set the second database as the slave database when the second state information meets a preset second condition;

[0125] The second upgrade module 605 is used to upgrade the second database based on the update installation file when the first database is a master database and the second database is a slave database.

[0126] Optionally, the device further comprises:

[0127] An availability zone module, used to determine first availability zone information corresponding to the first database, and to determine second availability zone information corresponding to the second database; wherein the availability zone information is used to indicate the physical area where the database is located;

[0128] A re-switching module is used to reset the upgraded second database as the master database and reset the second database as the slave database when there is a difference between the first availability zone information and the second availability zone information.

[0129] Optional, first upgrade module, including:

[0130] The original configuration submodule is used to obtain the existing configuration data in the first database and add the configuration data to the update installation file;

[0131] A file directory submodule, used to control the first database to stop running and store the update installation file in a preset directory of the server corresponding to the first database;

[0132] The trigger update submodule is used to control the second database to start running, so that the upgrade program running on the server upgrades the first database based on the update installation file.

[0133] Optionally, the device further comprises:

[0134] A disaster recovery configuration module, used to determine the disaster recovery configuration of the second database; the disaster recovery configuration includes a consistent disaster recovery configuration and an inconsistent disaster recovery configuration;

[0135] The disaster recovery modification module is used to modify the disaster recovery configuration to the inconsistency disaster recovery configuration when the disaster recovery configuration is the consistency disaster recovery configuration.

[0136] Optionally, the update installation file carries target version information; the device further includes:

[0137] An installation backup module is used to obtain initial installation files of the first database and the second database respectively;

[0138] A version acquisition module, used to acquire the current version information of the target database when the target database has completed upgrading; the target database includes at least one of the first database and the second database;

[0139] The version checking module is used to update the target database based on the initial installation file to complete the rollback when there is a difference between the current version information and the target version information.

[0140] Optionally, the first condition includes multiple sub-conditions; the first state information includes multiple sub-state information; and the device further includes:

[0141] a cyclic acquisition module, configured to continuously acquire the first state information of the first database and the second database based on a preset time interval when any sub-state information in the first state information does not meet a corresponding sub-condition;

[0142] The cyclic verification module is used to determine the compliance of each sub-state information with the corresponding sub-condition each time the first state information is obtained, until each sub-state information complies with the corresponding sub-condition.

[0143] Optional, master-slave switching module, including:

[0144] a first setting submodule, configured to delete the master-slave information of the first database, close the replication thread of the first database, and set the first database to a read-write mode, so as to set the first database as a master database;

[0145] The second setting submodule is used to configure the master-slave information of the second database, start the replication thread of the second database, and set the first database to read-only mode to set the second database as a slave database.

[0146] In summary, in the embodiment of the present invention, when the first database is a slave database and the second database is a master database, the first state information of the first database and the second database is obtained, when the first state information before the upgrade meets the first condition, the first database is upgraded based on the updated installation file, when the second state information after the upgrade meets the second condition, the upgraded first database is set as the master database, and the second database is set as the slave database, and when the second database is a slave database, the second database is upgraded based on the updated installation file. It is possible to first determine whether there is an environment suitable for upgrading the database based on the first state information, and upgrade the first database (slave database), and then continue to make environmental judgments based on the second state information. After completing the master-slave switching, the second database (slave database) is upgraded to achieve rolling upgrades of the first database and the second database, and it is possible to identify and evaluate upgrade risks in real time. When the upgrade conditions are met, only the slave database is always upgraded, and the master database is always in normal operation, minimizing the impact of the upgrade on the business, improving the stability of the database, ensuring data integrity and business continuity, greatly improving operation and maintenance efficiency and response speed, and being suitable for large-scale database systems. When facing a complex and large data environment, efficient and reliable upgrades without stopping business can also be achieved.

[0147] The present invention also provides an electronic device, see Figure 7 , including: a processor 1401, a memory 1402, and a computer program 14021 stored in the memory and executable on the processor, and when the processor executes the program, the database upgrade method of the aforementioned embodiment is implemented.

[0148] The present invention also provides a readable storage medium. When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the database upgrading method of the aforementioned embodiment.

[0149] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0150] It should be noted that the various information and data obtained in the embodiments of the present invention are all obtained with the authorization of the information / data holder.

[0151] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages ​​can be utilized to realize the content of the present invention described herein, and the description of the above specific languages ​​is for disclosing the best mode of the present invention.

[0152] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0153] Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.

[0154] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

[0155] The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components in the sorting device according to the present invention. The present invention may also be implemented as a device or apparatus program for executing part or all of the methods described herein. Such a program for implementing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0156] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.

[0157] The user information (including but not limited to the user's device information, user personal information, etc.) and related data involved in the present invention are all information authorized by the user or by all parties.

[0158] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0159] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

[0160] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A database upgrade method, characterized in that: include: When the first database is a slave database and the second database is a master database, obtaining first status information of the first database and the second database; The first status information indicates the operating status of the first database and the second database before the first database is upgraded; When the first status information meets a preset first condition, upgrading the first database based on an updated installation file; Acquire second status information of the first database and the second database; The second status information indicates the operating status of the first database and the second database after the first database is upgraded; When the second status information meets a preset second condition, setting the upgraded first database as a master database and setting the second database as a slave database; In a case where the first database is a master database and the second database is a slave database, the second database is upgraded based on the update installation file.

2. The method according to claim 1, characterized in that After the step of upgrading the second database based on the update installation file, the method further includes: Determine first available zone information corresponding to the first database, and determine second available zone information corresponding to the second database; wherein the available zone information is used to indicate the physical area where the database is located; In the case where there is a difference between the first availability zone information and the second availability zone information, the upgraded second database is reset as the master database, and the second database is reset as the slave database.

3. The method according to claim 1, characterized in that The step of upgrading the first database based on the updated installation file comprises: Acquire the existing configuration data in the first database, and add the configuration data to the update installation file; Controlling the first database to stop running, and storing the update installation file in a preset directory of a server corresponding to the first database; The second database is controlled to start running, so that the upgrade program running on the server upgrades the first database based on the update installation file.

4. The method according to claim 1, characterized in that: Before the step of upgrading the second database based on the updated installation file, the method further includes: Determine a disaster recovery configuration of the second database; the disaster recovery configuration includes a consistent disaster recovery configuration and an inconsistent disaster recovery configuration; When the disaster recovery configuration is the consistent disaster recovery configuration, the disaster recovery configuration is modified to the inconsistent disaster recovery configuration.

5. The method according to claim 1, characterized in that The update installation file carries target version information; the method further includes: Respectively obtain initial installation files of the first database and the second database; When the target database is upgraded, obtaining current version information of the target database; the target database includes at least one of the first database and the second database; In the case where there is a difference between the current version information and the target version information, the target database is updated based on the initial installation file to complete the rollback.

6. The method according to claim 1, characterized in that The first condition includes a plurality of sub-conditions; the first state information includes a plurality of sub-state information; the method further includes: When any sub-state information in the first state information does not meet the corresponding sub-condition, continuously acquiring the first state information of the first database and the second database based on a preset time interval; Each time the first state information is acquired, the compliance of each sub-state information with the corresponding sub-condition is determined until each sub-state information complies with the corresponding sub-condition.

7. The method according to claim 1, characterized in that The step of setting the upgraded first database as a master database and setting the second database as a slave database comprises: Deleting the master-slave information of the first database, closing the replication thread of the first database, and setting the first database to a read-write mode to set the first database as a master database; The master-slave information of the second database is configured, the replication thread of the second database is started, and the first database is set to read-only mode to set the second database as a slave database.

8. A database upgrade device, characterized in that: include: A first information module is used to obtain first status information of the first database and the second database when the first database is a slave database and the second database is a master database; The first status information indicates the operating status of the first database and the second database before the first database is upgraded; A first upgrading module, configured to upgrade the first database based on an updated installation file when the first status information meets a preset first condition; A second information module, used to obtain second status information of the first database and the second database; The second status information indicates the operating status of the first database and the second database after the first database is upgraded; a master-slave switching module, configured to set the upgraded first database as the master database and set the second database as the slave database when the second state information meets a preset second condition; The second upgrade module is used to upgrade the second database based on the update installation file when the first database is a master database and the second database is a slave database.

9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.

10. A readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any one of the methods described in claims 1-7.

Citation Information

Patent Citations

  • Database cluster upgrading method and device, electronic equipment and storage medium

    CN115269544A

  • Method and device for upgrading shared storage cluster of database all-in-one machine

    CN115562811A

  • Database cluster main node switching method and system and management and control platform

    CN117271227A

  • Database management system upgrading and degrading method and device, equipment and medium

    CN118519987A

  • Failover of database sessions to a logical replica database

    US20240126785A1