A database synchronization method and apparatus
Patent Information
- Application Number
- CN202211088702.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-07
- Publication Date
- 2026-10-23
- Estimated Expiration
- 2042-09-07
AI Technical Summary
[0006]本申请实施例提供了一种数据库同步方法和装置,以至少解决现有技术中数据库在进行数据同步时所存在的同步效率比较低的问题
[0011]在本申请实施例中,采用了获取源数据库下的用于存储物理数据库表的存储单元;获取目标数据库下的用于存储物理数据库表的存储单元;识别出所述源数据库和所述目标数据库中保存有相同物理数据库表的存储单元;将数据从所述源数据库的存储单元同步到所述目标数据库的存储单元,其中,进行数据同步的源数据库的存储单元和目标数据库的存储单元上保存有相同的物理数据库表。通过本申请解决了现有技术中数据库在进行数据同步时所存在的同步效率比较低的问题,进而降低了数据库数据同步的延迟,提高了数据库数据同步的效率。
Smart Images

Figure CN115587141B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of databases, and more specifically, to a database synchronization method and apparatus. Background Technology
[0002] With the rise of cloud computing, the demand for massive data storage and management is constantly increasing. In response, many databases designed for big data management have emerged in recent years, utilizing hardware to build large-scale server clusters to provide massive data storage and management capabilities.
[0003] The data in a database will ultimately still be stored in physical storage media. For example, a distributed database system typically uses multiple storage units (e.g., multiple servers) to store data. Each storage unit (e.g., each server) can be located in a separate place. Each storage unit may contain a complete or partial copy of the database and has its own local database. Multiple storage units located in different locations are interconnected through a network to form a complete, global, logically centralized, and physically distributed large database.
[0004] Replication mechanisms, as a key technology for ensuring the reliability and availability of database services, have been widely used in various emerging large-scale database systems, especially distributed database systems. In practical applications, data reliability and availability are guaranteed by synchronizing the data in the primary database with the data in the replica database.
[0005] Modern database systems, especially distributed database systems, are typically characterized by large data storage volumes and high real-time write volumes. Current technologies for data synchronization generally involve copying data from the source database to the target database. In this approach, the source database first collects and summarizes the data to be synchronized from various storage units to generate logical tables that need to be synchronized. Then, the data in these logical tables is synchronized to the target database. The target database, based on the synchronized logical tables, locates the storage unit containing the logical table and then distributes the logical table across the various distributed storage units. This update method requires converting data stored in physical storage units into logical tables before synchronization, resulting in relatively low synchronization efficiency. Summary of the Invention
[0006] This application provides a database synchronization method and apparatus to at least solve the problem of low synchronization efficiency in the prior art when synchronizing databases.
[0007] According to one aspect of this application, a database synchronization method is provided, comprising: obtaining storage units in a source database for storing physical database tables; obtaining storage units in a target database for storing physical database tables; identifying storage units in the source database and the target database that store the same physical database tables; and synchronizing data from the storage units in the source database to the storage units in the target database, wherein the storage units in the source database and the storage units in the target database storing the same physical database tables.
[0008] According to another aspect of this application, a database synchronization apparatus is also provided, comprising: a first acquisition module for acquiring storage units in a source database for storing physical database tables; a second acquisition module for acquiring storage units in a target database for storing physical database tables; an identification module for identifying storage units in the source database and the target database that store the same physical database tables; and a synchronization module for synchronizing data from storage units in the source database to storage units in the target database, wherein the storage units in the source database and the storage units in the target database storing the same physical database tables.
[0009] According to another aspect of this application, an electronic device is also provided, including a memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the above-described method steps.
[0010] According to another aspect of this application, a readable storage medium is also provided, on which computer instructions are stored, wherein the computer instructions, when executed by a processor, implement the above-described method steps.
[0011] In this embodiment, the method involves: acquiring storage units in a source database for storing physical database tables; acquiring storage units in a target database for storing physical database tables; identifying storage units in both the source and target databases that store the same physical database tables; and synchronizing data from the storage units in the source database to the storage units in the target database. The storage units in both the source and target databases store the same physical database tables. This invention solves the problem of low synchronization efficiency in existing database technologies, thereby reducing data synchronization latency and improving data synchronization efficiency. Attached Figure Description
[0012] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0013] Figure 1 This is a flowchart of a database synchronization method according to an embodiment of this application;
[0014] Figure 2 This is a schematic diagram illustrating the parent-child task operation relationship under pre-check according to an embodiment of this application;
[0015] Figure 3 This is a flowchart of a database synchronization method based on parent-child tasks according to an embodiment of this application; and,
[0016] Figure 4 This is a flowchart illustrating the identification of storage units having the same physical database tables according to an embodiment of this application. Detailed Implementation
[0017] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0018] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0019] In a database system (using a distributed database system as an example below), tables are stored in storage units. In the following embodiments, a storage unit refers to a physical device or physical unit used for database data storage. Data stored in multiple storage units constitutes the entire database. Although database tables are stored in different storage units, the table a user sees when using a table in the database is a complete table. The data of this table is actually stored in multiple storage units (tables stored in storage units are called physical database tables or physical tables). The table that the user sees or operates on is a logical table generated by the database after integrating the physical tables. That is, a logical table may be formed by integrating one or more physical tables. In the following embodiments, the meanings of "physical" and "logical" are the same as those of "physical table" and "logical table," respectively. "Physical" refers to the data actually stored on a physical device or physical unit (e.g., database tables), and "logical" refers to the data that is integrated from the data actually stored on the physical device or physical unit and then used by the user for operation or processing.
[0020] In the following implementation, the two databases (e.g., two distributed databases) undergoing data synchronization are referred to as the source database and the target database. During synchronization, data is transferred from the source database to the target database. In existing technologies, logical tables are used for data synchronization between two databases. This involves reading data from the logical tables in the source database and copying it to the logical tables in the target database. This logical table-based synchronization method involves a conversion process from logical tables to physical tables. Specifically, the source database first collects and summarizes the data to be synchronized from various storage units to generate a logical table to be synchronized. Then, it synchronizes the data in the logical table to the target database. The target database then locates the storage unit containing the synchronized logical table and distributes the logical table to the appropriate storage unit. This conversion between logical tables and physical tables occurs in both the source and target databases, thus reducing the efficiency of database synchronization.
[0021] To address the aforementioned issues, a database synchronization method is provided in the following embodiments. It should be noted that these embodiments can be applied to various types of databases. Due to the large number of storage units and the amount of data stored in distributed databases, applying these embodiments to distributed databases can significantly improve database synchronization efficiency. The following explanation uses a distributed database as an example. In the following embodiments, storage units can also be referred to as sub-instances or sub-partitions. Figure 1 This is a flowchart of a database synchronization method according to an embodiment of this application, such as... Figure 1 As shown below, Figure 1 The steps included in the process will be explained.
[0022] Step S102: Obtain the storage unit under the source database used to store the physical database tables.
[0023] Step S104: Obtain the storage unit under the target database used to store the physical database tables.
[0024] Although steps S102 and S104 are numbered sequentially, this does not mean that step S102 is executed before step S104. Alternatively, step S104 can be executed first, followed by step S102. In other words, unless explicitly stated or logically restricted, the step numbers in the following embodiments do not limit the order of execution of the steps.
[0025] Step S106: Identify storage units in the source database and the target database that contain the same physical database tables.
[0026] It should be noted that this step involves the use of the same physical database table. "Same" here means the physical database table is identical, but the content within the table may not be the same. The data mentioned in step S108 refers to the content of this table. For example, consider a table named "User Information" with three fields: name, age, and gender. This User Information table is stored in storage unit A of the source database, containing 100 records; it is also stored in storage unit B of the target database, containing 50 records. In this case, the User Information tables stored in storage units A and B are the same physical database table, and the data within them is the data that needs to be synchronized in step S108.
[0027] Step S108: Synchronize data from the storage unit of the source database to the storage unit of the target database, wherein the storage units of the source database and the target database store the same physical database tables.
[0028] In the above steps, when data synchronization is required between the source and target databases, storage units containing the same physical database tables are located in both the source and target databases. Data synchronization is then performed between these storage units, directly synchronizing the physical database tables from the source database's storage units to the target database's storage units. This eliminates the need to convert physical database tables into logical tables before synchronization; instead, physical database tables are synchronized directly between storage units. Therefore, this approach solves the problem of low synchronization efficiency in existing database technologies, thereby reducing latency and improving efficiency.
[0029] In step S106 above, it involves identifying storage units in the source database and the target database that store the same physical database tables. Since there are many types of databases, the way different types of databases store data in storage units may differ. In an optional implementation, as a more general identification method for various types of data, the physical database tables stored in each storage unit of the source database and the target database can be traversed, and the names of the physical database tables stored in these storage units can be recorded. If the storage units of the source database and the target database store physical database tables with the same names, then these two storage units can directly synchronize data. That is, in this optional implementation, identifying storage units in the source database and the target database that store the same physical database tables may include the following steps: obtaining the name of the physical database table stored in each storage unit of the source database; obtaining the name of the physical database table stored in each storage unit of the target database; and identifying the storage units of the source database and the target database that store physical database tables with the same names as storage units storing the same physical database tables. This optional method can identify storage units that store the same physical database tables regardless of the database type, improving adaptability to different types of databases.
[0030] For distributed databases that require data synchronization, their database structure and storage unit distribution are typically identical. For example, a source database might have three storage units: A1, A2, and A3, where A1 stores table 1, A2 stores tables 2 and 3, and A3 stores table 4. The target database, generally acting as a backup of the source database, also typically has three storage units: B1, B2, and B3, where B1 stores table 1, B2 stores tables 2 and 3, and B3 stores table 4. This approach is common in source and target databases that function as primary and backup databases. Considering this scenario, as an alternative implementation, identification information can be used to identify the physical database tables stored in a storage unit. If two storage units store the same database tables, their identification information is the same; if they store different database tables, their identification information is different. When using identification information, it is possible to identify whether storage units store the same physical database table. Specifically, in this optional embodiment, identifying storage units in the source database and the target database that store the same physical database table may include the following steps: obtaining identification information corresponding to each storage unit in the source database; obtaining identification information corresponding to each storage unit in the target database, wherein storage units storing the same physical database table have the same identification information; and identifying the storage units in the source database and the target database that have the same identification information as storage units storing the same physical database table. With this optional embodiment, it is no longer necessary to traverse the names of the physical database tables stored in each storage unit; the identification information alone is sufficient to determine whether the physical database tables stored in two storage units are the same, further improving identification efficiency.
[0031] For example, in a distributed database, a group key can be used as an identifier to obtain the group key of a sub-instance (i.e., storage unit) of the source database and the group key of a sub-instance of the target database. If the group keys of two sub-instances are the same, then these two sub-instances are regarded as sub-instances that store the same physical database table.
[0032] The above provides two optional methods for identifying storage units containing the same physical database table. Considering the possibility of identification errors (although the probability of this is relatively low), as another optional implementation, the identified storage units can be confirmed by the user. That is, after identifying the storage units in the source database and the target database that contain the same physical database table, the following step can be included: displaying the storage units of the source database and the target database containing the same physical database table through a user interface, where the storage units of the source database and the target database with the same physical database table can be modified. In this optional implementation, if the user modifies the correspondence between the storage units of the source database and the target database, data synchronization is performed on the corresponding storage units in the source database and the target database according to the modified correspondence. Considering that requiring user confirmation after each identification would be cumbersome, data synchronization can also be performed directly after identification. If an anomaly occurs during data synchronization, the identification result is then displayed to the user.
[0033] Figure 4 This is a flowchart illustrating the identification of storage units having the same physical database tables according to embodiments of this application, such as... Figure 4 As shown, the identification process includes the following steps: First, select whether to use the default identification algorithm or the configured algorithm. This step can be determined based on the database type. For example, when configuring the algorithm, you can configure the type of distributed database used by the algorithm, and then find the corresponding algorithm based on the type of distributed database. Figure 4 If an algorithm based on GroupKey is found, the GroupKey of the source sub-instance / partition is obtained, and then the GroupKey of the target sub-instance / partition is obtained. The GroupKeys are matched; if they match, they form a one-to-one pair of source and target sub-instances / partitions. After matching according to the algorithm, the result is given to the user for confirmation. If no matching algorithm is found for this type of distributed database, the default algorithm is used. Within this default algorithm, the source database (i.e.,...) is retrieved. Figure 4 The names of all database tables in all sub-instances / partitions of the source distributed database are used to obtain the target database (i.e., Figure 4The algorithm matches the table names in all sub-instances / partitions of the target distributed database. Sub-instances / partitions with the same table name are those to be synchronized. Regardless of whether the default or configured algorithm is used, the matching results are submitted to the user for confirmation. If the user confirms, the process ends; otherwise, the adjusted matching results are used. This approach improves processing efficiency, provides handling for exceptions, and enhances the user experience.
[0034] After identifying storage units that store the same physical database tables, data synchronization can begin. Some distributed databases do not provide the ability to establish links between two storage units. In such cases, users must manually establish links for data synchronization by entering commands, which is inefficient. In an optional implementation, link establishment can be automatic after identifying storage units that store the same physical database tables. Synchronizing data from the source database's storage units to the target database's storage units can include the following steps: establishing links between each group of storage units, where the source database's storage units and the target database's storage units that store the same physical database tables are considered as one group; and synchronizing data between each group of storage units using the established links. This optional method enables automatic link establishment, thus ensuring reduced data synchronization latency.
[0035] During data synchronization from the source database to the target database, a separate task can be created for each group of storage units. This allows for the creation of multiple tasks when synchronizing data across multiple groups of storage units, providing a foundation for parallel processing of data synchronization across these groups. In this optional implementation, multiple tasks created for multiple groups of storage units can be executed in parallel. Parallel processing further improves data synchronization efficiency and shortens synchronization time.
[0036] After using multiple tasks, management of these tasks becomes necessary. In another optional implementation, considering that the function of multiple tasks is to synchronize data between two storage units, a parent task can be created for easier management, and then all the aforementioned tasks can be treated as child tasks of this parent task. That is, in this optional implementation, synchronizing data from the storage unit of the source database to the storage unit of the target database may include the following steps: creating a parent task, and creating a child task under the parent task for data synchronization of each group of storage units; synchronizing data for each group of storage units through each child task. During data synchronization, multiple groups of storage units typically need to be synchronized. In this case, using parent-child tasks allows the parent task to automatically establish a data synchronization link for each group of storage units, improving synchronization efficiency.
[0037] For parent and child tasks, child tasks are derived from parent tasks and can inherit the basic attributes and methods of the parent task. This means that when task attributes need modification, changes to the parent task will affect all child tasks. Furthermore, the completion status of the parent task depends on the completion status of the child tasks. A simple logic is that the parent task is only considered complete when all child tasks are finished; that is, the status of the parent task indicates whether all synchronization tasks have been completed. Therefore, the parent-child task approach allows for better monitoring and control of data synchronization between multiple sets of storage units.
[0038] The synchronization process described above can be applied to both augmented and full data. Synchronizing data from the storage unit of the source database to the storage unit of the target database can include the following steps: obtaining the full data and / or incremental data to be synchronized from the storage unit of the source database; and synchronizing the full data and / or incremental data to the storage unit of the target database. In this optional embodiment, synchronizing full data is referred to as full synchronization, and synchronizing incremental data is referred to as incremental synchronization. Full synchronization refers to synchronizing all existing data up to the current time at the start of data synchronization, where data is retrieved by directly reading existing data. Incremental synchronization refers to synchronizing data that has been incrementally written since the last synchronization at the start of data synchronization, typically by reading and parsing the source database write logs.
[0039] Whether it's full synchronization or incremental synchronization, anomalies may occur during the synchronization process. The most common issue is connection failures between the source and target databases. One approach is to address these anomalies after they occur, but this affects the synchronization progress. In another alternative implementation, a pre-check can be performed, and synchronization can proceed only after the check confirms no problems. Synchronizing data from the source database's storage unit to the target database's storage unit can include the following steps: obtaining information for connecting the source and target databases; checking the connectivity based on the information; and synchronizing data from the source database's storage unit to the target database's storage unit after the check passes. In this alternative implementation, this check can be called a pre-check; that is, before data synchronization, checks can be performed on the source and target databases regarding connectivity, account permissions, and / or database configuration, etc., all collectively referred to as pre-checks.
[0040] Figure 2 This is a schematic diagram illustrating the parent-child task execution relationship under pre-check according to an embodiment of this application, as shown below. Figure 2 As shown, the source database comprises multiple sub-instances or partitions (hereinafter referred to as sub-instances / partitions). Figure 2 The image shows sub-instance / partition 1 and sub-instance / partition 2 (the remaining sub-instances / partitions are not shown). The target database (Target DB) also includes multiple sub-instances or partitions. Sub-instance / partition 1 in the source database and the target distributed database are storage units with the same physical database tables. Similarly, the two sub-instances / partitions 2 are also storage units with the same physical database tables. After establishing the parent task, two sub-tasks are created for the data synchronization of sub-instance / partition 1 and sub-instance / partition 2: Sub-task 1 and Sub-task 2. Sub-task 1 and Sub-task 2 perform full synchronization or incremental synchronization as needed (synchronization can also be called migration). Figure 2 In the process, the parent task, child task 1, and child task 2 all undergo pre-checks. If any task fails the pre-check, it is considered a failed pre-check and no further data synchronization will be performed. If the parent task, child task 1, and child task 2 all pass the pre-checks, then data synchronization will proceed.
[0041] It should be noted that the source and target databases are homogeneous. Because their structures are identical, the subtask directly reads full and incremental data from the source database and writes it to the target database. This process does not require any proxy layer or conversion between logical and physical database tables, resulting in faster speed. If the source and target databases are heterogeneous, the data structure of the source database can first be converted to match that of the target database before using the synchronization method described above.
[0042] Figure 3 This is a flowchart of a database synchronization method based on parent-child tasks according to an embodiment of this application. Figure 3 An alternative embodiment employing parent-child tasks is shown, such as... Figure 3 As shown, this database synchronization method based on parent-child tasks may include the following steps:
[0043] Step 1: Obtain information about the source database and the sub-instance / partition information used in the following steps. This source database information includes the instance identifier (ID), instance connection string (which includes information used to connect to the database), username, password, and other information used to create a database connection.
[0044] Step 2: Obtain information about the target database and the sub-instance / partition information used in the following steps. This source database information includes the instance identifier (ID), instance connection string (which includes information used to connect to the database), username, password, and other information used to create a database connection.
[0045] Step 3: Identify the one-to-one correspondence between sub-instances / partitions in the source database and the target database, which is used to determine the sub-instances / partitions for establishing a synchronization link between the source database and the target database in subsequent steps.
[0046] Step 4: Based on the sub-instance / partition information and corresponding relationship information of the source database and target database obtained in Steps 1 to 3, establish a parent task for synchronization and multiple sub-tasks for synchronization.
[0047] Step 5: The parent task and child task perform pre-checks simultaneously. If the pre-check fails, the process ends and the task creation fails. If the pre-check passes, multiple child tasks concurrently begin synchronizing full and incremental data.
[0048] In step 3 above, an interface can be provided to obtain the one-to-one correspondence between the source database and the target database instances / partitions. Through this interface, users can configure the algorithm for identifying storage units with the same physical database tables based on the specific implementation of the database instances / partitions. In this optional embodiment, a default algorithm is also configured for this interface. If a corresponding algorithm is configured for a certain type of distributed database, that algorithm is used; otherwise, the default algorithm is used.
[0049] For the default algorithm, the source database and target database information obtained in step 2 are used to connect to the source database and target database, and the table names in the physical sub-instances / partitions are read. The table names are matched, and a set of source sub-instances / partitions and target sub-instances / partitions with matching table names are considered to be a set of physical instances / partitions for data synchronization.
[0050] If other algorithms are configured, such as one that uses GroupKey for matching, then the GroupKeys of the source and target sub-instances / partitions are retrieved. Matching GroupKeys indicate a one-to-one correspondence between the source and target sub-instances / partitions. Users can also correct the matching results. After identifying and matching a set of source and target sub-instances / partitions using the default or configured algorithm, the matching results are displayed to the user. Before the connection is officially established, users can correct the matching results to ensure their accuracy.
[0051] Figure 4 This is a flowchart illustrating the identification of storage units having the same physical database tables according to embodiments of this application, such as... Figure 4 As shown, the identification process includes the following steps: First, select whether to use the default identification algorithm or the configured algorithm. This step can be determined based on the database type. For example, when configuring the algorithm, you can configure the type of distributed database used by the algorithm, and then find the corresponding algorithm based on the type of distributed database. Figure 4If an algorithm based on GroupKey is found, the GroupKey of the source sub-instance / partition is obtained, and then the GroupKey of the target sub-instance / partition is obtained. The GroupKeys are matched; if they match, they form a one-to-one pair of source and target sub-instances / partitions. After matching according to the algorithm, the matching result is submitted to the user for confirmation. If no matching algorithm configured for this type of distributed database is found, the default algorithm is used. In this default algorithm, the names of all tables in all sub-instances / partitions of the source database are obtained, and the names of all tables in all sub-instances / partitions of the target database are obtained. Matching is performed using these table names; a pair of source and target sub-instances / partitions with the same table name is considered for synchronization. Regardless of whether the default or configured algorithm is used, the matching result is submitted to the user for confirmation. If the user confirms, the identification process ends; if the user makes adjustments, the adjusted matching result is used.
[0052] In steps 1 to 5 above, a one-to-one synchronization method is used between the sub-instances / partitions of the source database and the sub-instances / partitions of the target database. Both the source and target databases directly read and write to the physical tables on the sub-instances / partitions. Without considering efficiency, direct writing to the target database is possible. However, this requires converting the physical table information read from the source database into logical tables, resulting in some performance overhead.
[0053] In the above optional implementation, by automatically identifying the one-to-one correspondence between the source database and the target database sub-instances or partitions, a synchronization link for all physical database tables from the source to the target is established at once. This reduces both the cost of establishing and maintaining the link. Furthermore, since both the source and target databases directly read and write physical database tables on the sub-instances / partitions, latency is significantly reduced. Additionally, the above optional implementation also supports both full and incremental synchronization.
[0054] It should be noted that the source database and target database mentioned above can be distributed databases. Of course, other types of databases can also be used with the synchronization scheme described above.
[0055] In this embodiment, an electronic device is provided, including a memory and a processor. The memory stores a computer program, and the processor is configured to run the computer program to perform the methods described in the above embodiments.
[0056] The aforementioned program can run on a processor or be stored in memory (or computer-readable medium). Computer-readable medium includes both permanent and non-permanent, removable and non-removable media, and information storage can be achieved by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable medium does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0057] These computer programs may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes can be implemented using different modules, and different steps can be implemented using different modules.
[0058] This embodiment provides such an apparatus. A database synchronization apparatus includes: a first acquisition module for acquiring storage units in a source database for storing physical database tables; a second acquisition module for acquiring storage units in a target database for storing physical database tables; an identification module for identifying storage units in the source database and the target database that store the same physical database tables; and a synchronization module for synchronizing data from the storage units in the source database to the storage units in the target database, wherein the storage units in the source database and the storage units in the target database storing the same physical database tables.
[0059] The system or apparatus is used to implement the functions of the methods in the above embodiments. Each module in the system or apparatus corresponds to each step in the method, as has been described in the method and will not be repeated here.
[0060] For example, the identification module is used to obtain the name of the physical database table stored in the storage unit of each source database; obtain the name of the physical database table stored in the storage unit of each target database; and classify the storage units of the source database and the target database that store physical database tables with the same name as storage units that store the same physical database tables; and / or, the identification module is used to obtain the identification information corresponding to the storage unit of each source database; obtain the identification information corresponding to the storage unit of each target database, wherein the storage units that store the same physical database tables have the same identification information; and classify the storage units of the source database and the target database that have the same identification information as storage units that store the same physical database tables.
[0061] For example, it also includes: a display module for displaying the storage units of the source database and the target database that store the same physical database tables through a user interface, wherein the storage units of the source database and the target database that have the same physical database tables can be modified in the user interface.
[0062] Optionally, the synchronization module is configured to establish links between each group of storage units, wherein the storage units of the source database and the target database that store the same physical database tables are considered as a group of storage units; data synchronization is performed on each group of storage units through the links established between them; and / or, the synchronization module is configured to establish a task for each group of storage units when there are multiple groups of storage units that need to be synchronized, wherein the storage units of the source database and the target database that store the same physical database tables are considered as a group of storage units; data is synchronized from the storage unit of the source database of that group of storage units to the storage unit of the target database of that group of storage units through the task corresponding to each group of storage units, wherein multiple groups of storage units correspond to multiple The tasks described above can be executed in parallel; and / or, the synchronization module is used to establish a parent task and establish a sub-task under the parent task for data synchronization of each group of storage units; perform data synchronization for each group of storage units through each sub-task; and / or, the synchronization module is used to obtain the full data and / or incremental data to be synchronized from the storage units of the source database; synchronize the full data and / or incremental data to the storage units of the target database; and / or, the synchronization module is used to obtain information for connecting the source database and the target database; check whether the connection to the source database and the target database can be made based on the information; after the check is passed, synchronize the data from the storage units of the source database to the storage units of the target database.
[0063] The above optional implementation methods solve the problem of low synchronization efficiency in the prior art when databases synchronize data, thereby reducing the latency of database data synchronization and improving the efficiency of database data synchronization.
[0064] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A database synchronization method, comprising: Obtain the storage unit under the source database used to store physical database tables; Obtain the storage units under the target database used to store physical database tables; wherein the source database and the target database have the same structure and the same distribution of storage units; Obtain the name of the physical database table stored in the storage unit of each source database, obtain the name of the physical database table stored in the storage unit of each target database, and designate the storage units of the source database and the target database that store physical database tables with the same name as storage units that store the same physical database tables; when synchronizing data from the storage unit of the source database to the storage unit of the target database, the data in the same physical database table is synchronized to the corresponding storage unit in the target database. In this process, the storage units of the source database and the target database, which are used for data synchronization, store the same physical database tables.
2. The method according to claim 1, wherein, The storage units that identify the source database and the target database as containing the same physical database tables include: Obtain the identification information corresponding to the storage unit of each of the source databases; Obtain the identification information corresponding to the storage unit of each target database, wherein storage units that store the same physical database table have the same identification information; Storage units of the source database and the target database that have the same identification information are used as storage units that store the same physical database tables.
3. The method according to claim 1, wherein, After identifying storage units in the source database and the target database that contain the same physical database tables, the method further includes: The storage units of the source database and the target database, which contain the same physical database tables, are displayed through a user interface, which allows modification of the storage units of the source database and the target database.
4. The method according to any one of claims 1 to 3, wherein, When synchronizing data from the storage unit of the source database to the storage unit of the target database, data in the same physical database table is synchronized to the corresponding storage unit in the target database; including: Links are established between each group of storage units, where the storage units of the source database and the target database that contain the same physical database tables form a group of storage units. Data synchronization between storage units is achieved through links established between each group of storage units.
5. The method according to any one of claims 1 to 3, wherein, When synchronizing data from the storage unit of the source database to the storage unit of the target database, data in the same physical database table is synchronized to the corresponding storage unit in the target database; including: When there are multiple groups of storage units that need to be synchronized, a task is created for each group of storage units. The storage units of the source database and the target database that contain the same physical database tables are considered as one group of storage units. Data is synchronized from the storage unit of the source database to the storage unit of the target database of the same group through the task corresponding to each group of storage units, wherein multiple tasks corresponding to multiple groups of storage units can be executed in parallel.
6. The method according to claim 5, wherein, When synchronizing data from the storage unit of the source database to the storage unit of the target database, data in the same physical database table is synchronized to the corresponding storage unit in the target database; including: Establish a parent task, and create a child task under the parent task for data synchronization of each group of storage units; Data is synchronized for each group of storage units through each subtask.
7. The method according to any one of claims 1 to 3, wherein, When data is synchronized from the storage unit of the source database to the storage unit of the target database, data in the same physical database table is synchronized to the corresponding storage unit in the target database. include: Obtain information used to connect the source database and the target database; Based on the information provided, a check is performed to determine whether a connection can be established with the source database and the target database. After the check is passed, the data is synchronized from the storage unit of the source database to the storage unit of the target database.
8. The method according to any one of claims 1 to 3, wherein, When synchronizing data from the storage unit of the source database to the storage unit of the target database, data in the same physical database table is synchronized to the corresponding storage unit in the target database; including: Obtain the full and / or incremental data to be synchronized from the storage unit of the source database; The full data and / or incremental data are synchronized to the storage unit of the target database.
9. A database synchronization device, comprising: The first acquisition module is used to acquire the storage units under the source database used to store physical database tables; The second acquisition module is used to acquire the storage unit under the target database used to store physical database tables; The identification module is used to obtain the name of the physical database table stored in the storage unit of each source database, obtain the name of the physical database table stored in the storage unit of each target database, and identify the storage units of the source database and the target database that store physical database tables with the same name as storage units that store the same physical database tables. The synchronization module is used to synchronize data from the storage unit of the source database to the storage unit of the target database, wherein data in the same physical database table is synchronized to the corresponding storage unit in the target database; wherein the storage units of the source database and the target database storing the same physical database table are stored in the storage units of the source database and the target database.
10. An electronic device comprising a memory and a processor; wherein, The memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the steps of the method according to any one of claims 1 to 8.
11. A readable storage medium having computer instructions stored thereon, wherein, When executed by a processor, the computer instructions implement the steps of the method described in any one of claims 1 to 8.
Citation Information
Patent Citations
Data migration method and device
CN114116681A