A method, device, electronic device and medium for synchronizing incremental data of a database

By building incremental databases and snapshot databases for production libraries that need to be upgraded, binding triggers in the production library to detect and synchronize incremental data, the problem of incremental data synchronization during database upgrade is solved, and the accuracy of upgrade results is improved.

CN119202093BActive Publication Date: 2025-04-01HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411687069.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-22
Publication Date
2025-04-01
Estimated Expiration
2044-11-22

AI Technical Summary

Technical Problem

During the database upgrade process, as the business system continues to operate, the data stored in the database will change and generate incremental data, resulting in a method of synchronizing incremental data to ensure the accuracy of the database upgrade.

Method used

By building incremental libraries and snapshot libraries for production libraries that need to be upgraded, and binding the first type of trigger in the production library, listening and detecting table building operations in the production library. When a table build operation exists, create a second type of trigger and synchronize the new table to the incremental library, so that the second type of trigger can detect and synchronize the incremental data corresponding to the update operation of the new table in the production library.

Benefits of technology

It is possible to upgrade the production library without pausing it, which improves the accuracy of incremental data synchronization and thus improves the accuracy of database upgrade results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119202093B_ABST
    Figure CN119202093B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a method, device, electronic device and medium for synchronizing incremental data of a database, which relates to the field of database management. The production library to be upgraded has a corresponding incremental library and snapshot library, and the production library is bound with a first type of trigger. The method includes: upgrading the snapshot library in response to a start upgrade instruction, and during the snapshot library upgrade process, detecting whether there is a table creation operation for the production library through the first type of trigger; in response to the existence of a table creation operation for the production library, creating a second type of trigger corresponding to the newly created table generated by the table creation operation, and synchronizing the newly created table to the incremental library, so that the second type of trigger synchronizes the incremental data corresponding to the update operation generated by the production library to the incremental library when an update operation for data in the newly created table is detected. By synchronizing the incremental data generated by the production library to be upgraded during the upgrade process to the incremental library, the accuracy of the database upgrade result can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of database management, and in particular to a method, device, electronic device and medium for synchronizing incremental data of a database. Background Art

[0002] As the business system is online for more years and the business scope continues to expand, the amount of business data accumulated in the database continues to increase, and the size of the database storing business data continues to increase. Usually during the database upgrade process, the database will stop providing data services to the business system, causing the business system to stop providing business services to users. Due to the large size of the database, it takes a long time to upgrade the database, and the business interruption time is also long, affecting the user experience.

[0003] In the related art, in order to avoid deactivating the production database during the database upgrade process, the database upgrade is achieved by copying the data in the database to a new database and upgrading the new database. However, during the database upgrade process, as the business system continues to run, the data stored in the database will change and generate incremental data, so a method for synchronizing the incremental data is needed. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a method, device, electronic device and medium for synchronizing incremental data of a database, so as to synchronize the incremental data generated by the production library to be upgraded during the upgrade process to the incremental library of the production library, thereby improving the accuracy of the database upgrade result. The specific technical solution is as follows:

[0005] In a first aspect, an embodiment of the present application provides a method for synchronizing incremental data of a database, wherein a production library has a corresponding incremental library and a snapshot library, the production library is a database to be upgraded, the snapshot library is a copy library obtained by copying the production library in response to a start upgrade instruction of the production library, the production library is bound to a first type of trigger, and the method includes:

[0006] In response to the start upgrade instruction, the snapshot database is upgraded, and during the snapshot database upgrade process, the first type of trigger is used to detect whether there is a table creation operation for the production database;

[0007] In response to the existence of a table creation operation for the production library, a second type of trigger corresponding to the newly created table generated by the table creation operation is created, and the newly created table is synchronized to the incremental library, so that when the second type of trigger detects an update operation on the data in the newly created table, the incremental data corresponding to the update operation generated by the production library is synchronized to the incremental library.

[0008] Optionally, the existing table in the production library is bound with a corresponding second type trigger;

[0009] Each of the second-type triggers is used to synchronize the incremental data corresponding to the update operation generated by the production library to the incremental library when an update operation on the data in the table bound to itself is detected.

[0010] Optionally, the step of synchronizing the newly created table to the incremental library includes:

[0011] According to the identifier and attributes of the newly created table, a table having the same identifier and attributes as those of the newly created table is constructed in the incremental library.

[0012] Optionally, the incremental database is a database whose structure is the same as that of the production database and is constructed when the production database starts to be upgraded;

[0013] The step of synchronizing the incremental data corresponding to the update operation generated by the production library to the incremental library includes:

[0014] According to the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation and the operation, the table position in the table with the identifier in the incremental library records the target data indicated by the operation and the type of the operation.

[0015] Optionally, in response to the existence of a table creation operation for the production database, the step of creating a second type of trigger corresponding to a newly created table generated by the table creation operation includes:

[0016] When the first type of trigger monitors the table creation operation for the production database, the second type of trigger creation function calls the second type of trigger creation function, so that after the new table generated by the table creation operation is created, the second type of trigger creation function creates a second type of trigger corresponding to the new table.

[0017] Optionally, the method further includes:

[0018] After the snapshot library is upgraded, the incremental library is upgraded;

[0019] The incremental data included in the upgraded incremental library is merged into the upgraded snapshot library to obtain the upgraded production library.

[0020] Optionally, the method further includes:

[0021] Obtaining an access instruction, wherein the access instruction includes an identifier of a table to be accessed, and the table to be accessed includes tables in at least two databases of the production library, the snapshot library, and the incremental library;

[0022] Parse the access instruction to obtain the access instruction including the internal table identifier and the external table identifier of the table to be accessed, and determine the target database to be accessed according to the internal table identifier obtained by parsing, wherein the external table identifier is an identifier obtained by mapping the table identifier in the associated database in advance according to a preset mapping method, the target database is the production database, the incremental database or the snapshot database, and the associated databases are two databases other than the target database;

[0023] Accessing the table corresponding to the internal table identifier in the target database through the access link between the target database and the target database;

[0024] Based on the mapping relationship between the actual table identifier in the associated database and the external table identifier included in the pre-built external table in the target database, the actual table in the associated database to be accessed is determined, and the actual table in the associated database is accessed.

[0025] Optionally, before the step of obtaining the access instruction, the method further includes:

[0026] The production database, the incremental database and the snapshot database are respectively used as target databases, and corresponding external tables of the associated databases are established in the target databases;

[0027] For each target database, obtain a table identifier of an actual table in a related database corresponding to the target database;

[0028] Determine the external table identifier corresponding to the obtained table identifier according to the preset identifier mapping method;

[0029] The mapping relationship between each external table identifier and the obtained table identifier is stored in the external table.

[0030] Optionally, the method further includes:

[0031] After the snapshot database upgrade is completed, each external table of the associated database stored in the target database is deleted.

[0032] In a second aspect, an embodiment of the present application provides an incremental data synchronization device for a database, wherein a production library has a corresponding incremental library and a snapshot library, the production library is a database to be upgraded, the snapshot library is a copy library obtained by copying the production library in response to a start upgrade instruction of the production library, the production library is bound to a first type of trigger, and the device includes:

[0033] an operation detection module, configured to upgrade the snapshot library in response to the start upgrade instruction, and during the snapshot library upgrade process, detect whether there is a table creation operation for the production library through the first type of trigger;

[0034] A trigger creation module is used to create a second type of trigger corresponding to a newly created table generated by a table creation operation for the production library in response to the existence of the table creation operation, and synchronize the newly created table to the incremental library, so that when the second type of trigger detects an update operation for the data in the newly created table, the incremental data corresponding to the update operation generated by the production library is synchronized to the incremental library.

[0035] Optionally, the existing tables in the production library are bound to corresponding second-type triggers; each second-type trigger is used to synchronize the incremental data corresponding to the update operation generated by the production library to the incremental library when an update operation on the data in the table bound to itself is detected.

[0036] Optionally, the trigger creation module includes:

[0037] A construction unit is used to construct, in the incremental library, a table whose identification and attributes are respectively the same as the identification and attributes of the newly created table, according to the identification and attributes of the newly created table.

[0038] Optionally, the incremental database is a database whose structure is the same as that of the production database and is constructed when the production database starts to be upgraded;

[0039] The trigger creation module includes:

[0040] A type recording unit is used to record the target data indicated by the operation and the type of the operation according to the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation, and the operation, at the table position in the table with the identifier in the incremental library.

[0041] Optionally, the trigger creation module includes:

[0042] The function calling unit is used for the first type of trigger to call the second type of trigger creation function when monitoring the table creation operation for the production database, so that the second type of trigger creation function creates a second type of trigger corresponding to the new table after the new table generated by the table creation operation is created.

[0043] Optionally, the device further comprises:

[0044] An upgrade module, used for upgrading the incremental library after the snapshot library is upgraded;

[0045] The merging module is used to merge the incremental data included in the upgraded incremental library into the upgraded snapshot library to obtain the upgraded production library.

[0046] Optionally, the device further comprises:

[0047] An instruction acquisition module, used for acquiring an access instruction, wherein the access instruction includes an identifier of a table to be accessed, and the table to be accessed includes tables in at least two databases of the production library, the snapshot library, and the incremental library;

[0048] A parsing module, used for parsing the access instruction, obtaining the internal table identifier and external table identifier of the table to be accessed, and determining the target database to be accessed according to the internal table identifier obtained by parsing, wherein the external table identifier is an identifier obtained by mapping the table identifier in the associated database in advance according to a preset mapping method, the target database is the production database, the incremental database or the snapshot database, and the associated databases are two databases other than the target database;

[0049] An access module, used for accessing a table corresponding to the internal table identifier in the target database through an access link with the target database;

[0050] The table determination module is used to determine the actual table in the associated database to be accessed based on the mapping relationship between the actual table identifier in the associated database included in the pre-built external table in the target database and the external table identifier, and access the actual table in the associated database.

[0051] Optionally, the device further comprises:

[0052] An external table establishment module is used to, before the step of obtaining the access instruction, respectively use the production database, the incremental database and the snapshot database as target databases, and establish corresponding external tables of the associated database in the target databases;

[0053] An identification acquisition module, used for acquiring, for each target database, a table identification of an actual table in a related database corresponding to the target database;

[0054] An external table identifier determination module, used to determine the external table identifier corresponding to the obtained table identifier according to a preset identifier mapping method;

[0055] The storage module is used to store the mapping relationship between each external table identifier and the obtained table identifier in the external table.

[0056] Optionally, the device further comprises:

[0057] The deletion module is used to delete the external table of each associated database stored in the target database after the snapshot library upgrade is completed.

[0058] In a third aspect, an embodiment of the present application further provides an electronic device, including:

[0059] Memory, used to store computer programs;

[0060] The processor is used to implement the incremental data synchronization method of the database described in any one of the first aspects when executing the program stored in the memory.

[0061] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the incremental data synchronization method of the database described in any one of the first aspects is implemented.

[0062] In a fifth aspect, an embodiment of the present application further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described methods for synchronizing incremental data of a database.

[0063] Beneficial effects of the embodiments of the present application:

[0064] In the solution provided by the embodiment of the present application, the production library that needs to be upgraded has a corresponding incremental library and snapshot library, and the production library is bound with a first type of trigger. The electronic device upgrades the snapshot library in response to the start upgrade instruction. During the snapshot library upgrade process, the first type of trigger is used to detect whether there is a table building operation for the production library; in response to the existence of a table building operation for the production library, a second type of trigger corresponding to the newly created table generated by the table building operation is created, and the newly created table is synchronized to the incremental library, so that the second type of trigger, when detecting an update operation for the data in the newly created table, synchronizes the incremental data corresponding to the update operation produced by the production library to the incremental library. By constructing an incremental library and a snapshot library for the production library that needs to be upgraded, and upgrading the incremental library and the snapshot library, the purpose of upgrading the production library can be achieved without suspending the use of the production library. In addition, the first type of trigger is used to actively monitor the table building operation in the production library to bind the second type of trigger to the newly created table generated by the production library during the upgrade process, so that the incremental data generated in the table building operation can also be synchronized to the incremental library, which improves the accuracy of the incremental data synchronization, and then improves the accuracy of the upgrade result. Of course, any product or method implementing the present application does not necessarily need to achieve all the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.

[0066] Figure 1 A schematic diagram of a flow chart of a method for synchronizing incremental data of a database provided in an embodiment of the present application;

[0067] Figure 2 A schematic diagram of an incremental data synchronization example provided in an embodiment of the present application;

[0068] FIG3 (a) is a flowchart of the database upgrade process;

[0069] FIG3 (b) is a schematic diagram of the association relationship among the production library, the snapshot library and the incremental library;

[0070] Figure 3 (c) is a schematic diagram of Table A in the upgraded snapshot library;

[0071] Figure 3 (d) is a schematic diagram of table A in the upgraded incremental library;

[0072] Figure 3(e) is a schematic diagram of Table A in the merged database;

[0073] Figure 4 Another flowchart of the incremental data synchronization method of the database provided in the embodiment of the present application;

[0074] Figure 5 A schematic diagram of the external table construction process of the target database provided in the embodiment of the present application;

[0075] Figure 6 A schematic diagram of an example of constructing an external table provided in an embodiment of the present application;

[0076] Figure 7 A schematic diagram of the structure of an incremental data synchronization device for a database provided in an embodiment of the present application;

[0077] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0078] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.

[0079] In order to synchronize the incremental data of a database that needs to be upgraded during the upgrade process, the present application provides a method, device, electronic device, computer-readable storage medium and computer program product for synchronizing incremental data of a database. The following first introduces a method for synchronizing incremental data of a database provided in an embodiment of the present application.

[0080] The production library has a corresponding incremental library and a snapshot library. The production library is the database that needs to be upgraded. The snapshot library is a copy library obtained by copying the production library in response to the start upgrade instruction of the production library. The production library is bound to a first type of trigger, such as Figure 1 As shown, the method includes:

[0081] S101: In response to the start upgrade instruction, the snapshot database is upgraded. During the snapshot database upgrade process, the first type of trigger is used to detect whether there is a table creation operation for the production database.

[0082] S102: In response to a table creation operation for the production library, create a second type of trigger corresponding to the newly created table generated by the table creation operation, and synchronize the newly created table to the incremental library, so that when the second type of trigger detects an update operation on the data in the newly created table, it synchronizes the incremental data corresponding to the update operation generated by the production library to the incremental library.

[0083] In the solution provided by the embodiment of the present application, the production library that needs to be upgraded has a corresponding incremental library and snapshot library, and the production library is bound with a first type of trigger. The electronic device upgrades the snapshot library in response to the start upgrade instruction. During the snapshot library upgrade process, the first type of trigger is used to detect whether there is a table building operation for the production library; in response to the existence of a table building operation for the production library, a second type of trigger corresponding to the newly created table generated by the table building operation is created, and the newly created table is synchronized to the incremental library, so that the second type of trigger, when detecting an update operation for the data in the newly created table, synchronizes the incremental data corresponding to the update operation produced by the production library to the incremental library. By constructing an incremental library and a snapshot library for the production library that needs to be upgraded, and upgrading the incremental library and the snapshot library, the purpose of upgrading the production library can be achieved without suspending the use of the production library. In addition, the first type of trigger is used to actively monitor the table building operation in the production library to bind the second type of trigger to the newly created table generated by the production library during the upgrade process, so that the incremental data generated in the table building operation can also be synchronized to the incremental library, thereby improving the accuracy of the incremental data synchronization, and thus improving the accuracy of the upgrade result.

[0084] When the user wishes to upgrade the database, the user can send a start upgrade instruction for the database to be upgraded, so that the electronic device responds to the start upgrade instruction to upgrade the database. In order to keep the database from providing data services to the business system and avoid the business system from stopping service due to database upgrade, the database to be upgraded can be used as a production database. The database can be various types of databases, such as PostgreSQL, MySQL, etc., which are not specifically limited here.

[0085] In one implementation, when the start upgrade instruction indicates to upgrade multiple databases, the database currently accessed by the business system among the multiple databases can be used as the production database, or each database can be used as the production database, which is reasonable and not specifically limited here.

[0086] Upon receiving an instruction to start upgrading the production library, the electronic device may respond to the instruction to start upgrading the production library by copying the production library to obtain a copy of the production library as a snapshot of the production library; and, respond to the instruction to start upgrading the production library by constructing an incremental library of the production library, wherein the incremental library is a database for storing incremental data generated by the production library during the upgrading process, and when the upgrade starts, the structure of the incremental library is consistent with that of the production library, that is, when the upgrade starts, the number, identifiers and attributes of the tables in the incremental library are respectively consistent with the number, identifiers and attributes of the tables in the production library.

[0087] In order to synchronize the incremental data of the production database during the upgrade process, the first type of trigger can be bound to the production database, where the first type of trigger is used to detect whether there is a table creation operation for the production database. Of course, the first type of trigger can also detect DDL (Data Definition Language) operations for the production database. When the first type of trigger is used to detect other operations for the production database, the implementation idea is the same, and the table creation operation is used as an example for explanation.

[0088] In addition, since the first type of trigger is used to detect whether there is a table creation operation for the production database, the first type of trigger is implemented by monitoring the new table creation event in the production database, so the first type of trigger is a trigger for monitoring the new table creation event.

[0089] In one implementation, the electronic device may create a first type of trigger for the production library upon receiving an instruction to start upgrading the production library, so that the production library is bound with the first type of trigger and the first type of trigger is enabled.

[0090] In one implementation, before receiving the instruction to start upgrading the production library, the production library is bound to the first type of trigger. When the electronic device receives the instruction to start upgrading the production library, it can enable the first type of trigger of the production library.

[0091] After building a snapshot library and an incremental library of a production library that needs to be upgraded, the electronic device can upgrade the production library by upgrading the snapshot library and the incremental library of the production library.

[0092] Furthermore, in the above step S101, the electronic device may upgrade the snapshot library in response to the start upgrade instruction. During the snapshot library upgrade process, the first type of trigger is used to detect whether there is a table creation operation for the production library.

[0093] In the case of receiving the start upgrade instruction for the production library, the electronic device can upgrade the snapshot library in response to the start upgrade instruction. Since the snapshot library is a duplicate library obtained by duplicating the production library in response to the start upgrade instruction of the production library, that is, the snapshot library is consistent with the production library at the time of receiving the start upgrade instruction of the production library, that is, the snapshot library is consistent with the production library at the start of the upgrade, then upgrading the snapshot library is to upgrade the production library at the start of the upgrade.

[0094] During the upgrade of the snapshot library, since the production library continues to provide data services for the business system, the data in the production library may change due to user operations while users use business products. For example, users may create tables in the production library, or update data in existing tables in the production library.

[0095] Since the production library is bound with a first type trigger that can detect whether there is a table creation operation for the production library, during the snapshot library upgrade process, the electronic device can detect whether there is a table creation operation for the production library through the first type trigger.

[0096] In the case that there is a table creation operation for the production database, the first type of trigger will be triggered, and the electronic device determines whether there is a table creation operation for the production database according to the triggering condition of the first type of trigger.

[0097] Furthermore, in the above step S102, the electronic device can create a second type of trigger corresponding to the newly created table generated by the table creation operation in response to the existence of a table creation operation on the production library, and synchronize the newly created table to the incremental library, so that when the second type of trigger detects an update operation on the data in the newly created table, it synchronizes the incremental data corresponding to the update operation generated by the production library to the incremental library.

[0098] When the first type of trigger is triggered, that is, when there is a table creation operation for the production database, the electronic device can create a corresponding second type of trigger for the newly created table generated by the table creation operation in response to the existence of the table creation operation for the production database, wherein the second type of trigger is used to detect whether there is a DML (Data Manipulation Language) for the data in the bound table, for example, update operations such as insert, update, and delete.

[0099] As an implementation manner, when the triggering of the first type of trigger is detected, the electronic device creates a corresponding second type of trigger for the new table generated by the table creation operation.

[0100] As an implementation method, when the second type of trigger detects a table creation operation for a production database, it automatically creates a corresponding second type of trigger for a new table generated by the table creation operation.

[0101] Furthermore, in order to facilitate synchronization of incremental data in the newly created table to the incremental library, the electronic device may also synchronize the newly created table to the incremental library in response to a table creation operation for the production library, so as to keep the structure of the incremental library consistent with that of the production library.

[0102] After creating a corresponding second-type trigger for the newly created table, the second-type trigger can detect whether there is an update operation on the data in the newly created table. When an update operation on the data in the newly created table is detected, the second-type trigger can synchronize the incremental data corresponding to the update operation generated by the newly created table to the incremental library.

[0103] In this way, when the first type of trigger detects that there is a table creation operation for the production database, the second type of trigger is bound to the newly created table, and when the second type of trigger detects an update operation on the data in the newly created table, the incremental data generated by the update operation in the production database is synchronized to the incremental database. Therefore, by binding the second type of trigger to the new table, it is ensured that the incremental data in the new table in the production database during the upgrade process can also be synchronized to the incremental database, thereby achieving the purpose of synchronizing the newly created table in the production database and the incremental data generated by the update operation in the newly created table to the incremental database.

[0104] In addition, since the second type of trigger is used to detect whether there is an update operation on the data in the table, and when an update operation on the data in the table is detected, the incremental data corresponding to the update operation is synchronized to the incremental library, the second type of trigger is implemented by monitoring and synchronizing the incremental data in the bound table, then the second type of trigger is an incremental data synchronization trigger.

[0105] It can be seen that in the solution provided by the embodiment of the present application, by constructing an incremental library and a snapshot library for the production library that needs to be upgraded, and upgrading the incremental library and the snapshot library, the purpose of upgrading the production library can be achieved without suspending the use of the production library. In addition, the first type of trigger is used to actively monitor the table building operation in the production library to bind the second type of trigger to the newly created table generated by the production library during the upgrade process, so that the incremental data generated in the table building operation can also be synchronized to the incremental library, which improves the accuracy of the incremental data synchronization, and further improves the accuracy of the upgrade result.

[0106] As an implementation of an embodiment of the present application, the existing tables in the production library are bound to corresponding second-type triggers; each second-type trigger is used to synchronize the incremental data corresponding to the update operation generated by the production library to the incremental library when an update operation on the data in the table bound to itself is detected.

[0107] In order to synchronize all incremental data generated by the production database during the upgrade process, each existing table in the production database is bound with a corresponding second-type trigger when the upgrade begins.

[0108] In one implementation, upon receiving an instruction to start upgrading the production library, the electronic device may create a second type of trigger for each existing table in the production library, so that each existing table in the production library is bound with the second type of trigger and the second type of trigger is enabled.

[0109] In one implementation, before receiving the start upgrade instruction for the production library, each existing table in the production library is bound to the second type of trigger. When the electronic device receives the start upgrade instruction for the production library, it can enable the second type of trigger for each existing table in the production library.

[0110] During the snapshot library upgrade process, each second-type trigger can detect whether there is an update operation on the data in the table bound to itself, and then, when an update operation on the data in the table bound to itself is detected, the incremental data corresponding to the update operation generated by the table bound to itself will be synchronized to the incremental library, thereby achieving the purpose of synchronizing the incremental data corresponding to the update operation generated by the production library to the incremental library through each second-type trigger.

[0111] For example, Figure 2As shown in the figure, Table 1 (table1) and Table 2 (table2) are existing tables in the production database. Table 1 and Table 2 are bound to incremental data synchronization triggers (second-type triggers) respectively. The production database is bound to a trigger that monitors new table creation events (first-type triggers). At the beginning of the upgrade, the first-type triggers and each second-type trigger are enabled. The user performs a table creation operation through the background service to create a new table (table_new) in the production database. The trigger that monitors the new table creation event recognizes the creation of a new table and creates an incremental data synchronization trigger for the new table. During the upgrade process, each incremental data synchronization trigger detects whether there is an update operation on the data in the table to which it is bound, and when an update operation on the data in the table to which it is bound is detected, the incremental data corresponding to the update operation generated by the table to which it is bound is synchronized to the incremental database, thereby achieving the purpose of synchronizing incremental data.

[0112] In this embodiment, the existing tables and newly created tables in the production library are bound to corresponding second-type triggers. During the upgrade process, each second-type trigger can detect an update operation on the data in the table bound to itself, and synchronize the incremental data generated in the table bound to itself to the incremental library. Therefore, during the upgrade process, through each second-type trigger, all incremental data generated by the production library during the upgrade process can be synchronized to the incremental library, and then the incremental library can be upgraded subsequently, which can realize the upgrade of the incremental data in the production library and improve the accuracy of the upgrade results.

[0113] As an implementation of the embodiment of the present application, the step of synchronizing the newly created table to the incremental library in the above step S102 may include:

[0114] According to the identifier and attributes of the newly created table, a table having the same identifier and attributes as those of the newly created table is constructed in the incremental library.

[0115] When a table creation operation for a production library is detected by detecting the first type of trigger, the electronic device can obtain the identifier and attributes of the new table constructed in response to the table creation operation for the production library, wherein the identifier is used to identify the new table and may be a table name; the attributes include information such as table specifications and the location of the table in the database.

[0116] The electronic device may use the acquired identifier and attributes of the newly created table to construct a table in the incremental library whose identifier is the same as the identifier of the newly created table and whose attributes are the same as the attributes of the newly created table.

[0117] For example, according to the table creation operation, a new table B named "table_new" is constructed in the main table A in the database. The electronic device can construct a new table B named "table_new" in the main table A in the incremental library according to the name of the new table and the position in the database, thereby achieving the effect of synchronizing the new table to the incremental library.

[0118] In this embodiment, when a table creation operation for the production library is detected through the first type of trigger, the electronic device can build a table with the same identifier and attributes in the incremental library based on the identifier and attributes of the newly created table, thereby achieving the purpose of synchronizing the newly created table in the production library to the incremental library.

[0119] As an implementation method of the embodiment of the present application, the incremental library is a database constructed when the production library starts to be upgraded and has the same structure as the production library;

[0120] In the above step S102, the step of synchronizing the incremental data corresponding to the update operation generated by the production library to the incremental library may include:

[0121] According to the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation and the operation, the table position in the table with the identifier in the incremental library records the target data indicated by the operation and the type of the operation.

[0122] The incremental library is a database with the same structure as the production library when the production library starts to be upgraded. That is to say, when the production library starts to be upgraded, the structure of the incremental library constructed is the same as that of the production library, the number of tables in the incremental library is the same as the number of tables in the production library, and the identifiers and attributes of each table are the same as those of the tables in the production library.

[0123] As an implementation method, since the incremental library is used to store the incremental data generated by the production library during the upgrade process, when the production library starts to be upgraded, the production library has not yet generated incremental data, and there is no data in the table in the incremental library.

[0124] When a second type of trigger detects an update operation on the data in the table to which it is bound, the second type of trigger can determine the table with the identifier in the incremental library based on the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation, and the operation, and record the target data indicated by the operation and the type of operation in the above-mentioned table position of the table.

[0125] The above update operations include insert, update and delete.

[0126] For example, the update operation is insert. When it is detected that data is inserted into the table data bound to itself, the inserted data and the insert operation are recorded in the third row and fourth column of the table with identifier A in the incremental library based on the identifier A of the table bound to itself, the table position of the inserted data (the third row and fourth column), and the insert operation.

[0127] For another example, when the update operation is update, when an update operation on the data in the table data bound to itself is detected, the updated data and the update operation are recorded in the fifth row and first column of the table with identifier A in the incremental library based on the identifier A of the table bound to itself, the fifth row and first column of the table position of the data to be operated indicated by the update operation, and the update operation.

[0128] For another example, the update operation is deletion. When a deletion operation on data in the table data to which it is bound is detected, based on the identifier A of the table to which it is bound, the first row and first column of the table position of the data to be operated indicated by the deletion operation, and the deletion operation, the first row and first column of the table with identifier A in the incremental library records the data to be operated and the deletion operation.

[0129] In this embodiment, the incremental library is a database with the same structure as the production library that is constructed when the production library starts to upgrade. The second type of trigger can record the target data indicated by the operation and the type of operation in the table position in the table with the identifier in the incremental library according to the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation, and the operation. In this way, during the upgrade process, when each second type of trigger detects an operation instruction for the data in the table to which it is bound, it can record the target data indicated by the operation and the type of operation in the corresponding position in the corresponding table in the incremental library according to the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation, and the operation. This can achieve the effect of synchronizing the incremental data generated by the production library during the upgrade process to the corresponding position in the incremental library. Subsequently, data merging can be performed according to the position of the incremental data and the type of operation, which can improve the efficiency of data merging.

[0130] As an implementation of an embodiment of the present application, the above step S102, i.e., the step of creating a second type of trigger corresponding to a newly created table generated by the table creation operation in response to the existence of a table creation operation for the production database, may include:

[0131] When the first type of trigger monitors the table creation operation for the production database, the second type of trigger creation function calls the second type of trigger creation function, so that after the new table generated by the table creation operation is created, the second type of trigger creation function creates a second type of trigger corresponding to the new table.

[0132] The first type of trigger may monitor table creation operations for a production database. For example, the first type of trigger may monitor table creation operations for the production database by monitoring a message queue.

[0133] A second-type trigger creation function is stored in the electronic device. When the first-type trigger monitors a table creation operation for a production library, the second-type trigger creation function can be called to create a second-type trigger corresponding to the new table after the new table generated by the table creation operation is created by running the second-type trigger creation function.

[0134] The second type of trigger creation function is used to implement the creation process of the second type of trigger. As an implementation method, the second type of trigger creation function is used to automatically create a second type of trigger for the newly created table after detecting the table creation operation. The implementation code is as follows:

[0135] CREATE OR REPLACE FUNCTION public.event_trigger_check_create_table()RETURNS EVENT_TRIGGER LANGUAGE plpgsql AS $$;

[0136] DECLARE;

[0137] obj record;

[0138] BEGIN;

[0139] FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() LOOP;

[0140] BEGIN;

[0141] EXECUTE format(' CREATE TRIGGER zzzzzz_import_incre_data_tg AFTERINSERT OR UPDATE OR DELETE ON %s FOR EACH ROW EXECUTE PROCEDURE import_incere_data_to_cms_incere()',obj.object_identity);

[0142] Among them, create a trigger that monitors the creation of a new table event, that is, a first-class trigger, and write the event trigger language plpgsql AS $$;

[0143] Set the DDL operation on the database to trigger the first type of trigger. The first type of trigger creates a second type of trigger for the table created by the DDL operation. The second type of trigger is triggered when an insert, update, or delete operation is detected for any row of data, and the data is synchronously updated in the incremental table according to the table identifier.

[0144] The second type of trigger creation function can also include an EXCEPTION exception handling mechanism, the code is as follows:

[0145] WHEN OTHERS THEN;

[0146] RAISE WARNING 'Create table warning%,%,TABLE_NAME:%,errorinfo:%,errocode:%',TG_EVENT,TG_TAG,obj.object_identity,SQLERRM,SQLSTATE;

[0147] END;

[0148] END LOOP;

[0149] END;

[0150] $$;

[0151] When table creation fails due to code errors or other reasons, an alarm message containing the table name and error type is triggered.

[0152] The first type of trigger listens to the table creation event for the database, and calls the second type of trigger creation function (event trigger function) when the table creation event occurs. Its implementation code is: CREATE EVENT TRIGGER a_create_event_trigger ON ddl_command_end WHEN TAG IN('CREATE TABLE') EXECUTEPROCEDURE public.event_trigger_check_create_table(); After listening to the input of the table creation operation language, the first type of trigger calls the second type of trigger creation function to build the second type of trigger for the newly created table.

[0153] In actual scenarios, after the trigger that monitors the new table creation event, that is, the first type of trigger, is created, the first type of trigger will be enabled in real time. During the upgrade process, if a new table is created in the production database, the first type of trigger will automatically create a trigger for incremental data synchronization for the new table, that is, the second type of trigger. For example, you can run the following table creation code to create a new table public.table_new in the production database and set the name and storage space of the table. After building the new table,

[0154] CREATE TABLE public.table_new (

[0155] id SERIAL PRIMARY KEY;

[0156] name VARCHAR(100); ).

[0158] The first type of trigger automatically binds the incremental data synchronization trigger (the second type of trigger) to the new table.

[0159] As an implementation method, when incremental data synchronization is not required, you can run the code DROP EVENTTRIGGER a_create_event_trigger to close the first type of trigger. Correspondingly, you can also run related code to close the second type of trigger.

[0160] In this embodiment, when the first type of trigger monitors the table creation operation for the production database, it can call the second type of trigger creation function to create the second type of trigger corresponding to the newly created table. In this way, by calling the second type of trigger creation function, the creation efficiency of the second type of trigger can be improved, thereby improving the overall upgrade efficiency.

[0161] As an implementation of an embodiment of the present application, a method for synchronizing incremental data of a database provided by the present application may further include:

[0162] After the snapshot library is upgraded, the incremental library is upgraded;

[0163] The incremental data included in the upgraded incremental library is merged into the upgraded snapshot library to obtain the upgraded production library.

[0164] Since the snapshot library is a copy of the production library in response to the production library's start upgrade instruction, upgrading the snapshot library is equivalent to upgrading the production library at the start of the upgrade. During the upgrade process, incremental data is generated in the production library. After the upgrade of the production library at the start of the upgrade is completed, this incremental data needs to be upgraded, that is, the incremental library is upgraded.

[0165] After the incremental library is upgraded, the incremental data included in the upgraded incremental library can be merged into the upgraded snapshot library. Specifically, according to the identifier of the table where the incremental data stored in the incremental library is located, the table location, the incremental data, and the type of operation, the data in the table location in the table with the identifier in the snapshot library can be updated according to the incremental data and the type of operation, so as to realize the merge of the upgraded incremental library and the upgraded snapshot library.

[0166] Since the merged value of the snapshot library and the incremental library is the production library, the upgraded incremental library and the upgraded snapshot library are merged, and the resulting database is the upgraded production library.

[0167] Exemplarily, the overall upgrade process is shown in FIG3 (a). In response to the start upgrade instruction for the production library, an incremental library and a snapshot library are created for the production library. A trigger for monitoring the creation of a new table (a first type of trigger) is added to the production library, and an incremental data synchronization trigger (a second type of trigger) is added to the table in the production library. After adding the above-mentioned trigger for monitoring the creation of a new table and the above-mentioned incremental data synchronization trigger, the incremental data generated in the production library begins to be synchronized to the incremental library. During the upgrade process, the snapshot library is first upgraded. After the snapshot library upgrade is completed, the incremental library is upgraded. After the incremental library upgrade is completed, the upgraded incremental library is merged into the upgraded snapshot library to realize the incremental data merge and obtain the upgraded production library. As shown in FIG3 (b), the snapshot library is a copy database of the production library at the beginning of the upgrade, and the incremental library is a database for storing the incremental data generated by the production library during the upgrade process. The two merge to form the production library during the upgrade process. Correspondingly, the merge of the upgraded incremental library and the upgraded snapshot library is the upgraded production library. The incremental data included in the upgraded incremental library can be merged into the upgraded snapshot library. Table A in the upgraded snapshot library is shown in Figure 3 (c). The data in the first column of the second row of Table A is a, and the data in the first column of the third row is a. Table A in the upgraded incremental library is shown in Figure 3 (d). The data in the first column of the second row of Table A is b, which is the incremental data generated by the update operation performed on the production library during the upgrade process; the data in the first column of the third row is a, which is the data indicated by the delete operation performed on the production library during the upgrade process; the upgraded incremental library and the upgraded snapshot library are merged, and Table A in the upgraded incremental library is used to update Table A in the upgraded snapshot library. Table A in the merged database is shown in Figure 3 (e). The data in the first column of the second row of Table A is b, and the data in the first column of the third row is empty. Table A in the merged database is Table A in the upgraded production library.

[0168] During the upgrade process, the production library does not need to stop providing data services to the business system, and users and business systems are unaware of the upgrade. The upgrade method that uses snapshot libraries, incremental libraries, first-class triggers, and second-class triggers to implement production library upgrades can be called an implicit upgrade method.

[0169] In this embodiment, after the snapshot library is upgraded, the incremental library can be upgraded, and the incremental data included in the upgraded incremental library can be merged into the upgraded snapshot library to obtain the upgraded production library. In this way, by creating a snapshot library and an incremental library for the production library that needs to be upgraded, and successively upgrading the snapshot library and the incremental library that stores the incremental data generated by the production library during the snapshot library upgrade process, and merging the upgraded incremental library and the upgraded snapshot library, the upgraded production library can be obtained, thereby realizing the implicit upgrade of the production library.

[0170] As an implementation method of the present application, Figure 4 As shown, the incremental data synchronization method of a database provided by the present application may also include:

[0171] S401: Obtain an access instruction, wherein the access instruction includes an identifier of a table to be accessed, and the table to be accessed includes tables in at least two databases of the production database, the snapshot database, and the incremental database.

[0172] S402: Parse the access instruction to obtain the internal table identifier and external table identifier of the table to be accessed, and determine the target database to be accessed according to the internal table identifier obtained by parsing. The external table identifier is an identifier obtained by mapping the table identifier in the associated database in advance according to a preset mapping method, the target database is the production database, the incremental database or the snapshot database, and the associated databases are two databases other than the target database.

[0173] During the snapshot library upgrade process, part of the upgrade logic will need to access at least two databases in the production library, snapshot library, and incremental library at the same time. For example, in order to verify the consistency of data during the upgrade process, three databases can be accessed at the same time to read the data in the tables of the three databases.

[0174] In the prior art, to access three databases, three links need to be established respectively, and one database needs to be accessed through each link, which undoubtedly increases memory consumption.

[0175] Based on this, in order to achieve single-link access to the production library, snapshot library and incremental library, external tables of the other two associated databases except the database itself can be constructed in the production library, snapshot library and incremental library respectively. That is, in the production library, an external table of the snapshot library and an external table of the incremental library can be established, in the snapshot library, an external table of the production library and an external table of the incremental library can be established, and in the incremental library, an external table of the production library and an external table of the snapshot library can be established, wherein each external table stores an external table identifier obtained by mapping the table identifier in the associated database according to a preset mapping method, and a mapping relationship between the actual table identifier in the associated database included in the external table and the external table identifier. For the sake of clarity, the construction method of the external table will be explained below.

[0176] Since each database in the production library, snapshot library and incremental library includes external tables of the other two databases except itself, each database in the production library, snapshot library and incremental library includes the identifiers of the tables in the production library, snapshot library and incremental library.

[0177] When you want to access tables in at least two databases among the production library, snapshot library, and incremental library at one time, the user can send an access instruction carrying the identifier of the table to be accessed based on the internal table identifier of its own table recorded in any database among the production library, snapshot library, and incremental library, and the external table identifiers of the tables in the two databases other than its own.

[0178] For example, the preset page displays the identifiers of each production library, snapshot library, and incremental library. The user can click on the production library as the database to be accessed. When the user's click operation is detected, the preset page can display the internal table identifiers AC of the tables included in the production library, and the external table identifiers DF in the external tables of the snapshot library and the incremental library. Then, the user can send access instructions to the electronic device for the tables corresponding to the selected internal table identifiers and external table identifiers by clicking on the internal table identifiers C and external table identifiers D to be accessed.

[0179] The electronic device can obtain the access instruction sent by the user, and parse the received access instruction to obtain the access instruction including the internal table identifier and the external table identifier of the table to be accessed.

[0180] Since the identification formats of internal table identification and external table identification are different, and for each database in the production library, incremental library or snapshot library, when the table identification in the associated database of the database is mapped to the external table identification according to the preset mapping method, the identification format of the external table identification of the associated database is also different for different associated databases. For example, the external table identification adds a prefix to the identification format of the internal table identification, and the prefixes of the external table identifications of the two associated databases are i and u respectively.

[0181] Next, the electronic device can determine the target database to be accessed according to the internal table identifier obtained by parsing, wherein the target database is a production database, an incremental database or a snapshot database, and the associated databases are two databases other than the target database.

[0182] S403: Accessing a table corresponding to the internal table identifier in the target database through an access link with the target database.

[0183] The electronic device can access a table with an internal table identifier in the target database through an access link between the electronic device and the target database.

[0184] S404: Based on the mapping relationship between the actual table identifier in the associated database and the external table identifier included in the pre-built external table in the target database, determine the actual table in the associated database to be accessed, and access the actual table in the associated database.

[0185] The electronic device can determine the actual table in the associated database to be accessed based on the external table identifier and the mapping relationship between the actual table identifier in the associated database included in the external table in the pre-built target database and the external table identifier, and then access the actual table in the associated database based on the external table identifier and the above mapping relationship.

[0186] Exemplarily, an access instruction "SELECT pa.column1, ipb.column1, upb.column1" sent by a user through a preset page is received. The electronic device can parse the access instruction and obtain the access instruction including the internal table identifier pa of the table to be accessed, and the external table identifiers ipb and upb. Then, based on the internal table identifier obtained by the parsing, it is determined that the target database to be accessed is the production database, and based on the two external table identifiers, it is determined that the external table identifier ipb belongs to the external table of the incremental library; upb belongs to the external table of the snapshot library.

[0187] The electronic device can access the table public.A with the internal table identifier pa in the production library through the access link with the production library, and access the first column of data of the table public.A; then, according to the external table identifier ipb, and according to the mapping relationship between the actual table identifier in the incremental library included in the pre-built external table in the production library and the external table identifier, determine the actual table cms_incre_public.B in the incremental library to be accessed, and then according to the external table identifier ipb and the above mapping relationship, access the first column of data of the actual table cms_incre_public.B in the incremental library; then, according to the external table identifier upb, and according to the pre-built The mapping relationship between the actual table identifier in the snapshot library included in the external table in the constructed production library and the external table identifier is used to determine the actual table cms_up_public.C in the snapshot library to be accessed, and then the first column of data of the actual table cms_up_public.C in the incremental library is accessed according to the external table identifier ipb and the above mapping relationship; that is, the electronic device can execute the following code according to the access link between the production library, the mapping relationship between the actual table identifier in the snapshot library included in the pre-constructed external table in the production library and the external table identifier, and the mapping relationship between the actual table identifier in the incremental library included in the pre-constructed external table in the production library and the external table identifier: FROM public.A, AS pa; cms_incre_public.B AS ipb; cms_up_public.CAS upb, thereby achieving the purpose of accessing three databases through one access link.

[0188] In this embodiment, by pre-establishing external tables of two associated databases other than the database in the production library, snapshot library, and incremental library, when the electronic device obtains the access instruction, it can determine the target database to be accessed according to the internal table identifier and external table identifier of the table to be accessed obtained by parsing the access instruction, and then access the table corresponding to the internal table identifier in the target database through the access link between the target database; and according to the mapping relationship between the actual table identifier in the associated database included in the external table in the pre-constructed target database and the external table identifier, determine the actual table in the associated database to be accessed, and access the actual table in the associated database. In this way, by establishing the external table of the associated database of the database in the database, three databases can be accessed through the access link of one database, that is, the purpose of accessing multiple databases through a single link is achieved, saving the memory resources occupied by the links loaded into the memory required to access multiple databases, saving the server memory, and simplifying the database execution and access logic of the business system during the database upgrade process.

[0189] As an implementation method of the present application, Figure 5 As shown, before the above step S401, i.e., the step of obtaining the access instruction, the incremental data synchronization method of a database provided by the present application may further include:

[0190] S501: The production database, the incremental database and the snapshot database are respectively used as target databases, and corresponding external tables of associated databases are established in the target databases.

[0191] S502: For each target database, obtain a table identifier of an actual table in a related database corresponding to the target database.

[0192] S503: Determine the external table identifier corresponding to the obtained table identifier according to a preset identifier mapping method.

[0193] S504: storing the mapping relationship between each external table identifier and the obtained table identifier in the external table.

[0194] In order to implement a method of accessing multiple databases with a single link, external tables of two other databases other than the database may be constructed for the production database, the incremental database, and the snapshot database, respectively.

[0195] Specifically, the production database, incremental database and snapshot database can be used as target databases respectively, and then the corresponding external tables of the associated databases can be established in the target database. As mentioned above, the associated databases of the target database are two databases other than the target database, that is, when the target database is the production database, the associated databases of the production database are the incremental database and the snapshot database; when the target database is the incremental database, the associated databases of the incremental database are the production database and the snapshot database; when the target database is the snapshot database, the associated databases of the snapshot database are the production database and the incremental database.

[0196] For each target database, the table identifier of the actual table in the associated database corresponding to the target database can be obtained, and the external table identifier corresponding to the obtained table identifier can be determined according to the preset identifier mapping method. The preset identifier mapping method can be set according to actual needs. For example, the database identifier can be concatenated before the table identifier to obtain the external table identifier corresponding to each table identifier in the database, etc., which is not specifically limited here.

[0197] For each associated database, after determining the external table identifier corresponding to the obtained table identifier of the associated database, the determined external table identifier and the mapping relationship between each external table identifier and the obtained table identifier can be stored in the external table of the associated database.

[0198] For each database in the production library, incremental library, and snapshot library, you can import the database as an external table into the other two databases. For example, you can import the incremental library and snapshot library as external tables into the production library, import the production library and snapshot library as external tables into the incremental library, and import the incremental library and production library as external tables into the snapshot library.

[0199] In this way, you can access three databases by using only the access link of a single database. For example, you can access the production database, incremental database, and snapshot database through the access link of the production database, the access link of the incremental database, or the access link of the snapshot database.

[0200] As an implementation method, the production database, incremental database, and snapshot database can be used as target databases respectively. Then, for each target database, use PostgreSQL's Postgre_FDW (Foreign Data Wrapper) extension function to establish the corresponding external table of the associated database. For each target database, use FDW to build the corresponding external table of the associated database, and you can import the table in the associated database into the target database, thereby realizing cross-database data query and data operation. Figure 6 As shown, the incremental library and snapshot library are imported into the production library through the FDW external table, the production library and snapshot library are imported into the incremental library through the FDW external table, and the incremental library and production library are imported into the snapshot library through the FDW external table.

[0201] For the production database, execute the code CREATE EXTENSION IF NOT EXISTS Postgre_FDW. If Postgre_FDW does not exist in the production database, the Postgre_FDW extension is created for the production database.

[0202] First, import the incremental database as an external table into the production database. According to the preset identification mapping method, the table public.A in the incremental database is mapped to cms_incre_public.A in the production database.

[0203] Specifically, you can execute the following code to import the incremental library as an external table into the production library:

[0204] CREATE SERVER cms_incer_server FOREIGN DATA WRAPPER Postgre_FDW;

[0205] OPTIONS(host '127.0.0.1', port '5432', dbname 'cms_incre', use_remote_estimate 'on');

[0206] CREATE USER MAPPING FOR postgres SERVER cms_incer_server OPTIONS(user'postgres', PASSWORD '%s');

[0207] CREATE SCHEMA cms_incre_%s;

[0208] IMPORT FOREIGN SCHEMA %s FROM SERVER cms_incer_server INTO cms_incre_%s.

[0209] Import the incremental library cms_incer_server through the foreign data wrapper Postgre_FDW, select the host host'127.0.0.1', the interface port '5432', select the dbname'cms_incre', and select to enable the use of external connections use_remote_estimate 'on'.

[0210] Select user 'postgres', create a mapping relationship between the incremental library's table identifier and the external table identifier for the production library, and set the password to '%s'; then create the incremental library's external table cms_incre_%s; import the external table identifier corresponding to the table identifier from the incremental library cms_incer_server to the incremental library's external table cms_incre_%s.

[0211] Then import the snapshot database as an external table into the production database. According to the preset identification mapping method, the table public.A in the snapshot database is mapped to cms_up_public.A in the production database.

[0212] Specifically, you can execute the following code to import the snapshot library as an external table into the production library:

[0213] CREATE SERVER cms_up_server FOREIGN DATA WRAPPER postgres_FDW;

[0214] OPTIONS(host '127.0.0.1', port '5432', dbname 'cms_up', use_remote_estimate 'on');

[0215] CREATE USER MAPPING FOR postgres SERVER cms_up_server OPTIONS(user 'postgres', PASSWORD '%s');

[0216] CREATE SCHEMA cms_up_%s;

[0217] IMPORT FOREIGN SCHEMA %s FROM SERVER cms_up_server INTO cms_up_%s.

[0218] Create the import snapshot library cms_up_server through the foreign data wrapper Postgre_FDW, select the host host'127.0.0.1', the interface port '5432', select the dbname'cms_up', and select to enable the use of external connections use_remote_estimate 'on'.

[0219] Select user 'postgres', create a mapping relationship between the incremental library's table identifier and the external table identifier for the production library, and set the password to '%s'; then create the external table cms_up_%s of the snapshot library; import the external table identifier corresponding to the table identifier from the snapshot library cms_up_server to the external table cms_up_%s of the incremental library.

[0220] For the incremental library, execute the code CREATE EXTENSION IF NOT EXISTS Postgre_FDW. If Postgre_FDW does not exist in the incremental library, create the Postgre_FDW extension for the incremental library.

[0221] First, import the production database as an external table into the incremental database. According to the preset identification mapping method, the table public.A in the production database is mapped to cms_public.A in the incremental database.

[0222] Specifically, you can execute the following code to import the production database into the incremental database as an external table:

[0223] CREATE SERVER cms_server FOREIGN DATA WRAPPER postgres_FDW;

[0224] OPTIONS(host '127.0.0.1', port '5432', dbname 'cms', use_remote_estimate 'on');

[0225] CREATE USER MAPPING FOR postgres SERVER cms_server OPTIONS(user 'postgres', PASSWORD '%s');

[0226] CREATE SCHEMA cms_%s;

[0227] IMPORT FOREIGN SCHEMA %s FROM SERVER cms_server INTO cms_%s.

[0228] Import the production database cms_incer_server through the foreign data wrapper Postgre_FDW, select the host host'127.0.0.1', the interface port '5432', select the dbname 'cms', and select to enable the use of external connections use_remote_estimate 'on'.

[0229] Select user 'postgres', create a mapping relationship between the table identifier of the production library and the external table identifier for the incremental library, and set the password to '%s'; then create the external table cms_%s of the production library; import the external table identifier corresponding to the table identifier from the production library cms_server to the external table cms_%s of the production library.

[0230] Then, the snapshot database is imported into the incremental database as an external table. According to the preset identification mapping method, the table public.A in the snapshot database is mapped to cms_up_public.A in the incremental database.

[0231] Specifically, you can execute the following code to import the snapshot library as an external table into the incremental library:

[0232] CREATE SERVER cms_up_server FOREIGN DATA WRAPPER postgres_FDW;

[0233] OPTIONS(host '127.0.0.1', port '5432', dbname 'cms_up', use_remote_estimate 'on');

[0234] CREATE USER MAPPING FOR postgres SERVER cms_up_server OPTIONS(user 'postgres', PASSWORD '%s');

[0235] CREATE SCHEMA cms_up_%s;

[0236] IMPORT FOREIGN SCHEMA %s FROM SERVER cms_up_server INTO cms_up_%s.

[0237] Create the import snapshot library cms_up_server through the foreign data wrapper Postgre_FDW, select the host host'127.0.0.1', the interface port'5432', select the dbname'cms_up', and select to enable the use of external connections use_remote_estimate 'on'.

[0238] Select user 'postgres', create a mapping relationship between the incremental library's table identifier and the external table identifier for the incremental library, and set the password to '%s'; then create the external table cms_up_%s of the snapshot library; import the external table identifier corresponding to the table identifier from the snapshot library cms_up_server to the external table cms_up_%s of the incremental library.

[0239] For the snapshot library, execute the code CREATE EXTENSION IF NOT EXISTS Postgre_FDW. If Postgre_FDW does not exist in the snapshot library, the Postgre_FDW extension is created for the snapshot library.

[0240] First, import the production database as an external table into the snapshot database. According to the preset identifier mapping method, the table public.A in the production database is mapped to cms_public.A in the snapshot database.

[0241] Specifically, you can execute the following code to import the production database into the snapshot database as an external table:

[0242] CREATE SERVER cms_server FOREIGN DATA WRAPPER postgres_FDW;

[0243] OPTIONS(host '127.0.0.1', port '5432', dbname 'cms', use_remote_estimate 'on');

[0244] CREATE USER MAPPING FOR postgres SERVER cms_server OPTIONS(user 'postgres', PASSWORD '%s');

[0245] CREATE SCHEMA cms_%s;

[0246] IMPORT FOREIGN SCHEMA %s FROM SERVER cms_server INTO cms_%s.

[0247] Import the production database cms_incer_server through the foreign data wrapper Postgre_FDW, select the host host'127.0.0.1', the interface port '5432', select the dbname 'cms', and select to enable the use of external connections use_remote_estimate 'on'.

[0248] Select user 'postgres', create a mapping relationship between the table identifier of the production database and the external table identifier for the snapshot database, and set the password to '%s'; then create the external table cms_%s of the production database; import the external table identifier corresponding to the table identifier from the production database cms_server to the external table cms_%s of the production database.

[0249] First, import the incremental database as an external table into the snapshot database. According to the preset identifier mapping method, the table public.A in the incremental database is mapped to cms_incre_public.A in the snapshot database.

[0250] Specifically, you can execute the following code to import the incremental library into the snapshot library as an external table:

[0251] CREATE SERVER cms_incer_server FOREIGN DATA WRAPPER Postgre_ FDW;

[0252] OPTIONS(host '127.0.0.1', port '5432', dbname 'cms_incre', use_remote_estimate 'on');

[0253] CREATE USER MAPPING FOR postgres SERVER cms_incer_server OPTIONS(user'postgres', PASSWORD '%s');

[0254] CREATE SCHEMA cms_incre_%s;

[0255] IMPORT FOREIGN SCHEMA %s FROM SERVER cms_incer_server INTO cms_incre_%s.

[0256] Import the incremental library cms_incer_server through the foreign data wrapper Postgre_FDW, select the host host'127.0.0.1', the interface port '5432', select the dbname 'cms_incre', and select to enable the use of external connections use_remote_estimate 'on'.

[0257] Select user 'postgres', create a mapping relationship between the incremental library's table identifier and the external table identifier for the snapshot library, and set the password to '%s'; then create the incremental library's external table cms_incre_%s; import the external table identifier corresponding to the table identifier from the incremental library cms_incer_server to the incremental library's external table cms_incre_%s.

[0258] In this embodiment, the electronic device can use the production library, incremental library and snapshot library as target databases respectively, and establish corresponding external tables of associated databases in the target databases. For each target database, obtain the table identifier of the actual table in the associated database corresponding to the target database. Then, according to the preset identifier mapping method, determine the external table identifier corresponding to the obtained table identifier, and store the external table identifier and the mapping relationship between each external table identifier and the obtained table identifier in the external table. By constructing the external tables of two associated databases other than the database in the production library, incremental library and snapshot library respectively, each database includes the identifier of the table in each database, and the mapping relationship between the table in the database and the external table identifier, so that the three databases can be accessed by using the access link of a single database and the external table stored in the database, simplifying the database access logic and saving server memory.

[0259] As an implementation of an embodiment of the present application, a method for synchronizing incremental data of a database provided by the present application may further include:

[0260] After the snapshot database upgrade is completed, each external table of the associated database stored in the target database is deleted.

[0261] After the snapshot database upgrade is completed, the external table of each associated database stored in the target database can be deleted, that is, the recorded external table identifier and the mapping relationship between the external table identifier and the table identifier of each associated database stored in the target database can be deleted.

[0262] Specifically, after the snapshot library upgrade is completed, the external tables of the snapshot library and the incremental library stored in the production library can be deleted, that is, the external table identifiers stored in the production library, the mapping relationship between the external table identifiers and the table identifiers of the snapshot library, and the mapping relationship between the external table identifiers and the table identifiers of the incremental library are deleted; the external tables of the production library and the incremental library stored in the snapshot library can be deleted, that is, the external table identifiers stored in the snapshot library, the mapping relationship between the external table identifiers and the table identifiers of the production library, and the mapping relationship between the external table identifiers and the table identifiers of the incremental library are deleted; and the external tables of the production library and the snapshot library stored in the incremental library can be deleted, that is, the external table identifiers stored in the incremental library, the mapping relationship between the external table identifiers and the table identifiers of the production library, and the mapping relationship between the external table identifiers and the table identifiers of the snapshot library are deleted.

[0263] As an implementation method, the following code can be used to delete the external table of each associated database stored in the target database after the snapshot library upgrade is completed.

[0264] When the target database is a production database, execute the following code to delete the external table identifier (cms_up_%) corresponding to the snapshot database stored in the production database, as well as the mapping relationship between the external table identifier and the table identifier of the snapshot database (cms_up_server CASCADE), to delete the external table of the snapshot database stored in the production database; delete the external table identifier (cms_incre_%) corresponding to the incremental database stored in the production database, as well as the mapping relationship between the external table identifier and the table identifier of the incremental database (cms_incer_server CASCADE), to delete the external table of the incremental database stored in the production database;

[0265] DROP SERVER IF EXISTS cms_incer_server CASCADE;

[0266] DROP SERVER IF EXISTS cms_up_server CASCADE;

[0267] DROP SCHEMA IF EXISTS cms_incre_%;

[0268] DROP SCHEMA IF EXISTS cms_up_%.

[0269] When the target database is an incremental database, execute the following code to delete the external table identifier (cms_up_%) corresponding to the snapshot database stored in the incremental database, as well as the mapping relationship between the external table identifier and the table identifier of the snapshot database (cms_up_server CASCADE), to delete the external table of the snapshot database stored in the incremental database; delete the external table identifier (cms_%;) corresponding to the production database stored in the incremental database, as well as the mapping relationship between the external table identifier and the table identifier of the production database (cms_server CASCADE), to delete the external table of the production database stored in the incremental database;

[0270] DROP SERVER IF EXISTS cms_server CASCADE;

[0271] DROP SERVER IF EXISTS cms_up_server CASCADE;

[0272] DROP SCHEMA IF EXISTS cms_%;

[0273] DROP SCHEMA IF EXISTS cms_up_%.

[0274] When the target database is a snapshot library, execute the following code to delete the external table identifier (cms_up_%) corresponding to the production library stored in the snapshot library, as well as the mapping relationship between the external table identifier and the table identifier of the production library (cms_up_server CASCADE), to delete the external table of the production library stored in the snapshot library; delete the external table identifier (cms_%;) corresponding to the incremental library stored in the snapshot library, as well as the mapping relationship between the external table identifier and the table identifier of the incremental library (cms_server CASCADE), to delete the external table of the incremental library stored in the snapshot library;

[0275] DROP SERVER IF EXISTS cms_server CASCADE;

[0276] DROP SERVER IF EXISTS cms_incre_server CASCADE;

[0277] DROP SCHEMA IF EXISTS cms_%;

[0278] DROP SCHEMA IF EXISTS cms_incre_%.

[0279] Of course, in other cases, if it is no longer necessary to implement mutual access between databases through external tables, the external tables of other databases stored in each database may also be used.

[0280] In this embodiment, after the snapshot library upgrade is completed, the electronic device can delete the external table of each associated database stored in the target database to save the storage space of each database.

[0281] Corresponding to the above-mentioned incremental data synchronization method of a database, an embodiment of the present application also provides an incremental data synchronization device of a database. The following introduces an incremental data synchronization device of a database provided by an embodiment of the present application.

[0282] like Figure 7 As shown, a device for synchronizing incremental data of a database, wherein a production library has a corresponding incremental library and a snapshot library, the production library is a database to be upgraded, the snapshot library is a copy library obtained by copying the production library in response to a start upgrade instruction of the production library, the production library is bound to a first type of trigger, and the device comprises:

[0283] An operation detection module 710 is configured to upgrade the snapshot library in response to the start upgrade instruction, and detect whether there is a table creation operation for the production library through the first type of trigger during the snapshot library upgrade process;

[0284] The trigger creation module 720 is used to create a second type of trigger corresponding to the newly created table generated by the table creation operation in response to the existence of a table creation operation for the production library, and synchronize the newly created table to the incremental library, so that when the second type of trigger detects an update operation for the data in the newly created table, the incremental data corresponding to the update operation generated by the production library is synchronized to the incremental library.

[0285] In the solution provided by the embodiment of the present application, the production library that needs to be upgraded has a corresponding incremental library and snapshot library, and the production library is bound with a first type of trigger. The electronic device upgrades the snapshot library in response to the start upgrade instruction. During the snapshot library upgrade process, the first type of trigger is used to detect whether there is a table building operation for the production library; in response to the existence of a table building operation for the production library, a second type of trigger corresponding to the newly created table generated by the table building operation is created, and the newly created table is synchronized to the incremental library, so that the second type of trigger, when detecting an update operation for the data in the newly created table, synchronizes the incremental data corresponding to the update operation produced by the production library to the incremental library. By constructing an incremental library and a snapshot library for the production library that needs to be upgraded, and upgrading the incremental library and the snapshot library, the purpose of upgrading the production library can be achieved without suspending the use of the production library. In addition, the first type of trigger is used to actively monitor the table building operation in the production library to bind the second type of trigger to the newly created table generated by the production library during the upgrade process, so that the incremental data generated in the table building operation can also be synchronized to the incremental library, thereby improving the accuracy of the incremental data synchronization, and thus improving the accuracy of the upgrade result.

[0286] As an implementation of an embodiment of the present application, the existing tables in the production library are bound to corresponding second-type triggers; each second-type trigger is used to synchronize the incremental data corresponding to the update operation generated by the production library to the incremental library when an update operation on the data in the table bound to itself is detected.

[0287] As an implementation of the embodiment of the present application, the trigger creation module 720 includes:

[0288] A construction unit is used to construct, in the incremental library, a table whose identification and attributes are respectively the same as the identification and attributes of the newly created table, according to the identification and attributes of the newly created table.

[0289] As an implementation method of the embodiment of the present application, the incremental library is a database constructed when the production library starts to be upgraded and has the same structure as the production library;

[0290] The trigger creation module 720 includes:

[0291] A type recording unit is used to record the target data indicated by the operation and the type of the operation according to the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation, and the operation, at the table position in the table with the identifier in the incremental library.

[0292] As an implementation of the embodiment of the present application, the trigger creation module 720 includes:

[0293] The function calling unit is used for the first type of trigger to call the second type of trigger creation function when monitoring the table creation operation for the production database, so that the second type of trigger creation function creates a second type of trigger corresponding to the new table after the new table generated by the table creation operation is created.

[0294] As an implementation of the embodiment of the present application, the device further includes:

[0295] An upgrade module, used for upgrading the incremental library after the snapshot library is upgraded;

[0296] The merging module is used to merge the incremental data included in the upgraded incremental library into the upgraded snapshot library to obtain the upgraded production library.

[0297] As an implementation of the embodiment of the present application, the device further includes:

[0298] An instruction acquisition module, used for acquiring an access instruction, wherein the access instruction includes an identifier of a table to be accessed, and the table to be accessed includes tables in at least two databases of the production library, the snapshot library, and the incremental library;

[0299] A parsing module, used for parsing the access instruction, obtaining the internal table identifier and external table identifier of the table to be accessed, and determining the target database to be accessed according to the internal table identifier obtained by parsing, wherein the external table identifier is an identifier obtained by mapping the table identifier in the associated database in advance according to a preset mapping method, the target database is the production database, the incremental database or the snapshot database, and the associated databases are two databases other than the target database;

[0300] An access module, used for accessing a table corresponding to the internal table identifier in the target database through an access link with the target database;

[0301] The table determination module is used to determine the actual table in the associated database to be accessed based on the mapping relationship between the actual table identifier in the associated database included in the pre-built external table in the target database and the external table identifier, and access the actual table in the associated database.

[0302] As an implementation of the embodiment of the present application, the device further includes:

[0303] An external table establishment module is used to, before the step of obtaining the access instruction, respectively use the production database, the incremental database and the snapshot database as target databases, and establish corresponding external tables of the associated database in the target databases;

[0304] An identification acquisition module, used for acquiring, for each target database, a table identification of an actual table in a related database corresponding to the target database;

[0305] An external table identifier determination module, used to determine the external table identifier corresponding to the obtained table identifier according to a preset identifier mapping method;

[0306] The storage module is used to store the mapping relationship between each external table identifier and the obtained table identifier in the external table.

[0307] As an implementation of the embodiment of the present application, the device further includes:

[0308] The deletion module is used to delete the external table of each associated database stored in the target database after the snapshot library upgrade is completed.

[0309] The present application also provides an electronic device, such as Figure 8 As shown, including:

[0310] Memory 801, used for storing computer programs;

[0311] The processor 802 is used to implement the above-mentioned incremental data synchronization method of a database when executing the program stored in the memory 801.

[0312] Furthermore, the electronic device may further include a communication bus and / or a communication interface, and the processor 802, the communication interface, and the memory 801 communicate with each other via the communication bus.

[0313] In the solution provided by the embodiment of the present application, the production library that needs to be upgraded has a corresponding incremental library and snapshot library, and the production library is bound with a first type of trigger. The electronic device upgrades the snapshot library in response to the start upgrade instruction. During the snapshot library upgrade process, the first type of trigger is used to detect whether there is a table building operation for the production library; in response to the existence of a table building operation for the production library, a second type of trigger corresponding to the newly created table generated by the table building operation is created, and the newly created table is synchronized to the incremental library, so that the second type of trigger, when detecting an update operation for the data in the newly created table, synchronizes the incremental data corresponding to the update operation produced by the production library to the incremental library. By constructing an incremental library and a snapshot library for the production library that needs to be upgraded, and upgrading the incremental library and the snapshot library, the purpose of upgrading the production library can be achieved without suspending the use of the production library. In addition, the first type of trigger is used to actively monitor the table building operation in the production library to bind the second type of trigger to the newly created table generated by the production library during the upgrade process, so that the incremental data generated in the table building operation can also be synchronized to the incremental library, thereby improving the accuracy of the incremental data synchronization, and thus improving the accuracy of the upgrade result.

[0314] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0315] The communication interface is used for communication between the above electronic device and other devices.

[0316] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0317] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0318] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of the incremental data synchronization method of any of the above-mentioned databases are implemented.

[0319] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the incremental data synchronization method of any database in the above embodiments.

[0320] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a solid-state hard disk (SSD), etc.

[0321] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0322] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, computer-readable storage medium, and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0323] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims

1. A method for synchronizing incremental data of a database, characterized in that: The production library has a corresponding incremental library and a snapshot library. The production library is a database that needs to be upgraded. The snapshot library is a copy library obtained by copying the production library in response to a start upgrade instruction of the production library. The production library is bound to a first type of trigger. The method includes: In response to the start upgrade instruction, the snapshot database is upgraded, and during the snapshot database upgrade process, the first type of trigger is used to detect whether there is a table creation operation for the production database; In response to the existence of a table creation operation for the production library, a second type of trigger corresponding to a newly created table generated by the table creation operation is created, and the newly created table is synchronized to the incremental library, so that when the second type of trigger detects an update operation for data in the newly created table, the incremental data corresponding to the update operation generated by the production library is synchronized to the incremental library; After the snapshot library is upgraded, the incremental library is upgraded; The incremental data included in the upgraded incremental library is merged into the upgraded snapshot library to obtain the upgraded production library.

2. The method according to claim 1, characterized in that The existing table in the production database is bound to a corresponding second type trigger; Each of the second-type triggers is used to synchronize the incremental data corresponding to the update operation generated by the production library to the incremental library when an update operation on the data in the table bound to itself is detected.

3. The method according to claim 1, characterized in that The step of synchronizing the newly created table to the incremental library includes: According to the identifier and attributes of the newly created table, a table having the same identifier and attributes as those of the newly created table is constructed in the incremental library.

4. The method according to any one of claims 1 to 3, characterized in that: The incremental database is a database constructed when the production database starts to be upgraded and has the same structure as the production database; The step of synchronizing the incremental data corresponding to the update operation generated by the production library to the incremental library includes: According to the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation and the operation, the table position in the table with the identifier in the incremental library records the target data indicated by the operation and the type of the operation.

5. The method according to any one of claims 1 to 3, characterized in that: The step of creating a second type of trigger corresponding to a newly created table generated by the table creation operation in response to the existence of a table creation operation for the production database includes: When the first type of trigger monitors the table creation operation for the production database, the second type of trigger creation function calls the second type of trigger creation function, so that after the new table generated by the table creation operation is created, the second type of trigger creation function creates a second type of trigger corresponding to the new table.

6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Obtaining an access instruction, wherein the access instruction includes an identifier of a table to be accessed, and the table to be accessed includes tables in at least two databases of the production library, the snapshot library, and the incremental library; Parse the access instruction to obtain the access instruction including the internal table identifier and the external table identifier of the table to be accessed, and determine the target database to be accessed according to the internal table identifier obtained by parsing, wherein the external table identifier is an identifier obtained by mapping the table identifier in the associated database in advance according to a preset mapping method, the target database is the production database, the incremental database or the snapshot database, and the associated databases are two databases other than the target database; Accessing the table corresponding to the internal table identifier in the target database through the access link between the target database and the target database; Based on the mapping relationship between the actual table identifier in the associated database and the external table identifier included in the pre-built external table in the target database, the actual table in the associated database to be accessed is determined, and the actual table in the associated database is accessed.

7. The method according to claim 6, characterized in that Before the step of obtaining the access instruction, the method further includes: The production database, the incremental database and the snapshot database are respectively used as target databases, and corresponding external tables of the associated databases are established in the target databases; For each target database, obtain a table identifier of an actual table in a related database corresponding to the target database; Determine the external table identifier corresponding to the obtained table identifier according to the preset identifier mapping method; The mapping relationship between each external table identifier and the obtained table identifier is stored in the external table.

8. The method according to claim 7, characterized in that The method further comprises: After the snapshot database upgrade is completed, each external table of the associated database stored in the target database is deleted.

9. A device for synchronizing incremental data of a database, characterized in that: The production library has a corresponding incremental library and a snapshot library, the production library is a database that needs to be upgraded, the snapshot library is a copy library obtained by copying the production library in response to a start upgrade instruction of the production library, the production library is bound to a first type of trigger, and the device includes: an operation detection module, configured to upgrade the snapshot library in response to the start upgrade instruction, and during the snapshot library upgrade process, detect whether there is a table creation operation for the production library through the first type of trigger; A trigger creation module is used to create a second type of trigger corresponding to a newly created table generated by the table creation operation in response to the existence of a table creation operation for the production library, and synchronize the newly created table to the incremental library, so that when the second type of trigger detects an update operation for data in the newly created table, the incremental data corresponding to the update operation generated by the production library is synchronized to the incremental library; An upgrade module, used for upgrading the incremental library after the snapshot library is upgraded; The merging module is used to merge the incremental data included in the upgraded incremental library into the upgraded snapshot library to obtain the upgraded production library.

10. The device according to claim 9, characterized in that The existing tables in the production library are bound to corresponding second-type triggers; each of the second-type triggers is used to synchronize the incremental data corresponding to the update operation generated by the production library to the incremental library when an update operation on the data in the table bound to itself is detected; The trigger creation module includes: A construction unit, configured to construct, in the incremental library, a table whose identification and attributes are respectively the same as those of the newly created table, according to the identification and attributes of the newly created table; The incremental database is a database constructed when the production database starts to be upgraded and has the same structure as the production database; The trigger creation module includes: A type recording unit, configured to record the target data indicated by the operation and the type of the operation according to the identifier of the table to which it is bound, the table position of the data to be operated indicated by the update operation, and the operation, in the table position in the table with the identifier in the incremental library; The trigger creation module includes: The function calling unit is used for the first type of trigger to call the second type of trigger creation function when monitoring the table creation operation for the production database, so that the second type of trigger creation function creates a second type of trigger corresponding to the newly created table after the newly created table generated by the table creation operation is created; The device also includes: An instruction acquisition module, used for acquiring an access instruction, wherein the access instruction includes an identifier of a table to be accessed, and the table to be accessed includes tables in at least two databases of the production library, the snapshot library, and the incremental library; A parsing module, used for parsing the access instruction, obtaining the internal table identifier and external table identifier of the table to be accessed, and determining the target database to be accessed according to the internal table identifier obtained by parsing, wherein the external table identifier is an identifier obtained by mapping the table identifier in the associated database in advance according to a preset mapping method, the target database is the production database, the incremental database or the snapshot database, and the associated databases are two databases other than the target database; An access module, used for accessing a table corresponding to the internal table identifier in the target database through an access link with the target database; A table determination module, configured to determine the actual table in the associated database to be accessed based on the mapping relationship between the actual table identifier in the associated database and the external table identifier included in the pre-built external table in the target database, and access the actual table in the associated database; The device also includes: An external table establishment module is used to, before the step of obtaining the access instruction, respectively use the production database, the incremental database and the snapshot database as target databases, and establish corresponding external tables of the associated database in the target databases; An identification acquisition module, used for acquiring, for each target database, a table identification of an actual table in a related database corresponding to the target database; An external table identifier determination module, used to determine the external table identifier corresponding to the obtained table identifier according to a preset identifier mapping method; A storage module, used for storing the mapping relationship between each external table identifier and the obtained table identifier in the external table; The device also includes: The deletion module is used to delete the external table of each associated database stored in the target database after the snapshot library upgrade is completed.

11. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-8 when executing a program stored in a memory.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • DDL synchronization method and device for PostgreSQL database, equipment and medium

    CN112231407A

  • Database-based data fusion method and device, electronic equipment and storage medium

    CN116955369A