High-speed data import and export method based on openGauss platform
By adopting a high-speed data import and export method on the openGauss platform, by copying table data files and using MVCC features to modify tuple information, the problem of low data import and export efficiency in the existing technology is solved, significantly improving performance and reducing maintenance costs.
Patent Information
- Application Number
- CN202111214816.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-19
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-10-19
AI Technical Summary
Existing databases are inefficient in the data import and export process, especially for tables with large amounts of data. The import and export efficiency achieved through SQL commands cannot meet the requirements for fast data exchange, resulting in high maintenance costs.
The high-speed data import and export method based on the openGauss platform is used to export and import by copying the table data file, and uses the MVCC feature to modify the tuple information in the data file, replacing the traditional logical import and export method.
Significantly improves the performance of data import and export, reduces data maintenance costs, especially the time-consuming export and import of large table object data is greatly reduced, and improves the efficiency of object migration between databases.
Smart Images

Figure CN113886395B
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of database management system and computer software, and in particular relates to a high-speed data import and export method based on openGauss platform. Background Art
[0002] In the information age, massive amounts of data are generated all the time. As time goes by, the amount of data stored in the database will become larger and larger, and its maintenance cost will become higher and higher. When database administrators perform daily database maintenance work, as well as data backup or migration, data import and export become their primary tasks.
[0003] Data import and export is one of the essential functions of a database. Currently, most databases implement data import and export based on the principle of logical import and export. For example, the openGauss platform (openGauss is an open source relational database management system whose kernel is derived from PostgreSQL) exports metadata and table data into SQL files through SQL commands, and then rebuilds the table structure and executes SQL to insert table data in the new database system.
[0004] However, given that the amount of data in the main tables of many business systems is very large, the efficiency of data import and export through SQL commands is very low for tables containing large amounts of data, and it is difficult to meet customers' requirements for fast data exchange in terms of performance. Therefore, in order to reduce data maintenance costs and improve data processing efficiency, a new data import and export method that can effectively improve data exchange speed is urgently needed. Summary of the invention
[0005] In order to overcome the defects of low efficiency, high maintenance cost and low processing efficiency in importing and exporting table data with large amounts of data under the openGauss platform, the present invention provides a set of solutions: we propose a high-speed data import and export method based on the openGauss database to replace the traditional logical import and export method. The method of the present invention exports by copying table data files. When importing, the table data files are copied to the table space of the new database system, and then the tuple information in the data file is modified according to its MVCC (Mutil-Version Concurrency Control) characteristics. In this way, the data import and export performance can be effectively improved. At the same time, the system efficiency is significantly improved when performing data processing, and the data maintenance cost is also reduced accordingly.
[0006] In the high-speed data import and export method based on the openGauss platform of the present invention:
[0007] The high-speed data export method comprises: firstly querying metadata of the object to be exported through SQL commands, and saving the metadata into a metadata file; then finding the corresponding table data file, visibility mapping file and free space mapping file in the data directory of the source library according to the oid of the table object, and finally copying the above files into the export directory in the form of files;
[0008] The high-speed data import method includes: firstly importing metadata and creating a table object in a new library; then copying the table data file, visibility mapping file and free space mapping file to the corresponding data directory to replace the table data file generated when importing metadata.
[0009] Furthermore, during the high-speed data import process, after the table data file is imported, the visibility of all records in the data file is updated to ensure that the imported data can be used normally; finally, the imported table is reindexed to generate an index data file.
[0010] More specifically, the high-speed data import and export method of the present invention comprises the following steps:
[0011] High-speed data export methods include:
[0012] Step 1: Enter the export command and control parameters, parse the command and parameters; connect to the database through the connection parameters, and set other parameters as the properties of this export;
[0013] Step 2: Determine the export attributes and select the corresponding export strategy. There are two types of export strategies: one is to export only metadata, that is, object definition; the other is to export all metadata and table data. The export strategy is determined by the passed-in parameter items;
[0014] Step 3: If you choose the first strategy, query the metadata of the object to be exported from the system table through SQL commands, convert the metadata into DDL language, and then store it in the specified format. Objects of the same type are grouped into one category and have one metadata file.
[0015] Step 4: If you choose the second strategy, first export the metadata according to the solution of strategy 1 and save it as a metadata file; then export the associated table data files. In the source library directory, directly copy the table data files involved to the export directory. One table object corresponds to at least one table data file. If there are multiple table data files, all of them need to be copied;
[0016] Step 5: After exporting metadata and table data, generate a mapping relationship file between table objects and table data files based on the table's OID identifier, that is, a relationship between one OID identifier and multiple table data files with the OID as the prefix, and use it during the import process;
[0017] Step 6: For the index object, only export its metadata file and convert it into DDL language, but do not export the index data file;
[0018] Step 7: Encrypt the exported metadata file, table data file, and mapping relationship file between table objects and table data files;
[0019] Step 8: Compress the encrypted table data files to reduce the disk space occupied by large table data files;
[0020] Step 9: Pack the encrypted and compressed files uniformly so that they can be imported into other devices;
[0021] High-speed data import methods include:
[0022] Step A: Input the import command and control parameters, parse the command and parameters; connect to the database through the connection parameters;
[0023] Step B: first decompress the files to be imported to obtain the encrypted metadata DDL files, table data files, and mapping relationship files between table objects and table data files; then decrypt the above three types of files to obtain the decrypted files;
[0024] Step C: Use SQL commands to import metadata files. During this process, import metadata except indexes and create related objects through DDL definitions.
[0025] Step D: Check whether there is a table in the currently imported object and whether there is a corresponding table data file; if there is no table data file, complete the import of the current metadata; if there is a table data file, determine whether the table data file needs to be imported based on the import parameters;
[0026] Step E: If the table data file does not need to be imported, the import of the current metadata is completed; if the table data file needs to be imported, all corresponding table data files are copied to the data directory of the import target library according to the mapping relationship between the table object and the table data file, replacing the newly generated empty data file when the table object is created;
[0027] Step F: If the name of the imported object conflicts with that of an existing object in the target database, the command parameters are used to determine whether to overwrite the old object. If not, the import is skipped. If it is, the old object is deleted first, and then the DDL statement is used to create the new object and overwrite the file.
[0028] Step G: According to the MVCC feature of openGauss, obtain the latest transaction ID of the target database and the shared lock of the table change, enable multi-threading to update the visibility of all tuples in the data file, modify the transaction ID of the tuple creation in the tuple information to ensure that after the data is imported, the visibility of its tuples to future transactions is consistent with that of the source database. After updating the tuple information of all data files, release the shared lock;
[0029] Step H: Import index metadata, rebuild index information on corresponding table objects, and automatically generate new index data files;
[0030] Step I: Finally, call the vacuum command to perform lazy cleanup on the newly imported table, clear invalid tuples in the table, and generate the latest visibility mapping file oid_vm and free space mapping file oid_fsm to improve the tuple scanning efficiency of the imported table in the target database.
[0031] In addition, the present invention also relates to the application of the above-mentioned high-speed data import and export method in a database management system.
[0032] In summary, compared with the traditional logical import and export method, the method of the present invention does not need to parse SQL commands and scan and filter tuples in data files when performing data file operations, thereby significantly improving the performance of data import and export, especially greatly reducing the time consumption of exporting and importing large table object data, improving the efficiency of object migration between databases, and at the same time, the data maintenance cost is also reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0034] Figure 1 The figure is a flow chart of high-speed data export based on the openGauss platform in the present invention.
[0035] Figure 2 It is a schematic diagram of the process of high-speed data import based on the openGauss platform of the present invention. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. The present invention can also be implemented or applied through other different specific implementation methods. The details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention.
[0037] At the same time, it should be understood that the protection scope of the present invention is not limited to the specific embodiments described below; it should also be understood that the terms used in the embodiments of the present invention are for describing specific embodiments rather than for limiting the protection scope of the present invention.
[0038] Embodiment 1: A high-speed data import and export method based on the openGauss platform, specifically comprising the following steps:
[0039] High-speed data export methods include (see Figure 1 ):
[0040] Step 1: Enter the export command and control parameters, parse the command and parameters; connect to the database through the connection parameters, and set other parameters as the properties of this export;
[0041] Step 2: Determine the export attributes and select the corresponding export strategy. There are two types of export strategies: one is to export only metadata, that is, object definition; the other is to export all metadata and table data. The export strategy is determined by the passed-in parameter items;
[0042] Step 3: If you choose the first strategy, query the metadata of the object to be exported from the system table through SQL commands, convert the metadata into DDL language, and then store it in the specified format. Objects of the same type are grouped into one category and have one metadata file.
[0043] Step 4: If you choose the second strategy, first export the metadata according to the solution of strategy 1 and save it as a metadata file; then export the associated table data files. In the source library directory, directly copy the table data files involved to the export directory. One table object corresponds to at least one table data file. If there are multiple table data files, all of them need to be copied;
[0044] Step 5: After exporting metadata and table data, generate a mapping relationship file between table objects and table data files based on the table's OID identifier, that is, a relationship between one OID identifier and multiple table data files with the OID as the prefix, and use it during the import process;
[0045] Step 6: For the index object, only export its metadata file and convert it into DDL language, but do not export the index data file;
[0046] Step 7: Encrypt the exported metadata file, table data file, and mapping relationship file between table objects and table data files;
[0047] Step 8: Compress the encrypted table data files to reduce the disk space occupied by large table data files;
[0048] Step 9: Pack the encrypted and compressed files uniformly so that they can be imported into other devices;
[0049] High-speed data import methods include (see Figure 2 ):
[0050] Step A: Input the import command and control parameters, parse the command and parameters; connect to the database through the connection parameters;
[0051] Step B: first decompress the files to be imported to obtain the encrypted metadata DDL files, table data files, and mapping relationship files between table objects and table data files; then decrypt the above three types of files to obtain the decrypted files;
[0052] Step C: Use SQL commands to import metadata files. During this process, import metadata except indexes and create related objects through DDL definitions.
[0053] Step D: Check whether there is a table in the currently imported object and whether there is a corresponding table data file; if there is no table data file, complete the import of the current metadata; if there is a table data file, determine whether the table data file needs to be imported based on the import parameters;
[0054] Step E: If the table data file does not need to be imported, the import of the current metadata is completed; if the table data file needs to be imported, all corresponding table data files are copied to the data directory of the import target library according to the mapping relationship between the table object and the table data file, replacing the newly generated empty data file when the table object is created;
[0055] Step F: If the name of the imported object conflicts with that of an existing object in the target database, the command parameters are used to determine whether to overwrite the old object. If not, the import is skipped. If it is, the old object is deleted first, and then the DDL statement is used to create the new object and overwrite the file.
[0056] Step G: According to the MVCC feature of openGauss, obtain the latest transaction ID of the target database and the shared lock of the table change, enable multi-threading to update the visibility of all tuples in the data file, modify the transaction ID of the tuple creation in the tuple information to ensure that after the data is imported, the visibility of its tuples to future transactions is consistent with that of the source database. After updating the tuple information of all data files, release the shared lock;
[0057] Step H: Import index metadata, rebuild index information on corresponding table objects, and automatically generate new index data files;
[0058] Step I: Finally, call the vacuum command to perform lazy cleanup on the newly imported table, clear invalid tuples in the table, and generate the latest visibility mapping file oid_vm and free space mapping file oid_fsm to improve the tuple scanning efficiency of the imported table in the target database.
[0059] The above description is only an embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the claims of the present invention.
Claims
1. A high-speed data import and export method based on the openGauss platform. Features: The high-speed data export method includes: firstly, querying the metadata of the object to be exported through SQL commands, and saving the metadata into the metadata DDL file; then, according to the oid of the table object, finding the corresponding table data file, visibility mapping file and free space mapping file in the data directory of the source library; finally, copying the above table data file, visibility mapping file and free space mapping file into the export directory in the form of files, specifically including the following steps: Step 1: Enter the export command and control parameters, parse the command and parameters; connect to the database through the connection parameters, and set other parameters as the properties of this export; Step 2: Determine the export attributes and select the corresponding export strategy. There are two types of export strategies: one is to export only metadata, that is, object definition; the other is to export all metadata and table data. The export strategy is determined by the passed-in parameter items; Step 3: If you choose the first strategy, query the metadata of the object to be exported from the system table through SQL commands, convert the metadata into DDL language, and then store it in the specified format. Objects of the same type are grouped into one category, corresponding to one metadata DDL file. Step 4: If you choose the second strategy, first export the metadata according to the solution of the first strategy and save it as a metadata DDL file; then export the associated table data files. In the source library directory, directly copy the table data files involved to the export directory. One table object corresponds to at least one table data file. If there are multiple table data files, all of them need to be copied; Step 5: After exporting metadata and table data, generate a mapping relationship file between table objects and table data files based on the table's OID identifier, that is, a relationship between one OID identifier and multiple table data files with the OID as the prefix, and use it during the import process; Step 6: For index objects, only export their metadata DDL files, not the index data files; Step 7: Encrypt the exported metadata DDL file, table data file, and the mapping relationship file between table objects and table data files; Step 8: Compress the encrypted table data files to reduce the disk space occupied by large table data files; Step 9: Pack the encrypted and compressed files uniformly so that they can be imported into other devices; The high-speed data import method includes: firstly, importing metadata and creating a table object in a new database; then, copying the table data file, visibility mapping file and free space mapping file to the corresponding data directory to replace the table data file generated when importing metadata, specifically including the following steps: Step A: Input the import command and control parameters, parse the command and parameters; connect to the database through the connection parameters; Step B: first decompress the file to be imported to obtain the encrypted metadata DDL file, table data file, and the mapping relationship file between table objects and table data files; then decrypt the encrypted metadata DDL file, table data file, and the mapping relationship file between table objects and table data files to obtain the decrypted file; Step C: Use SQL commands to import metadata DDL files. In this process, import metadata except indexes and create related objects through DDL definitions. Step D: Check whether there is a table in the currently imported object and whether there is a corresponding table data file; if there is no table data file, complete the import of the current metadata; if there is a table data file, determine whether the table data file needs to be imported based on the import parameters; Step E: If the table data file does not need to be imported, the import of the current metadata is completed; if the table data file needs to be imported, all corresponding table data files are copied to the data directory of the import target library according to the mapping relationship between the table object and the table data file, replacing the newly generated empty data file when the table object is created; Step F: If the name of the imported object conflicts with that of an existing object in the target database, the command parameters are used to determine whether to overwrite the old object. If not, the import is skipped. If it is, the old object is deleted first, and then the DDL statement is used to create the new object and overwrite the file. Step G: According to the MVCC feature of openGauss, obtain the latest transaction ID of the target database and the shared lock of the table change, enable multi-threading to update the visibility of all tuples in the data file, modify the transaction ID of the tuple creation in the tuple information to ensure that after the data is imported, the visibility of its tuples to future transactions is consistent with that of the source database. After updating the tuple information of all data files, release the shared lock; Step H: Import index metadata, rebuild index information on corresponding table objects, and automatically generate new index data files; Step I: Finally, call the vacuum command to perform lazy cleanup on the newly imported table, clear invalid tuples in the table, and generate the latest visibility mapping file oid_vm and free space mapping file oid_fsm to improve the tuple scanning efficiency of the imported table in the target database.
2. The high-speed data import and export method according to claim 1, It is characterized in that During the high-speed data import process, after the table data file is imported, the visibility of all records in the data file is updated to ensure that the imported data can be used normally; finally, the index of the imported table is rebuilt to generate an index data file.
3. Application of the high-speed data import and export method described in claim 1 or 2 in a database management system.
