CN114676118B - Database switching method, device, equipment and storage medium - Google Patents

Database switching method, device, equipment and storage medium Download PDF

Info

Publication number
CN114676118B
CN114676118B CN202210595928.3A CN202210595928A CN114676118B CN 114676118 B CN114676118 B CN 114676118B CN 202210595928 A CN202210595928 A CN 202210595928A CN 114676118 B CN114676118 B CN 114676118B
Authority
CN
China
Prior art keywords
database
access
service
configuration
standby
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210595928.3A
Other languages
Chinese (zh)
Other versions
CN114676118A (en
Inventor
程方全
周波
代青松
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Clerware Technology Co ltd
Original Assignee
Shenzhen Clerware Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Clerware Technology Co ltd filed Critical Shenzhen Clerware Technology Co ltd
Priority to CN202210595928.3A priority Critical patent/CN114676118B/en
Publication of CN114676118A publication Critical patent/CN114676118A/en
Application granted granted Critical
Publication of CN114676118B publication Critical patent/CN114676118B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • G06F16/273Asynchronous replication or reconciliation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0663Performing the actions predefined by failover planning, e.g. switching to standby network elements
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Abstract

The invention belongs to the technical field of computers, and discloses a database switching method, a database switching device and a database switching equipment and a storage medium. When the service abnormality of the main database is detected, the access IP configuration information in the main database is read; shutting down business services and access configuration services in the main database; and when the shutdown is completed, performing access IP configuration on the standby database according to the access IP configuration information so as to switch the service access of the main database to the standby database. When the service of the main database is abnormal, the service of the main database is directly stopped, and the access IP configuration is carried out on the standby database according to the access IP configuration information in the main database, so that the access request of the service system points to the standby database, the switching of the databases is completed while the IP address is avoided being contended, the whole realization is simple and reliable without carrying out complex configuration and operation flow.

Description

Database switching method, device, equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a database switching method, apparatus, device, and storage medium.
Background
At present, when application level service disaster tolerance is performed on a cluster database such as Oracle RAC (not only Oracle RAC but also a cluster database of dreams), a common method is to perform disaster tolerance through Oracle Data Guard and Oracle Golden Gate. However, no matter using Oracle Data Guard or Oracle Golden Gate, when switching or back-switching the service, a lot of manual operations and configurations are needed, which is difficult, error-prone, difficult to use, poor in use experience, difficult for a database administrator with a slightly weak level to operate smoothly, and greatly affects the continuity of the service.
The above is only for the purpose of assisting understanding of the technical aspects of the present invention, and does not represent an admission that the above is prior art.
Disclosure of Invention
The invention mainly aims to provide a database switching method, a database switching device and a database switching storage medium, and aims to solve the technical problems that in the prior art, when a database is switched in service or switched back, operation is complex and realization is difficult.
In order to achieve the above object, the present invention provides a database switching method, including the following steps:
when the service abnormality of a main database is detected, reading access IP configuration information in the main database;
shutting down business services and access configuration services in the main database;
and when the shutdown is completed, performing access IP configuration on the standby database according to the access IP configuration information so as to switch the service access of the main database to the standby database.
Optionally, after the step of performing access IP configuration on the standby database according to the access IP configuration information to switch the service access of the primary database to the standby database when the shutdown is completed, the method further includes:
restarting the business service of the main database when the repair of the main database is finished, setting a temporary access IP in the main database, and starting a first type access configuration service;
synchronizing data in the standby database to the primary database based on the temporary access IP;
when the synchronization is completed, deleting the access IP configuration in the standby database, and performing the access IP configuration on the main database according to the access IP configuration information;
and when the access IP configuration is completed, starting a second type access configuration service in the main database to switch service access back to the main database.
Optionally, the restarting the service of the master database when the master database is repaired, setting a temporary access IP in the master database, and starting a first type access configuration service includes:
modifying the monitoring IP address in the master database into a preset IP address when the master database is repaired;
restarting the business service of the master database when the modification is completed;
and if the service is restarted, setting a temporary access IP in the master database, and starting a first type access configuration service of the master database.
Optionally, the restarting the service of the master database when the master database is repaired, setting a temporary access IP in the master database, and starting a first type access configuration service includes:
restarting the business service of the master database when the master database is repaired;
if the service is restarted, reading an access configuration file in the master database;
detecting whether target type configuration exists in the access configuration file;
if so, removing the target type configuration from the access configuration file;
upon completion of the removal, writing a temporary access IP into the access profile and initiating a first type of access profile service of the master database.
Optionally, the step of deleting the access IP configuration in the standby database and performing the access IP configuration on the primary database according to the access IP configuration information when the synchronization is completed includes:
when the synchronization is completed, deleting the access IP configuration in the standby database, and generating first type configuration information and second type configuration information according to the access IP configuration information;
writing the first type configuration information and the second type configuration information into an access configuration file of the main database to realize access IP configuration of the main database;
the access IP is validated by the method of configuring the operating system IP address.
Optionally, before the step of reading the access IP configuration information in the master database when detecting a service anomaly of the master database, the method further includes:
modifying the monitored IP address in the standby database into a preset IP address;
if the modification is completed, restarting the standby database;
and when the restarting of the standby database is finished, synchronizing the data in the main database to the standby database through a preset synchronization interface.
Optionally, the step of modifying the monitored IP address in the backup database to a preset IP address includes:
generating a file deleting instruction according to a preset file path;
executing the file deleting instruction, and deleting the monitoring configuration file in the standby database;
when the deletion is finished, a homonymous configuration file with the same name as the monitoring configuration file is created in the directory of the monitoring configuration file;
and generating monitoring configuration information according to a preset IP address, and writing the monitoring configuration information into the same-name configuration file so as to modify the monitoring IP address in the standby database into the preset IP address.
In addition, in order to achieve the above object, the present invention further provides a database switching apparatus, including the following modules:
the data acquisition module is used for reading access IP configuration information in the main database when the service abnormality of the main database is detected;
the service management module is used for shutting down the business service and the access configuration service in the main database;
and the service switching module is used for carrying out access IP configuration on the standby database according to the access IP configuration information when the shutdown is finished so as to switch the service access of the main database to the standby database.
In addition, to achieve the above object, the present invention further provides a database switching apparatus, including: a processor, a memory and a database switching program stored on the memory and operable on the processor, the database switching program when executed by the processor implementing the steps of the database switching method as described above.
In addition, in order to achieve the above object, the present invention further provides a computer-readable storage medium, on which a database switching program is stored, and the database switching program, when executed, implements the steps of the database switching method as described above.
When the service abnormality of the main database is detected, the access IP configuration information in the main database is read; shutting down business services and access configuration services in the main database; and when the shutdown is completed, performing access IP configuration on the standby database according to the access IP configuration information so as to switch the service access of the main database to the standby database. When the service of the main database is abnormal, the service of the main database is directly stopped, and the access IP configuration is carried out on the standby database according to the access IP configuration information in the main database, so that the access request of the service system points to the standby database, the switching of the databases is completed while the IP address is avoided being contended, the whole realization is simple and reliable without carrying out complex configuration and operation flow.
Drawings
Fig. 1 is a schematic structural diagram of an electronic device in a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a database switching method according to a first embodiment of the present invention;
FIG. 3 is a flowchart illustrating a database switching method according to a second embodiment of the present invention;
FIG. 4 is a block diagram of a database switching apparatus according to a first embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a schematic structural diagram of a database switching device in a hardware operating environment according to an embodiment of the present invention.
As shown in fig. 1, the electronic device may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a Wireless interface (e.g., a Wireless-Fidelity (WI-FI) interface). The Memory 1005 may be a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as a disk Memory. The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration shown in fig. 1 does not constitute a limitation of the electronic device and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a storage medium, may include therein an operating system, a network communication module, a user interface module, and a database switching program.
In the electronic apparatus shown in fig. 1, the network interface 1004 is mainly used for data communication with a network server; the user interface 1003 is mainly used for data interaction with a user; the processor 1001 and the memory 1005 of the electronic device according to the present invention may be provided in a database switching device, and the electronic device calls the database switching program stored in the memory 1005 through the processor 1001 and executes the database switching method according to the embodiment of the present invention.
An embodiment of the present invention provides a database switching method, and referring to fig. 2, fig. 2 is a schematic flowchart of a first embodiment of a database switching method according to the present invention.
In this embodiment, the database switching method includes the following steps:
step S10: and when the service abnormality of the main database is detected, reading the access IP configuration information in the main database.
It should be noted that the execution main body of this embodiment may be the database switching device, and the database switching device may be an electronic device such as a personal computer, a server, and the like, or may be other devices that can achieve the same or similar functions.
It should be noted that the master database may be a cluster database (e.g., Oracle database), and the access IP configuration information may include VIP configuration and SCAN IP configuration of the cluster database. The VIP can be a Virtual IP address of a cluster database (such as an Oracle database), each node in the cluster has one, an application program can access database services through the IP address, and when a host corresponding to the IP fails, cluster software of the database cluster can shift the IP address to other hosts of the cluster, so that the services of the database can be normally accessed. The function of the SCAN IP (Single Client Access Name IP) is equal to that of the VIP, load balance can be realized when the database service of the cluster database is accessed through the SCAN IP, only part of versions of the cluster database support the SCAN IP, the early versions do not support the SCAN IP, and the SCAN IP is also managed by cluster software of the cluster database.
In a specific implementation, the reading of the access IP configuration information in the master database may be to obtain VIP configurations of each node in the master database and SCAN IP configurations in the master database, and combine the read VIP configurations and SCAN IP configurations into the access IP configuration information. Since the master database may fail and cannot be normally accessed, the relevant configuration file may be directly obtained from the server where the master database is located (of course, the configuration file may also be obtained in advance before the master database fails), and the access IP configuration information is extracted from the configuration file.
In actual use, when a fault of the main database is detected or the start of disaster tolerance drilling is detected, it can be determined that the service abnormality of the main database is detected.
Further, the time for switching the subsequent service is shortened, and the continuity of the service is ensured, before the step S10 in this embodiment, the method may further include:
modifying the monitored IP address in the standby database into a preset IP address;
if the modification is completed, restarting the standby database;
and when the restarting of the standby database is finished, synchronizing the data in the main database to the standby database through a preset synchronization interface.
It should be noted that the preset IP address may be "0.0.0.0", and after the monitoring address is set, the application program may access the database service through any IP address of the host.
It should be noted that, in a normal case, the service of the database only listens to a specific IP address, and if the host IP address of the device library is 172.16.1.222, the backup database only listens to 172.16.1.222 this IP address by default. In this case, even if both SCAN IP and VIP are configured on the host of the standby database, the service system cannot access the service of the standby database through SCAN IP and VIP. In order to ensure that a service system can access services of a standby database through SCAN IP and VIP after service switching, a monitoring IP address of the standby database is modified and the standby database is restarted before data synchronization data of a main database is sent to the standby database, so that the standby database monitors the IP address of 0.0.0.0.0, then data in the main database is synchronized into the standby database through a preset synchronization interface, and data in the standby database is synchronized with the main database.
In a specific implementation, since directly modifying a configuration file for different scenarios and databases of different versions often encounters compatibility problems, in order to complete configuration simply and quickly, the step of modifying a monitored IP address in a standby database to a preset IP address may include:
generating a file deleting instruction according to a preset file path;
executing the file deleting instruction, and deleting the monitoring configuration file in the standby database;
when the deletion is finished, a homonymous configuration file with the same name as the monitoring configuration file is created in a directory of the monitoring configuration file;
and generating monitoring configuration information according to a preset IP address, and writing the monitoring configuration information into the same-name configuration file so as to modify the monitoring IP address in the standby database into the preset IP address.
It should be noted that the preset file path may be a path where the monitoring configuration file is located, and may be pieced together according to the environment variable of the database program, where the file is generally stored in the "$ ORACLE _ HOME/network/admin" directory. The generating of the monitoring configuration information according to the preset IP address may be filling the preset IP address into a preset configuration template, so as to generate the monitoring configuration information, wherein the preset configuration template may be preset by a software developer according to a database version.
It can be understood that the original monitoring configuration file is deleted, then the same-name configuration file is created in the same-level directory, and then the monitoring configuration information is written in the same-name configuration file, so that the original monitoring configuration file can be prevented from being modified, the compatibility problem is avoided, the method and the device can be suitable for databases of different versions and operating systems of different architectures, and the universality is strong and the compatibility is good.
For example: assuming that the preset IP ADDRESS is "0.0.0.0", the listening configuration information generated at this time is "listen = (describe _ LIST = (adds = (program = TCP) (HOST =0.0.0.0) (PORT = 1521)))", and the preset file path is "$ ORACLE _ HOME/network/admin/LISTENER. ora", then the file named "LISTENER. ora" is deleted according to the generated file deletion instruction at this time, then a same-name configuration file named "LISTENER. ora" is created, and then the generated listening configuration information is written thereto, so that the listening IP ADDRESS in the standby database is modified to the preset IP ADDRESS at this time.
Step S20: and shutting down the business service and accessing the configuration service in the main database.
It should be noted that the business service may include a database service, a listening (listener) service, and the like. Accessing the configuration service may include: the service corresponding to the VIP and the service corresponding to the SCAN IP.
It should be noted that when a service of the primary database fails (or a service disaster tolerance drill is started), the database service needs to be switched to the standby database, that is, the SCAN IP and the VIP are removed from the primary database and then configured on the host of the standby database. Since the SCAN IP and VIP are managed by the Oracle cluster system, these IP addresses cannot be removed by the ordinary method of deleting the IP addresses of the operating system. Doing so causes a problem in that if the host of the master database reboots (the cluster service is automatically started after the system reboots) or is manually rebooted by a malfunction, the cluster system attempts to configure SCAN IP and VIP on the host of the master database, causing IP collision, and if so, traffic interruption, and if serious, data brainbreak may be caused. In order to avoid the problem, the service corresponding to the SCAN IP and the VIP in the master database needs to be shut down and disabled, so as to ensure that the service corresponding to the SCAN IP and the VIP is not started by misoperation.
In a specific implementation, since the service corresponding to the SCAN IP and the VIP may not be disabled if the service of the master database is not stopped, the service of the master database may be first stopped, and then the service corresponding to the SCAN IP and the VIP of the master database may be stopped and disabled.
In practical use, the specific operation flow of shutting down the business service in the master database and accessing the configuration service may be:
A. the database service for all nodes in the master database is disabled (srvctl stop database command is available) otherwise the related services may not be disabled, resulting in failure of subsequent operations.
B. The listening listener service for all nodes in the master database is closed (srvctl stop listener is available) which may otherwise result in failure of subsequent operations.
C. The service corresponding to SCAN IP in the main database (2 services, SCAN _ list and SCAN) is disabled (srvctl disable command is available).
D. The entry corresponding to the SCAN IP in the/etc/hosts is deleted, so that even if someone mistakenly operates to enable the forbidden service again, the service corresponding to the SCAN IP cannot be normally started (the starting fails because the configuration information is lost), and the risk of contending for the SCAN IP address is avoided.
E. The service of the VIP is disabled in the same way, and the corresponding entry of the VIP in/etc/hosts is deleted, so that the risk of contending for the VIP address is avoided.
Step S30: and when the shutdown is completed, performing access IP configuration on the standby database according to the access IP configuration information so as to switch the service access of the main database to the standby database.
It should be noted that, accessing the standby database according to the access IP configuration information may be reading a VIP configuration and a SCAN IP configuration from the access IP configuration information, and then configuring a VIP and a SCAN IP in the standby database according to the read VIP configuration and SCAN IP configuration, and since both the VIP and SCAN IP are configured in the standby database, the service access of the service system is directly directed to the standby database, thereby implementing switching of the service access of the main database to the standby database, that is, implementing database switching.
The embodiment reads the access IP configuration information in the main database when the service abnormality of the main database is detected; shutting down business services and access configuration services in the main database; and when the shutdown is completed, performing access IP configuration on the standby database according to the access IP configuration information so as to switch the service access of the main database to the standby database. When the service of the main database is abnormal, the service of the main database is directly stopped, and the access IP configuration is carried out on the standby database according to the access IP configuration information in the main database, so that the access request of the service system points to the standby database, the switching of the databases is completed while the IP address is avoided being contended, the whole realization is simple and reliable without carrying out complex configuration and operation flow.
Referring to fig. 3, fig. 3 is a flowchart illustrating a database switching method according to a second embodiment of the present invention.
Based on the first embodiment, after step S30, the database switching method in this embodiment further includes:
step S40: and restarting the service of the main database when the repair of the main database is finished, setting a temporary access IP in the main database, and starting a first type access configuration service.
It should be noted that the first type access configuration service may be a service corresponding to the VIP. Compared with the standby database, the main database is generally better in configuration and higher in performance, therefore, when the repair of the main database is completed, service access is generally switched back to the main database, but as the VIP configuration is already configured in the standby database, the main database cannot normally start database service under the condition that the VIP is not configured, so as to receive data from the standby database and realize data synchronization. Thus, a temporary VIP, i.e., a temporary access IP, may be set in the master database at this time.
However, because the cluster and the database have many associated services and are interdependent, if one of the services is abnormal, a chain reaction occurs, which results in that other subsequent services are also abnormal. In addition, many services on the master library are in an abnormal state after the traffic of the master library is switched to the standby library. In this case, attempting to configure the temporary VIP and start the service may be successful, may fail, and may encounter various unknown problems, and in order to avoid these problems, it is necessary to stop the service from the entire cluster database, restart the service, wait for the service in the cluster database to enter a predictable state, and reconfigure the temporary access IP.
It is to be understood that, since the VIP service in the master database has been previously disabled and disabled, it is not effective to configure the temporary access IP only, and thus, after the temporary access IP is configured, the service corresponding to the VIP (i.e., the first type access configuration service) needs to be started.
Further, in order to ensure that the master database can be normally accessed after being switched back, the step S40 in this embodiment may include:
modifying the monitoring IP address in the master database into a preset IP address when the master database is repaired;
restarting the business service of the master database when the modification is completed;
and if the service is restarted, setting a temporary access IP in the master database, and starting a first type access configuration service of the master database.
It should be noted that, the database only monitors a specific IP address under a default condition, and the master database is no exception, which may affect the access of the service after the database service is switched back, so before the service of the master database is started, the configuration file of the listener needs to be modified, the monitored IP address in the master database is modified to a preset IP address, the database service monitors the preset IP address, and then the service in the master database is restarted, thereby ensuring that the database service can be normally accessed through any IP address on the database host after the master database is switched back.
Further, in order to avoid service interruption or data split, step S40 in this embodiment may include:
restarting the business service of the master database when the master database is repaired;
if the service is restarted, reading an access configuration file in the master database;
detecting whether target type configuration exists in the access configuration file;
if so, removing the target type configuration from the access configuration file;
upon completion of the removal, writing a temporary access IP into the access profile and initiating a first type of access profile service of the master database.
It should be noted that the target type configuration may be a configuration entry corresponding to the SCAN IP. At this time, the SCAN IP configuration still exists in the standby database, and after the service of the primary database is started, the temporary VIP may be configured in/etc/hosts first, and meanwhile, it is also necessary to check whether the configuration file has a SCAN IP configuration entry, and if so, the SCAN IP configuration entry needs to be deleted first, otherwise once the SCAN IP service in the primary database is started by mistake, an IP conflict may occur, which may cause service interruption or data split, and cause serious consequences. Therefore, when the service is restarted, the access configuration file in the main database is read, whether the target type configuration exists in the access configuration file is checked, if yes, the SCAN IP configuration entry exists in the access configuration file, at this time, the target type configuration can be removed from the configuration file, then when the removal is completed, the temporary access IP is written into the access configuration file, and then the first type access configuration service (namely, the service corresponding to the VIP) of each node in the main database is started to enable the written temporary access IP to take effect.
If the VIP service is deleted instead of being disabled when the business access of the main database is switched to the standby database, the VIP service needs to be added and then started.
Step S50: and synchronizing the data in the standby database to the main database based on the temporary access IP.
It is understood that the primary database may normally start the data service after the temporary access IP is configured, and thus, may receive the reverse synchronization data of the secondary database and synchronize the data in the secondary database to the primary database.
Step S60: and when the synchronization is finished, deleting the access IP configuration in the standby database, and carrying out the access IP configuration on the main database according to the access IP configuration information.
It can be understood that, the data of the standby database is completely synchronized back to the main database, at this time, the service access may be switched back from the standby database to the main database, at this time, the VIP configuration and the SCAN IP configuration configured in the standby database need to be configured back to the main database, and the configuration of the VIP needs to restart the cluster service and the database service, causing service interruption, which affects the continuity of the service, and at this time, in order to implement the service switching back without interrupting the service, the technical scheme splits the VIP configuration into two phases, namely, modifies the cluster configuration and restarts the cluster service (in the technical scheme, the cluster configuration modification operation is performed only, the cluster service restart operation is not performed, and the service switching back is not interrupted), at this time, the step S60 in this embodiment may include:
when the synchronization is completed, deleting the access IP configuration in the standby database, and generating first type configuration information and second type configuration information according to the access IP configuration information;
writing the first type configuration information and the second type configuration information into an access configuration file of the main database to realize access IP configuration of the main database;
the access IP is validated by the method of configuring the operating system IP address.
It should be noted that the first type of configuration information may be VIP configuration information, and the second type of configuration information may be SCAN IP configuration information. Writing the first type configuration information and the second type configuration information into the access configuration file of the main database may be writing the first type configuration information into the access configuration file, overwriting a VIP configuration in the access configuration file, and modifying SCAN IP entries in the access configuration file according to the second type configuration information.
It should be noted that, if only the VIP configuration is modified but the cluster service is not restarted, the original temporary VIP on each host operating system in the master database is not removed, the service VIP (i.e., the VIP address corresponding to the access IP configuration) is not set on the operating system, and the service system cannot access the database service through the service VIP. The temporary access IP is not removed, so that the normal use of the service of the main database is not influenced, and no additional processing is needed; the service VIP has no configuration problem, and the service VIP can be configured on the operating system of the corresponding host by a method for configuring the IP address of the operating system (network configuration commands can be used, and system calls provided by the operating system can also be used), so that the service system can access the database service through the service VIP. Because the service VIP configuration is written into the cluster configuration file and covers the configuration of the temporary VIP, when a certain host in the cluster fails, the service VIP in the cluster configuration file can be automatically drifted to other hosts of the cluster by the cluster system, the service system can be ensured to normally access the database service through the service VIP, the characteristic of cluster service failure automatic transfer (Failover) is met, and the continuity of the service system is ensured.
Step S70: and when the access IP configuration is completed, starting a second type access configuration service in the main database to switch service access back to the main database.
It should be noted that the second type access configuration service may be a service corresponding to the SCAN IP.
It can be understood that when the service access of the main database is switched to the standby database, only the service of the SCAN IP is disabled, and the switchback is relatively simple, and only after the SCAN IP entry is corrected in the/etc/hosts, the service corresponding to the SCAN IP (SCAN and SCAN _ builder service) is enabled (enabled) and started (start), so that at this time, the service system can access the service of the main database through the SCAN IP, and then the switchback of the SCAN IP is completed, which is simple and convenient and has good compatibility.
In this embodiment, when the repair of the master database is completed, the service of the master database is restarted, a temporary access IP is set in the master database, and a first type access configuration service is started; synchronizing data in the standby database to the primary database based on the temporary access IP; when the synchronization is completed, deleting the access IP configuration in the standby database, and performing the access IP configuration on the main database according to the access IP configuration information; and when the access IP configuration is completed, starting a second type access configuration service in the main database to switch service access back to the main database. Because the service of the main database can be started by setting the temporary access IP, the data synchronization can be completed under the condition of not influencing the service of the standby database, and the VIP is set in a staged configuration mode after the synchronization is completed, so that the service of the main database does not need to be restarted when the VIP is configured, the quick switching back of the service access is realized, the service continuity is ensured, and the characteristic of automatic Failover (Failover) of the cluster service fault is realized.
In addition, an embodiment of the present invention further provides a storage medium, where the storage medium stores a database switching program, and the database switching program, when executed by a processor, implements the steps of the database switching method described above.
Referring to fig. 4, fig. 4 is a block diagram illustrating a first embodiment of a database switching apparatus according to the present invention.
As shown in fig. 4, the database switching apparatus according to the embodiment of the present invention includes:
the data acquisition module 10 is configured to, when detecting that a service of a master database is abnormal, read access IP configuration information in the master database;
a service management module 20, configured to close the service and access the configuration service in the master database;
and the service switching module 30 is configured to perform access IP configuration on the standby database according to the access IP configuration information when the shutdown is completed, so as to switch the service access of the primary database to the standby database.
The embodiment reads the access IP configuration information in the main database when the service abnormality of the main database is detected; shutting down business services and access configuration services in the main database; and when the shutdown is completed, performing access IP configuration on the standby database according to the access IP configuration information so as to switch the service access of the main database to the standby database. When the service of the main database is abnormal, the service of the main database is directly stopped, and the access IP configuration is carried out on the standby database according to the access IP configuration information in the main database, so that the access request of the service system points to the standby database, the switching of the databases is completed while the IP address is avoided being contended, the whole realization is simple and reliable without carrying out complex configuration and operation flow.
Further, the service switching module 30 is further configured to restart the service of the master database when the master database is repaired, set a temporary access IP in the master database, and start a first type access configuration service; synchronizing data in the standby database to the primary database based on the temporary access IP; when the synchronization is completed, deleting the access IP configuration in the standby database, and performing the access IP configuration on the main database according to the access IP configuration information; and when the access IP configuration is completed, starting a second type access configuration service in the main database to switch service access back to the main database.
Further, the service switching module 30 is further configured to modify a monitored IP address in the master database into a preset IP address when the master database is repaired; restarting the business service of the master database when the modification is completed; and if the service is restarted, setting a temporary access IP in the master database, and starting a first type access configuration service of the master database.
Further, the service switching module 30 is further configured to restart the service of the master database when the master database is repaired; if the service is restarted, reading an access configuration file in the master database; detecting whether target type configuration exists in the access configuration file; if so, removing the target type configuration from the access configuration file; upon completion of the removal, writing a temporary access IP into the access profile and initiating a first type of access profile service of the master database.
Further, the service switching module 30 is further configured to delete the access IP configuration in the standby database when synchronization is completed, and generate first type configuration information and second type configuration information according to the access IP configuration information; writing the first type configuration information and the second type configuration information into an access configuration file of the main database to realize access IP configuration on the main database; the access IP is validated by the method of configuring the operating system IP address.
Further, the data acquisition module is also used for modifying the monitoring IP address in the standby database into a preset IP address; if the modification is completed, restarting the standby database; and when the restarting of the standby database is finished, synchronizing the data in the main database to the standby database through a preset synchronization interface.
Further, the data acquisition module is further configured to generate a file deletion instruction according to a preset file path; executing the file deleting instruction, and deleting the monitoring configuration file in the standby database; when the deletion is finished, a homonymous configuration file with the same name as the monitoring configuration file is created in the directory of the monitoring configuration file; and generating monitoring configuration information according to a preset IP address, and writing the monitoring configuration information into the same-name configuration file so as to modify the monitoring IP address in the standby database into the preset IP address.
It should be understood that the above is only an example, and the technical solution of the present invention is not limited in any way, and in a specific application, a person skilled in the art may set the technical solution as needed, and the present invention is not limited in this respect.
It should be noted that the above-described work flows are only exemplary, and do not limit the scope of the present invention, and in practical applications, a person skilled in the art may select some or all of them to achieve the purpose of the solution of the embodiment according to actual needs, and the present invention is not limited herein.
In addition, the technical details that are not described in detail in this embodiment may refer to the database switching method provided in any embodiment of the present invention, and are not described herein again.
Furthermore, it should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention or portions thereof that contribute to the prior art may be embodied in the form of a software product, where the computer software product is stored in a storage medium (e.g. Read Only Memory (ROM)/RAM, magnetic disk, optical disk), and includes several instructions for enabling a terminal device (e.g. a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (9)

1. A database switching method is characterized by comprising the following steps:
when the service abnormality of a main database is detected, reading access IP configuration information in the main database;
shutting down business services and access configuration services in the main database;
when the shutdown is completed, performing access IP configuration on a standby database according to the access IP configuration information so as to switch the service access of the main database to the standby database;
after the step of performing access IP configuration on the standby database according to the access IP configuration information to switch the service access of the primary database to the standby database when the shutdown is completed, the method further includes:
restarting the service of the main database when the repair of the main database is finished, setting a temporary access IP in the main database, and starting a first type access configuration service;
synchronizing data in the standby database to the primary database based on the temporary access IP;
when the synchronization is completed, deleting the access IP configuration in the standby database, and performing the access IP configuration on the main database according to the access IP configuration information;
and when the access IP configuration is completed, starting a second type access configuration service in the main database to switch service access back to the main database.
2. The database switching method of claim 1, wherein the step of restarting a business service of the master database, setting a temporary access IP in the master database, and starting a first type access configuration service when the repair of the master database is completed, comprises:
modifying the monitoring IP address in the master database into a preset IP address when the master database is repaired;
restarting the business service of the master database when the modification is completed;
and if the service is restarted, setting a temporary access IP in the master database, and starting a first type access configuration service of the master database.
3. The database switching method of claim 2, wherein the step of restarting the business service of the master database, setting a temporary access IP in the master database, and starting a first type access configuration service upon completion of the repair of the master database, comprises:
restarting the business service of the master database when the master database is repaired;
if the service is restarted, reading an access configuration file in the master database;
detecting whether target type configuration exists in the access configuration file;
if so, removing the target type configuration from the access configuration file;
upon completion of the removal, writing a temporary access IP into the access profile and initiating a first type of access profile service of the master database.
4. The database switching method according to claim 1, wherein the step of deleting the access IP configuration in the backup database and performing the access IP configuration on the primary database according to the access IP configuration information when the synchronization is completed comprises:
when the synchronization is completed, deleting the access IP configuration in the standby database, and generating first type configuration information and second type configuration information according to the access IP configuration information;
writing the first type configuration information and the second type configuration information into an access configuration file of the main database to realize access IP configuration of the main database;
the access IP is validated by the method of configuring the operating system IP address.
5. The database switching method according to any one of claims 1 to 4, wherein the step of reading the access IP configuration information in the master database when the service abnormality of the master database is detected further comprises:
modifying the monitored IP address in the standby database into a preset IP address;
if the modification is completed, restarting the standby database;
and when the restarting of the standby database is finished, synchronizing the data in the main database to the standby database through a preset synchronization interface.
6. The database switching method according to claim 5, wherein the step of modifying the monitored IP address in the standby database to a preset IP address comprises:
generating a file deleting instruction according to a preset file path;
executing the file deleting instruction, and deleting the monitoring configuration file in the standby database;
when the deletion is finished, a homonymous configuration file with the same name as the monitoring configuration file is created in the directory of the monitoring configuration file;
and generating monitoring configuration information according to a preset IP address, and writing the monitoring configuration information into the same-name configuration file so as to modify the monitoring IP address in the standby database into the preset IP address.
7. A database switching apparatus, comprising:
the data acquisition module is used for reading access IP configuration information in the main database when the service abnormality of the main database is detected;
the service management module is used for shutting down the business service and the access configuration service in the main database;
the service switching module is used for carrying out access IP configuration on a standby database according to the access IP configuration information when the shutdown is finished so as to switch the service access of the main database to the standby database;
the service switching module is further configured to restart a service of the master database when the repair of the master database is completed, set a temporary access IP in the master database, and start a first type of access configuration service; synchronizing data in the standby database to the primary database based on the temporary access IP; when the synchronization is completed, deleting the access IP configuration in the standby database, and performing the access IP configuration on the main database according to the access IP configuration information; and when the access IP configuration is completed, starting a second type access configuration service in the main database to switch service access back to the main database.
8. A database switching apparatus, characterized in that the database switching apparatus comprises: processor, memory and a database switching program stored on the memory and executable on the processor, which when executed by the processor implements the steps of the database switching method as claimed in any of claims 1 to 6.
9. A computer-readable storage medium, characterized in that a database switching program is stored on the computer-readable storage medium, which when executed performs the steps of the database switching method according to any one of claims 1-6.
CN202210595928.3A 2022-05-30 2022-05-30 Database switching method, device, equipment and storage medium Active CN114676118B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210595928.3A CN114676118B (en) 2022-05-30 2022-05-30 Database switching method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210595928.3A CN114676118B (en) 2022-05-30 2022-05-30 Database switching method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN114676118A CN114676118A (en) 2022-06-28
CN114676118B true CN114676118B (en) 2022-08-12

Family

ID=82079818

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210595928.3A Active CN114676118B (en) 2022-05-30 2022-05-30 Database switching method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114676118B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117349088B (en) * 2023-12-04 2024-04-02 深圳市科力锐科技有限公司 Database increment back-cut method, device, equipment and storage medium

Family Cites Families (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9395933B2 (en) * 2009-09-01 2016-07-19 Nec Corporation Distributed storage system, distributed storage method, and program and storage node for distributed storage
CN103064860A (en) * 2011-10-21 2013-04-24 阿里巴巴集团控股有限公司 Database high availability implementation method and device
CN107229455B (en) * 2016-03-24 2019-09-17 阿里巴巴集团控股有限公司 A kind of method for processing business, apparatus and system
CN106126652B (en) * 2016-06-24 2019-03-15 武汉斗鱼网络科技有限公司 Mishap Database switching method and system for distributed experiment & measurement system
CN107766502B (en) * 2017-10-20 2021-03-23 上海新炬网络信息技术股份有限公司 Oracle RAC database disaster recovery switching drilling method
CN109947591B (en) * 2017-12-20 2023-03-24 腾讯科技(深圳)有限公司 Database remote disaster recovery system and deployment method and device thereof
CN108416040B (en) * 2018-03-14 2020-10-27 上海达梦数据库有限公司 Database repair method and device, terminal equipment and storage medium
CN109388630B (en) * 2018-09-29 2020-09-29 京东数字科技控股有限公司 Database switching method, system, electronic device and computer readable medium
CN111209265B (en) * 2018-11-22 2023-11-17 华为技术有限公司 Database switching method and terminal equipment
CN110069365B (en) * 2019-04-26 2023-07-04 腾讯科技(深圳)有限公司 Method for managing database and corresponding device, computer readable storage medium
CN110532278B (en) * 2019-10-30 2020-01-31 上海爱可生信息技术股份有限公司 High availability method of declarative MySQL database system
CN111324617A (en) * 2020-02-09 2020-06-23 苏州浪潮智能科技有限公司 Method and equipment for online hot backup of database
CN111597192B (en) * 2020-04-10 2023-10-03 北京百度网讯科技有限公司 Database switching control method and device and electronic equipment
CN111581287A (en) * 2020-05-07 2020-08-25 上海茂声智能科技有限公司 Control method, system and storage medium for database management
CN113360579A (en) * 2021-06-30 2021-09-07 平安普惠企业管理有限公司 Database high-availability processing method and device, electronic equipment and storage medium
CN113900863A (en) * 2021-10-13 2022-01-07 深圳市震有软件科技有限公司 Method for automatically transferring PostgreSQL service fault

Also Published As

Publication number Publication date
CN114676118A (en) 2022-06-28

Similar Documents

Publication Publication Date Title
US9146839B2 (en) Method for pre-testing software compatibility and system thereof
CN108416040B (en) Database repair method and device, terminal equipment and storage medium
WO2022036901A1 (en) Implementation method and apparatus for redis replica set
CN108984349B (en) Method and device for electing master node, medium and computing equipment
CN112596951A (en) NAS data disaster tolerance method, device, equipment and storage medium
CN114676118B (en) Database switching method, device, equipment and storage medium
US8174966B2 (en) Switching program, switching method and duplex system
CN108595292B (en) System optimization method, mobile terminal and computer storage medium
WO2021259109A1 (en) Patch loading method, network element, and computer-readable storage medium
GB2532076A (en) Backup method, pre-testing method for environment updating and system thereof
CN112612652A (en) Distributed storage system abnormal node restarting method and system
CN107783855B (en) Fault self-healing control device and method for virtual network element
CN111078303A (en) Method and device for optimizing UEFI (unified extensible firmware interface) boot startup
CN109996262B (en) AC starting method and device
JP3527756B2 (en) How to update system files
CN112433860B (en) Event management method, system, equipment and medium
CN110647526B (en) Batch data processing method, device, computer equipment and storage medium
CN114003436A (en) Software backup method and device
CN112437119B (en) Distributed system upgrading method, device and node
CN112148463B (en) Business process control method and device
CN117032790A (en) Virtualization system version synchronization method, device, equipment and medium
CN111124520A (en) Method, equipment and medium for enhancing reliability of SONiC
CN117667296A (en) Restarting method and device of target container
US20190197235A1 (en) Server and setting method thereof
CN117312235A (en) Snapshot management method and device, metadata server and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant