Method and device for merging remote databases, electronic equipment and storage medium
By preprocessing and adding data source identification for off-site databases, selecting the total database and gradually merging other databases, the data isolation and interaction complexity problems between off-site databases are solved, and efficient database merging and resource optimization are achieved.
Patent Information
- Application Number
- CN202411964618.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2044-12-30
AI Technical Summary
There are data isolation and interaction complexity between off-site databases, which leads to the hidden dangers of resource waste and system crashes, and there is a lack of effective solutions to improve the operation and maintenance of multi-region databases.
By preprocessing multiple databases to be merged, the table structure and data storage method are consistent, and data source identifiers are added to the data table, a database is selected as the total library and set on the cloud server, gradually merge databases in other regions to form a cloud database, and finally merge with the headquarters database.
It realizes efficient merging of off-site databases, reduces server resource usage, shortens merge time, saves labor costs, and effectively avoids data disorders, improving system stability and availability.
Smart Images

Figure CN119903109A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a method, device, electronic device, computer-readable storage medium and computer program product for merging off-site databases. Background Art
[0002] For enterprises that need to store massive amounts of data or process large amounts of data, they often need to set up databases in different regions or areas, and sometimes they need to set up independently deployed servers to run these databases. As the business develops, the number of databases and the data stored in each database will continue to increase, forming a database cluster. For example, a commercial system has nearly 30 independently deployed databases in nearly 30 regions, which is a great waste of server resources.
[0003] As time goes by, the number of servers that need to be deployed remotely is increasing. Not only is there a waste of server resources, but more importantly, there are actually different degrees of data isolation between server databases in different regions, and the data interaction process between remote databases is complicated, and the response to data requests is slow. If there are too many databases, it is extremely unfavorable for data interaction and statistics of database clusters, and there is a risk of system crash. In order to maintain the normal operation of multi-regional databases, the resource cost and time cost required are increasing day by day, and there is still a lack of clear and effective solutions to improve the operation and maintenance of multi-regional databases. Summary of the invention
[0004] In view of this, an embodiment of the present application provides a method for merging databases in different locations, comprising the following steps: preprocessing a plurality of databases to be merged so that the table structures and data storage methods of the data tables in the plurality of databases to be merged are consistent, wherein the plurality of databases to be merged include a headquarters database and a plurality of regional databases, and the level of the headquarters database is higher than that of the regional databases; adding a data source identifier to all data tables in the plurality of databases to be merged, wherein the data source identifier is used to mark the original database to which the data table belongs; selecting a database that meets the conditions from among the plurality of databases to be merged after preprocessing and adding the data source identifier as the master database, and setting the master database on a cloud server, wherein the master database belongs to the regional database. the remaining regional databases are respectively set on the cloud server in predetermined batches or predetermined order and merged with the main database to form a cloud database; the headquarters database is set on the cloud server and merged with the cloud database to complete the database merging; wherein, during the preprocessing process, if a data table with a primary key conflict appears, a merged primary key value field is added to each of the multiple data tables with the primary key conflict, the merged primary key value field stores the primary key value of the merged data table, and the merged primary key value field is used in the data query task involving the primary key, together with the data source identifier as a query condition, so as to locate the required data table in the merged database according to the target merged primary key value and the target data source identifier.
[0005] Optionally, during the preprocessing process, if a data table with a seed conflict appears, the method further includes: increasing the primary key interval corresponding to the data table with the seed conflict so that no seed conflict occurs when the database is merged.
[0006] Optionally, the method further includes: before or during the database merging, updating the starting value of the primary key auto-increment interval corresponding to the data table to be merged according to a preset numerical range corresponding to the region where the original database to which the data table to be merged belongs is located, so as to prevent seed conflict from occurring during the merging.
[0007] Optionally, during the database merging process, if a database without a primary key table appears, the method further includes: adding a new primary key table to the database without a primary key table; and setting the starting value of the primary key auto-increment interval of the newly added primary key table according to a preset numerical range corresponding to the region where the database without a primary key table is located.
[0008] Optionally, before merging the databases, it further includes: before merging the databases, it further includes: modifying the replication relationship between the headquarters database and the local databases so that after the databases are merged, the corresponding replication relationship between the headquarters database and the local databases is unified, wherein the data to be copied meets the replication conditions of either the headquarters database or the local database, then the data is copied.
[0009] Optionally, after the database merger is completed, the cloud database synchronizes data to the merged regional database or headquarters database based on the data source field, and configures the merged database as a standby database so that when the cloud database fails, it can switch to the standby database for use.
[0010] Optionally, when merging databases, merge them one by one according to the data size from small to large, so as to reduce the risk of large-scale data conflicts and improve the merging efficiency.
[0011] The present invention further includes a device for merging databases in different locations, including: a data preprocessing module, used to preprocess multiple databases to be merged so that the table structures and data storage methods of the data tables in the multiple databases to be merged are consistent, wherein the multiple databases to be merged include a headquarters database and multiple regional databases, and the level of the headquarters database is higher than that of the regional databases; a data source adding module, used to add a data source identifier to all data tables in the multiple databases to be merged, and the data source identifier is used to mark the original database to which the data table belongs; a total library setting module, used to select a database that meets the conditions as the total library from the multiple databases to be merged after preprocessing and adding the data source identifier, and set the total library on the cloud server, wherein the total library belongs to the regional database. a regional database merging module, used to set the remaining regional databases on the cloud server in predetermined batches or predetermined order and merge them with the main database to form a cloud database; a headquarters database merging module, used to set the headquarters database on the cloud server and merge it with the cloud database to complete the database merging; wherein, during the preprocessing process, if a data table with a primary key conflict appears, a merged primary key value field is added to each of the multiple data tables with the primary key conflict, the merged primary key value field stores the primary key value of the merged data table, and the merged primary key value field is used in the data query task involving the primary key, together with the data source identifier as a query condition, so as to locate the required data table in the merged database according to the target merged primary key value and the target data source identifier.
[0012] The present invention further includes an electronic device, comprising: a processor and a memory storing computer program instructions; when the electronic device executes the computer program instructions, the method described above is implemented.
[0013] The present invention further includes a computer-readable storage medium, characterized in that computer program instructions are stored on the computer-readable storage medium, and when the computer program instructions are executed by a processor, any of the above methods is implemented.
[0014] The present invention further includes a computer program product, characterized in that it includes computer program instructions, and when the computer program instructions are executed by a processor, any of the above methods is implemented.
[0015] An embodiment of the present application provides an electronic device, which includes a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the steps of the method described above are implemented.
[0016] By adopting the embodiments of the present application, the server data scattered in different regions can be merged into the main server in a relatively short time, which greatly reduces the server resource usage. Moreover, the present application scheme as a whole makes little change to the existing data, which not only shortens the time consumption of server merging, but also saves labor costs. The present application uses methods such as adding data source fields to effectively avoid data disorder problems. When the present application is merging, the modified data will also be written to the merged server to ensure that when there is a problem with the main database, it can switch to the regional data in time to reduce system risks. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following briefly introduces the drawings in the embodiments of the present application.
[0018] Figure 1 It is a flowchart of a method for merging off-site databases according to an embodiment of the present application.
[0019] Figure 2 It is a schematic diagram of the structure of a device for merging databases in different locations according to an embodiment of the present application.
[0020] Figure 3 It is a schematic diagram of an electronic device used to implement the method for merging remote databases in an embodiment of the present application. DETAILED DESCRIPTION
[0021] The principles and spirit of the present application will be described below with reference to several exemplary embodiments. It should be understood that the purpose of providing these embodiments is to make the principles and spirit of the present application clearer and more thorough, so that those skilled in the art can better understand and implement the principles and spirit of the present application. The exemplary embodiments provided herein are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments herein, all other embodiments obtained by ordinary technicians of the art without creative work are within the scope of protection of this application.
[0022] Embodiments of the present application relate to terminal devices and / or servers. Those skilled in the art will appreciate that the embodiments of the present application may be implemented as a system, apparatus, device, method, computer-readable storage medium, or computer program product. Therefore, the present disclosure may be specifically implemented as at least one of the following forms: complete hardware, complete software, or a combination of hardware and software. According to the embodiments of the present application, the present application claims a method, apparatus, electronic device, computer-readable storage medium, and computer program product for merging off-site databases.
[0023] In this document, terms such as first, second, third, etc. are only used to distinguish one entity (or operation) from another entity (or operation), but not to require or imply any order or relationship between these entities (or operations).
[0024] Generally, in a database, the table structure is the basic component used to organize and store data. The database table structure defines how data is stored and how it is related to each other. Usually, each table has a unique primary key that uniquely identifies each row of data in the table. Each column of the table defines a field, and each field has a specific data type. The data type determines the type and format of data that the field can store. The main purpose of the primary key is to ensure the uniqueness of the data.
[0025] When a database is first established, it is usually set up nearby for ease of management and access, based on the generation and use of data. For example, a database is set up on a server in Beijing to store user data of local users in Beijing. In order to expand business in multiple different regions, one or more databases are also set up in multiple different regions. As the amount of data increases, multiple databases separated in different regions are neither convenient for maintenance and management nor conducive to data access.
[0026] Based on this, the present application proposes a method for merging remote databases, wherein the geographical locations of multiple databases can be in different regions. Figure 1 A flow chart of a method for merging databases in different locations according to an embodiment of the present application is shown. The method comprises the following steps:
[0027] In step S101 , multiple databases to be merged are preprocessed to make the table structures and data storage methods of the data tables in the multiple databases to be merged consistent, wherein the multiple databases to be merged include a headquarters database and multiple regional databases, and the level of the headquarters database is higher than that of the regional databases.
[0028] In step S102: a data source identifier is added to all data tables of the multiple databases to be merged, where the data source identifier is used to mark the original database to which the data table belongs.
[0029] In step S103: among the multiple databases to be merged after preprocessing and adding data source identification, a database that meets the conditions is selected as the master database, and the master database is set on the cloud server, wherein the master database belongs to the regional database.
[0030] In step S104: the remaining regional databases are respectively set on the cloud server in predetermined batches or predetermined order and merged with the main database to form a cloud database.
[0031] In step S105: the headquarters database is set on the cloud server and merged with the database on the cloud to complete the database merging. In the preprocessing process, if a data table with a primary key conflict appears, a merged primary key value field is added to each of the multiple data tables with the primary key conflict. The merged primary key value field stores the primary key value of the merged data table. The merged primary key value field is used as a query condition together with the data source identifier in the data query task involving the primary key, so as to locate the required data table in the merged database according to the target merged primary key value and the target data source identifier.
[0032] This application pre-processes multiple databases to be merged to ensure that the table structure and data storage method of each database are consistent, thereby solving the merging problem caused by inconsistent database structures. By adding a data source identification field, the data source can be effectively tracked, which is convenient for subsequent data analysis and management. At the same time, the primary key value field is merged to solve the primary key conflict problem, ensuring accurate data query and precise positioning of data during the merging process.
[0033] According to the embodiment of the present application, a database of a region is selected and uploaded to the cloud server, a general database is established on the cloud server based on the database, and then other databases are uploaded to the cloud server respectively and merged with the general database one by one. Based on this, the server data scattered in different regions can be merged into a general server in a relatively short time, which greatly reduces the server resource usage. The phased merging method ensures the controllability and flexibility of the merging operation and reduces the risk in the merging process. Moreover, the present application scheme as a whole makes little change to the existing system data, which not only shortens the time of server merging, but also saves labor costs.
[0034] In some embodiments, during the preprocessing process, if a data table with a seed conflict appears, the method further includes: increasing the primary key interval corresponding to the data table with the seed conflict so that no seed conflict occurs when the database is merged.
[0035] By increasing the primary key range, you can effectively avoid seed conflicts and ensure that the primary key values of each table will not be repeated when the database is merged, thereby avoiding data errors caused by primary key conflicts and ensuring data consistency and integrity.
[0036] In some embodiments, the method also includes: before or during the database merge, updating the starting value of the primary key auto-increment interval corresponding to the data table to be merged according to a preset numerical range corresponding to the region where the original database to which the data table to be merged belongs is located, so as to prevent seed conflict from occurring during the merge.
[0037] Dynamically adjust the starting value of the primary key auto-increment interval before or during the merge to ensure that there will be no seed conflicts in the merged database. This preventive measure provides more flexible adjustment space for the merge process, avoids merge failures caused by primary key conflicts, and improves the efficiency and accuracy of the merge.
[0038] In some embodiments, during the database merging process, if a database without a primary key table appears, the method further includes: adding a new primary key table to the database without a primary key table; and setting the starting value of the primary key auto-increment interval of the newly added primary key table according to a preset numerical range corresponding to the region where the database without a primary key table is located.
[0039] For tables without primary keys, a new primary key table is added and the starting value of the auto-increment interval is set according to the original region. This not only ensures the integrity and uniqueness of the data table, but also avoids data operation errors caused by the lack of primary key fields, further enhancing the stability and query efficiency of the database.
[0040] In some embodiments, before merging the databases, it further includes: modifying the replication relationship between the headquarters database and the local databases so that after the databases are merged, the corresponding replication relationship between the headquarters database and the local databases is unified, wherein the data to be replicated satisfies the replication conditions of either the headquarters database or the local database, then the data is replicated.
[0041] Modify the replication relationship between the headquarters database and the local databases so that the replication rules of the headquarters and local databases remain consistent after the merger. This measure unifies the data synchronization rules between databases and ensures that data can flow seamlessly between different databases, thereby improving data consistency and avoiding conflicts and errors that may occur during the synchronization process.
[0042] In some embodiments, after the database merger is completed, the cloud database synchronizes data to the merged regional database or headquarters database based on the data source field, and configures the merged database as a standby database so that when the cloud database fails, it can switch to the standby database for use.
[0043] After the database is merged, the main database synchronizes data back to the merged database based on the data source field, ensuring data consistency between all databases and improving data integrity. Through this synchronization mechanism, even if the main database fails, it can still ensure accurate data transmission between various databases.
[0044] In some embodiments, after the merger is completed, the merged database is configured as a standby database environment through automated tools or scripts. When the main database fails, it can be quickly switched to the standby database to ensure business continuity.
[0045] Using automated tools or scripts to configure the merged database as a standby database environment, you can quickly switch to the main database when it fails, ensuring business continuity. This mechanism reduces manual intervention, improves fault response speed, and ensures high availability and fault tolerance of the system.
[0046] In some embodiments, after the main database resumes normal operation, the data is synchronized back to the merged database, and the business traffic is switched back to the main database to achieve data consistency after fault recovery.
[0047] After the main database is restored to normal, the data will be synchronized back to the merged database, and the traffic will be switched back to the main database, thus ensuring the consistency of data and smooth operation of the business after the system is restored. This mechanism realizes seamless data recovery and business transition, and improves the stability of the system.
[0048] In some embodiments, when merging databases, the data is merged one by one from small to large in size to reduce the risk of large-scale data conflicts and improve merging efficiency.
[0049] Merging databases one by one according to the data scale can effectively avoid conflicts and performance bottlenecks during large-scale data merging, reduce merging risks and improve merging efficiency. This merging strategy can not only gradually accumulate experience and optimize the merging process, but also ensure the smooth progress of each merging operation, avoiding system crashes or processing delays caused by excessive data volume. Using the embodiments of the present application, even if the table structures of different databases in different regions are different, they can be merged accurately, quickly and without omissions. Moreover, whether during or after the merging process, online services can run in an orderly manner without being affected.
[0050] In some embodiments, adjusting database tables of multiple databases includes:
[0051] In step S301: if there are omissions or errors in the structure of a database table of the database, the database table is supplemented or corrected.
[0052] In step S302: the abandoned database tables are marked and no longer uploaded to the cloud server.
[0053] In step S303: the tables generated by the stored procedure are checked, and the tables that need to be deleted and rebuilt are screened out. These tables are not uploaded, and these tables are recreated when the stored procedure is re-run.
[0054] In order to ensure the uniformity and integrity of database tables in each region, it is necessary to regularize the tables used in each region. Specifically, we will carefully check for omissions and make sure that the database table structure of all regions is consistent. For abandoned tables, we will clearly mark them and decide not to migrate them to the cloud to avoid unnecessary waste of resources.
[0055] For tables generated by stored procedures, if they need to be deleted and recreated, they will not be migrated. After the system is online, these tables can be regenerated by running stored procedures. In some embodiments, in order to better track and identify the source of data, a field called "sourceBranch" can be added to all tables. This field will be used to identify which database the data comes from, so as to facilitate writing online data back to offline databases.
[0056] When adding this field, the value of this field will be matched according to the current region to ensure that the source of the data is clear. This will not only improve the traceability of the data, but also help to make subsequent data processing and analysis more efficient and accurate.
[0057] In a specific embodiment, in order to ensure the uniformity and integrity of the database tables in each region, it is necessary to regularize the tables used in each region. In this process, we will carefully check for omissions and make up for them to ensure that the database table structure of all regions is consistent. For abandoned tables, we will clearly mark them and decide not to migrate them to the cloud to avoid unnecessary waste of resources.
[0058] For tables generated by stored procedures, if they need to be deleted and recreated, they will not be migrated. After the system goes online, these tables can be regenerated by running stored procedures. In addition, in order to better track and identify the source of data, a field called "sourceBranch" will be added to all tables. This field will be used to identify which database the data comes from, making it easier to write online data back to offline databases.
[0059] When adding this field, the value of this field will be matched according to the current region to ensure that the source of the data is clear. This will not only improve the traceability of the data, but also help to make subsequent data processing and analysis more efficient and accurate.
[0060] In some embodiments, the stored procedures of multiple databases are adjusted, including: comparing the stored procedures of each region with those of the headquarters, and correcting the differences and missing stored procedures; for the total database that no longer needs the stored procedures, offline processing is performed; wherein, for the stored procedures involving table creation, the table creation logic of these stored procedures is compared, and the table creation logic of these stored procedures is made consistent.
[0061] In order to optimize and unify the database operations in various locations, a detailed comparison will be conducted between the stored procedures in various locations and the headquarters (hq). During this process, the focus will be on those stored procedures that are different or missing, and they will be supplemented and corrected one by one. For stored procedures that are no longer needed or have become outdated, they will be taken offline to ensure the efficiency and accuracy of database operation.
[0062] At the same time, we will also comprehensively check all existing stored procedures to assess whether they need to be modified or optimized. In particular, for the logic of creating tables in the stored procedures, we will focus on checking whether key fields such as xx, HQ, and EC are consistent in all the logic of creating tables. This is to prevent errors in the program when querying due to missing fields. Through this series of comparisons, additions, corrections, and troubleshooting, we will ensure the integrity and consistency of the database and provide strong guarantees for the stable operation of the business.
[0063] In a specific embodiment, in order to optimize and unify the database operations in various places, a detailed comparison will be made between the stored procedures of various places and the headquarters (hq). In this process, the focus will be on those stored procedures that are different or missing, and they will be supplemented and corrected one by one. For the stored procedures that are no longer needed or have become outdated, they will be taken offline to ensure the efficiency and accuracy of the database operation.
[0064] At the same time, we will also comprehensively check all existing stored procedures to assess whether they need to be modified or optimized. In particular, for the logic of creating tables in the stored procedures, we will focus on checking whether key fields such as xx, HQ, and EC are consistent in all the logic of creating tables. This is to prevent errors in the program when querying due to missing fields. Through this series of comparisons, additions, corrections, and troubleshooting, we will ensure the integrity and consistency of the database and provide strong guarantees for the stable operation of the business.
[0065] In a specific embodiment, the modification of the primary key conflict table may include:
[0066] The first one: a new field will be added to store the existing primary key value. This measure is designed to solve the problem of primary key conflicts while retaining the original primary key information. At the same time, a data source field will be added, and the value of the data source field in databases in different regions is different. In order to ensure the accuracy and efficiency of the query, this new field and the data label (sourceBranch) information will be used as query conditions in all queries involving primary keys. In this way, even if there is a primary key conflict, the required data can be accurately located by combining the new field and branch information. This transformation not only solves potential primary key conflicts, but also improves the flexibility and accuracy of data queries.
[0067] The second method: For tables with primary key conflicts, perform interval increment updates based on the ID associated with the primary key conflict table to ensure that there will be no primary key conflicts when merging the databases; ask the administrator of the merged database to set the starting value of the auto-increment interval that does not conflict according to the region in advance. For example, the primary keys of Table 1 and Table 2 are both catid, the catid value of Table 1 is 1 to 20, and the catid value of Table 2 is 12 to 40. If the two tables are merged into the same database, a primary key conflict will inevitably occur. Then you can increase the primary key value of Table 1 by 100,000 and the primary key value of Table 2 by 200,000, so that the primary key values of the two tables are completely different and avoid primary key conflicts.
[0068] In some embodiments, the process of merging databases is to merge them one by one according to the size of the databases, from small to large. Merging databases with smaller data volumes first is not only convenient for early operations and will not cause large-scale impacts, but also allows for rapid accumulation of experience, making subsequent merging of large databases smoother.
[0069] In some embodiments, if no index is configured for a table in the current database and the number of rows of data in the table exceeds 100,000 after the merge, an index is added to the table after the merge.
[0070] Before merging databases, different regional databases may need to interact with the headquarters database, for example, copying the headquarters database data to the local database. The replication rules between different databases and the headquarters may be different.
[0071] In a specific embodiment, during the database merging process, the replication relationship between the headquarters (hq) and various locations needs to be carefully adjusted. After the database merging is completed, the original source database replication rules will no longer apply, and the replication rules need to be updated to be based on the replication conditions of the two databases or the relationship. After the merger, all data uses unified replication rules. This adjustment is intended to ensure that data can flow accurately and efficiently in the new architecture to meet the needs of business operations. By optimizing the replication relationship, the performance and stability of the database can be further improved, providing strong support for the sustainable development of the business.
[0072] In some embodiments, it further includes: after the data of multiple databases are merged into the main database, the main database synchronizes data with the database based on the data source field.
[0073] In some embodiments, it further includes updating and retaining the database, including: setting up a standby database environment to keep it synchronized with the online database for backup; when the main database fails, switching the traffic to the database through automated tools or scripts to ensure business continuity; starting the data synchronization program to synchronize the data restored to normal in the main database to the database to ensure data consistency; after completing the data synchronization, switching the business traffic back to the main database to resume normal operation.
[0074] Through the above operations, after the database is merged, the main database is added to synchronize data to the merged database according to the data tag, and the merged database is used as a backup database. In this way, even if the main database of the cloud server has problems, a main database can be quickly merged again for use.
[0075] In some embodiments, the present application further includes a device for merging off-site databases, such as Figure 2 As shown, the device comprises:
[0076] A data preprocessing module 201 is used to preprocess multiple databases to be merged so that the table structures and data storage methods of the data tables in the multiple databases to be merged are consistent, wherein the multiple databases to be merged include a headquarters database and multiple regional databases, and the headquarters database has a higher level than the regional databases;
[0077] A data source adding module 202, configured to add a data source identifier to all data tables of the plurality of databases to be merged, wherein the data source identifier is used to mark the original database to which the data table belongs;
[0078] A general database setting module 203 is used to select a database that meets the conditions as a general database from among the multiple databases to be merged after preprocessing and adding data source identification, and set the general database on the cloud server, wherein the general database belongs to the regional database;
[0079] The regional database merging module 204 is used to respectively set the remaining regional databases on the cloud server in a predetermined batch or a predetermined order and merge them with the main database to form a cloud database;
[0080] The headquarters database merging module 205 is used to set the headquarters database on the cloud server and merge it with the cloud database to complete the database merging; wherein,
[0081] During the preprocessing process, if a data table with a primary key conflict appears, a merged primary key value field is added to each of the multiple data tables with the primary key conflict. The merged primary key value field stores the primary key value of the merged data table. The merged primary key value field is used as a query condition together with the data source identifier in the data query task involving the primary key, so as to locate the required data table in the merged database according to the target merged primary key value and the target data source identifier.
[0082] The electronic device in the embodiment of the present application may be a user terminal device, a server, other computing devices, or a cloud server. Figure 3A schematic diagram of the hardware structure of an electronic device according to an embodiment of the present application is shown. The electronic device may include a processor 601 and a memory 602 storing computer program instructions. When the processor 601 executes the computer program instructions, the process or function of any of the above-mentioned embodiments of the method is implemented.
[0083] Specifically, the processor 601 may include a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application. The memory 602 may include a large-capacity memory for data or instructions. For example, the memory 602 may be at least one of the following: a hard disk drive (HDD), a read-only memory (ROM), a random access memory (RAM), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a tape, a universal serial bus (USB) drive or other physical / tangible memory storage device. For another example, the memory 602 may include a removable or non-removable (or fixed) medium. For another example, the memory 602 may be inside or outside the integrated gateway disaster recovery device. The memory 602 may be a non-volatile solid-state memory. In other words, the memory 602 usually includes a tangible (non-transitory) computer-readable storage medium (such as a memory device) encoded with computer-executable instructions, and when the software is executed (such as executed by one or more processors), the operation described in the method of the embodiment of the present application can be performed. The processor 601 implements the process or function of any method in the above embodiments by reading and executing the computer program instructions stored in the memory 602.
[0084] In one example, Figure 3The electronic device shown may also include a communication interface 603 and a bus 610. Among them, the processor 601, the memory 602, and the communication interface 603 are connected through the bus 610 and complete the communication between each other. The communication interface 603 is mainly used to realize the communication between each module, device, unit and / or device in the embodiment of the present application. The bus 610 includes hardware, software or both, and can couple the components of the online data traffic billing device to each other. For example, the bus may include at least one of the following: an accelerated graphics port (AGP) or other graphics bus, an enhanced industrial standard architecture (EISA) bus, a front-end bus (FSB), a hypertransport (HT) interconnect, an industrial standard architecture (ISA) bus, an infinite bandwidth interconnect, a low pin count (LPC) bus, a memory bus, a micro channel architecture (MCA) bus, a peripheral component interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a serial advanced technology attachment (SATA) bus, a video electronics standard association local (VLB) bus or other suitable buses. The bus 610 may include one or more buses. Although the embodiments of the present application describe or illustrate a specific bus, the embodiments of the present application may consider any suitable bus or interconnection method.
[0085] In combination with the method in the above embodiments, an embodiment of the present application also provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the process or function of any method in the above embodiments is implemented.
[0086] In addition, an embodiment of the present application further provides a computer program product, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the process or function of any one of the methods in the above embodiments is implemented.
[0087] The above exemplarily describes the flowcharts and / or block diagrams of the methods, devices, systems and computer program products of the embodiments of the present application, and describes the relevant various aspects. It should be understood that each box or combination thereof in the flowchart and / or block diagram can be implemented by computer program instructions, or by dedicated hardware that performs a specified function or action, or by a combination of dedicated hardware and computer instructions. For example, these computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to form a machine that enables these instructions executed by such a processor to enable the implementation of the functions / actions specified in each box or combination thereof in the flowchart and / or block diagram. Such a processor can be a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit.
[0088] The functional blocks shown in the structured block diagram of the embodiment of the present application can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application-specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc.; when implemented in software, it is a program or code segment used to perform the required task. The program or code segment can be stored in a memory, or transmitted on a transmission medium or a communication link via a data signal carried in a carrier. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0089] It should be noted that the present application is not limited to the specific configurations and processes described above or shown in the figures. The above is only a specific implementation mode of the present application. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the described system, device, module or unit can refer to the corresponding process in the method embodiment without further description. It should be understood that the scope of protection of the present application is not limited to this. Any technician familiar with the technical field can think of various equivalent modifications or substitutions within the technical scope disclosed in the present application, and these modifications or substitutions should be included in the scope of protection of the present application.
Claims
1. A method for merging databases in different locations, characterized in that: The following steps are involved: Preprocessing a plurality of databases to be merged so that the table structures and data storage methods of the data tables in the plurality of databases to be merged are consistent, wherein the plurality of databases to be merged include a headquarters database and a plurality of regional databases, and the headquarters database has a higher level than the regional databases; Adding a data source identifier to all data tables of the multiple databases to be merged, wherein the data source identifier is used to mark the original database to which the data table belongs; Among the multiple databases to be merged after preprocessing and adding data source identification, a database that meets the conditions is selected as the master database, and the master database is set on the cloud server, where the master database belongs to the regional database; The remaining regional databases are respectively set on the cloud server in a predetermined order and merged with the main database to form a cloud database; The headquarters database is set on the cloud server and merged with the cloud database to complete the database merging; wherein, During the preprocessing process, if a data table with a primary key conflict appears, a merged primary key value field is added to each of the multiple data tables with the primary key conflict. The merged primary key value field stores the primary key value of the merged data table. The merged primary key value field is used as a query condition together with the data source identifier in the data query task involving the primary key, so as to locate the required data table in the merged database according to the target merged primary key value and the target data source identifier.
2. The method according to claim 1, characterized in that During the pretreatment process, the method further comprises: If a data table with a seed conflict appears, the primary key interval corresponding to the data table with the seed conflict is increased so that no seed conflict occurs when the database is merged; and / or, If a database without a primary key table appears, a new primary key table is added to the database without a primary key table; the starting value of the primary key auto-increment interval of the newly added primary key table is set according to the preset value range corresponding to the region where the database without a primary key table is located.
3. The method according to claim 1, characterized in that The method further comprises: Before or during database merging, the starting value of the primary key auto-increment interval corresponding to the data table to be merged is updated according to the preset value range corresponding to the region where the original database to which the data table to be merged belongs is located, so that no seed conflict occurs during the merge.
4. The method according to claim 1, characterized in that: Before merging the databases, the method further includes: Modify the replication relationship between the headquarters database and the local database so that after the databases are merged, the replication relationship between the headquarters database and the local database is unified, wherein the data to be replicated satisfies the replication conditions of either the headquarters database or the local database, then the data is replicated.
5. The method according to claim 1, characterized in that The predetermined order includes: an order from small to large according to the size of the databases to be merged.
6. The method according to claim 1, characterized in that After the database merger is completed, the cloud database synchronizes data to the merged regional database or headquarters database based on the data source field, and configures the merged database as a standby database so that when the cloud database fails, it can switch to the standby database for use.
7. A device for merging databases in different locations, characterized in that: include: A data preprocessing module, used for preprocessing a plurality of databases to be merged, so as to make the table structures and data storage methods of the data tables in the plurality of databases to be merged consistent, wherein the plurality of databases to be merged include a headquarters database and a plurality of regional databases, and the level of the headquarters database is higher than that of the regional databases; A data source adding module, used for adding a data source identifier to all data tables of the plurality of databases to be merged, wherein the data source identifier is used for marking the original database to which the data table belongs; A general database setting module is used to select a database that meets the conditions as a general database from among multiple databases to be merged after preprocessing and adding data source identification, and set the general database on the cloud server, wherein the general database belongs to the regional database; A regional database merging module is used to set the remaining regional databases to the cloud server in a predetermined batch or a predetermined order and merge them with the main database to form a cloud database; The headquarters database merging module is used to set the headquarters database on the cloud server and merge it with the cloud database to complete the database merging; wherein, During the preprocessing process, if a data table with a primary key conflict appears, a merged primary key value field is added to each of the multiple data tables with the primary key conflict. The merged primary key value field stores the primary key value of the merged data table. The merged primary key value field is used as a query condition together with the data source identifier in the data query task involving the primary key, so as to locate the required data table in the merged database according to the target merged primary key value and the target data source identifier.
8. An electronic device, characterized in that: The electronic device comprises: a processor and a memory storing computer program instructions; when the electronic device executes the computer program instructions, the method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that It comprises computer program instructions, which implement the method according to any one of claims 1 to 6 when executed by a processor.
Citation Information
Patent Citations
Quality management transversal integration system and method
CN101458782A
Cross-machine-room data synchronization system, method and device and electronic device
CN108573006A
Data management device, data management method, and program
JP2024128734A
Dynamic aggregation of data from separate sources
US11200213B1
Codeless specification of software as a service integrations
US20210081179A1