Temporary table data backup method, system, terminal and storage medium
By copying and mapping temporary table data to permanent segments when the temporary table is in a paused state, the problem of difficulty in backing up temporary table data is solved, enabling backup that does not affect transaction or session content, saving time and reducing costs, and realizing other transactions or The target for the session to read temporary table data.
Patent Information
- Application Number
- CN202210747903.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-29
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2042-06-29
Smart Images

Figure CN115129513B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data storage, and in particular relates to a temporary table data backup method, system, terminal and storage medium. Background Art
[0002] Temporary tables play an important role in databases. Their main purpose is to temporarily store some intermediate result data. However, these intermediate result data will not be permanently saved. After the transaction is completed or the session ends, the data in the temporary table will be automatically cleared and will not be permanently retained. When querying the temporary table through other transactions or sessions, the data will always be empty, which increases the difficulty of backing up the temporary table data. If some of the intermediate result data generated is very important data, but these intermediate data are not backed up in the transaction or session, then it is necessary to modify the transaction or session, add a backup action before the transaction is completed or the session ends, and then re-execute the transaction or session. This operation is obviously cumbersome and requires adjustments to the transaction or session content. It is highly invasive to the transaction or session and needs to be re-executed, which is time-consuming and laborious.
[0003] At this stage, without adjusting the transaction or session content of the temporary table, the temporary table cannot be backed up through other transactions or sessions. Summary of the invention
[0004] In view of the above-mentioned deficiencies in the prior art, the present invention provides a temporary table data backup method, system, terminal and storage medium to solve the above-mentioned technical problems.
[0005] In a first aspect, the present invention provides a method for backing up temporary table data, comprising:
[0006] By tracking the business location corresponding to the temporary table and tracking the temporary table;
[0007] When it is tracked that the temporary table is in a suspended state, the temporary data blocks stored in the temporary table space of the temporary table are copied and converted and stored in the first permanent segment data block, and the temporary data stored in the temporary memory of the temporary table is output to the second permanent segment data block through the data buffer;
[0008] The first permanent segment data block and the second permanent segment data block are both mapped to a pre-established permanent table, so as to read the temporary table data through the permanent table.
[0009] Furthermore, by tracking the business location corresponding to the temporary table and tracking the temporary table, including:
[0010] Query the system temporary segment view, and query the temporary segment name of the temporary table space where the temporary table is located according to the temporary table name; query the temporary block address information according to the temporary segment name, and record the temporary data block address information;
[0011] Query the database transaction or session view, query the transaction activity or session information corresponding to the temporary table according to the temporary table name, and track the relevant activities of the temporary table in real time;
[0012] When the transaction where the temporary table is located is completed or the session is ended, the file where the temporary table space is located is set to read-only. At this time, the temporary table is locked and cannot be modified, and the transaction or session related to the temporary table is in a suspended state.
[0013] Further, when it is tracked that the temporary table is in a suspended state, the temporary data blocks stored in the temporary table space of the temporary table are copied and converted and stored in the first permanent segment data block, and the temporary data stored in the temporary memory of the temporary table is output to the second permanent segment data block through the data buffer, including:
[0014] Locate the temporary data block according to the temporary data block address of the temporary table, copy the temporary data block, the copy content is the actual content of the data skipping the data block header information, and the copy destination is the pre-recorded first permanent segment data block;
[0015] The temporary memory buffer allocated for temporary data is located according to the temporary table information, a copy of the temporary memory buffer data is mirrored into the data buffer, and then the temporary data cached in the data buffer is flushed out of the data buffer into the pre-recorded second permanent segment data block.
[0016] Further, mapping the first permanent segment data block and the second permanent segment data block to a pre-established permanent table, so as to read the temporary table data through the permanent table, includes:
[0017] Pre-create a permanent table with a table structure consistent with the temporary table, specify the permanent table storage table space as the permanent table space, automatically generate a permanent segment, query data block address information according to the permanent segment view, and record continuous data block address information in the permanent segment, wherein the data block address information includes a first permanent segment data block and a second permanent segment data block;
[0018] Set the file system where the temporary tablespace is located to read-write, unlock the temporary table and clear the data;
[0019] The data block is located according to the address information of the first permanent segment data block and the second permanent segment data block, the data content in the data block is parsed, and a one-to-one mapping is performed with the pre-generated permanent table fields according to the field attributes.
[0020] In a second aspect, the present invention provides a temporary table data backup system, comprising:
[0021] A target positioning unit, used for locating a business corresponding to the temporary table and tracking the temporary table;
[0022] A data backup unit is used to copy and convert the temporary data blocks stored in the temporary table space of the temporary table and store them in the first permanent segment data block when tracking that the temporary table is in a suspended state, and output the temporary data stored in the temporary memory of the temporary table to the second permanent segment data block through the data buffer;
[0023] The data mapping unit is used to map the first permanent segment data block and the second permanent segment data block to a pre-established permanent table, so as to read the temporary table data through the permanent table.
[0024] Furthermore, the target positioning unit is specifically used for:
[0025] Query the system temporary segment view, and query the temporary segment name of the temporary table space where the temporary table is located according to the temporary table name; query the temporary block address information according to the temporary segment name, and record the temporary data block address information;
[0026] Query the database transaction or session view, query the transaction activity or session information corresponding to the temporary table according to the temporary table name, and track the relevant activities of the temporary table in real time;
[0027] When the transaction where the temporary table is located is completed or the session is ended, the file where the temporary table space is located is set to read-only. At this time, the temporary table is locked and cannot be modified, and the transaction or session related to the temporary table is in a suspended state.
[0028] Furthermore, the data backup unit is specifically used for:
[0029] Locate the temporary data block according to the temporary data block address of the temporary table, copy the temporary data block, the copy content is the actual content of the data skipping the data block header information, and the copy destination is the pre-recorded first permanent segment data block;
[0030] The temporary memory buffer allocated for temporary data is located according to the temporary table information, a copy of the temporary memory buffer data is mirrored into the data buffer, and then the temporary data cached in the data buffer is flushed out of the data buffer into the pre-recorded second permanent segment data block.
[0031] Furthermore, the data mapping unit is specifically used for:
[0032] Pre-create a permanent table with a table structure consistent with the temporary table, specify the permanent table storage table space as the permanent table space, automatically generate a permanent segment, query data block address information according to the permanent segment view, and record continuous data block address information in the permanent segment, wherein the data block address information includes a first permanent segment data block and a second permanent segment data block;
[0033] Set the file system where the temporary tablespace is located to read-write, unlock the temporary table and clear the data;
[0034] The data block is located according to the address information of the first permanent segment data block and the second permanent segment data block, the data content in the data block is parsed, and a one-to-one mapping is performed with the pre-generated permanent table fields according to the field attributes.
[0035] In a third aspect, a terminal is provided, including:
[0036] processor, memory, wherein:
[0037] The memory is used to store computer programs.
[0038] The processor is used to call and run the computer program from the memory, so that the terminal executes the above-mentioned terminal method.
[0039] According to a fourth aspect, a computer storage medium is provided, wherein the computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the computer executes the methods described in the above aspects.
[0040] The beneficial effects of the present invention are:
[0041] The backup method, system, terminal and storage medium of temporary table data provided by the present invention track the transaction or session corresponding to the temporary table, and before the transaction where the temporary table is located is completed or the session ends, the temporary data blocks stored in the temporary table space of the temporary table are copied and converted and stored in the data blocks of the permanent segment, and the temporary data in the temporary memory where the temporary table is located is output to the data blocks of the permanent segment through the data buffer, and finally the data of the data blocks of the permanent segment is parsed and read. The present invention does not need to modify the transaction or session content where the temporary table is located, nor does it need to re-execute the transaction or session, which saves time and reduces the cost caused by manual modification. The greatest benefit is that the goal of reading temporary table data through other transactions or sessions is achieved.
[0042] In addition, the invention has a reliable design principle, a simple structure and a very broad application prospect. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present invention 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, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention.
[0045] Figure 2 is a schematic block diagram of a system according to an embodiment of the present invention.
[0046] Figure 3 A schematic diagram of the structure of a terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0047] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0048] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention. Figure 1 The execution subject may be a backup system of temporary table data.
[0049] like Figure 1 As shown, the method includes:
[0050] Step 110, locating the business corresponding to the temporary table and tracking the temporary table;
[0051] Step 120, when it is tracked that the temporary table is in a suspended state, the temporary data blocks stored in the temporary table space of the temporary table are copied and converted and stored in the first permanent segment data block, and the temporary data stored in the temporary memory of the temporary table is output to the second permanent segment data block through the data buffer;
[0052] Step 130: Map the first permanent segment data block and the second permanent segment data block to a pre-established permanent table, so as to read the temporary table data through the permanent table.
[0053] To facilitate understanding of the present invention, the temporary table data backup method provided by the present invention is further described below based on the principle of the temporary table data backup method of the present invention and in combination with the process of backing up the temporary table data in the embodiment.
[0054] Specifically, the temporary table data backup method includes:
[0055] (1) Generate data blocks: Create a new permanent tablespace, create a permanent table with the same table structure as the temporary table to be backed up, and specify the permanent table storage tablespace as the permanent tablespace. Automatically generate permanent segments. Query data block address information based on the permanent segment view and record the continuous data block address information in the permanent segment. At this time, the data stored in the data block in the permanent segment is empty (because there is no data in the permanent table temporarily).
[0056] (2) Locate the temporary block: query the system temporary segment view, and query the temporary segment name of the temporary table space where the temporary table is located based on the temporary table name: further query the temporary block address information based on the temporary segment related information, and record the temporary data block address information in the temporary segment;
[0057] (3) Track temporary table activities: query the database transaction or session view, query the transaction activity or session information corresponding to the temporary table according to the temporary table name, and track the relevant activities of the temporary table in real time;
[0058] (4) Locking the temporary table: When the transaction where the temporary table is located is completed or the session ends, the file system where the temporary table space is located is set to read-only. At this time, the temporary table is locked and the temporary table data cannot be modified. At this time, the transaction or session related to the temporary table is in a suspended state;
[0059] (5) Backup temporary data: The data in the temporary table is scattered in two places. One part of the temporary data is in the temporary segment, that is, the temporary data block recorded previously. At this time, the temporary data block is located according to the temporary data block address recorded previously, and it is quickly copied (copied in parallel according to the temporary table structure information. If the temporary table has N fields, N+1 processes are started to copy simultaneously). The copied content is the actual content of the data skipping the data block header information, and the destination is the data block in the permanent segment recorded previously (the location of the relevant data block can be obtained according to the data block address information of the permanent segment recorded previously); the other part of the temporary data is in the memory. According to the temporary table information, the temporary memory buffer allocated for the temporary data is located, and a copy of the temporary memory buffer data is mirrored to the data buffer, and then the temporary data cached in the data buffer is flushed out of the data buffer to the data block of the permanent segment recorded previously;
[0060] (6) Unlock the temporary table: Set the file system where the temporary table space is located to read-write. The temporary table is unlocked and the transaction or session where the temporary table is located can continue. At this time, the transaction is completed or the session ends. According to the characteristics of the temporary table, the temporary table will complete the last action: the data is truncated (the data in the temporary table is cleared);
[0061] (7) Read temporary data: locate the data block according to the data block address information in the permanent segment, parse the data content in the data block, and map it with the permanent table fields generated previously according to the field attributes, one by one. In this way, the backup data can be obtained by directly querying the data in the permanent table.
[0062] like Figure 2 As shown, the system 200 includes:
[0063] A target positioning unit 210, configured to locate the service corresponding to the temporary table and track the temporary table;
[0064] The data backup unit 220 is used to copy the temporary data blocks stored in the temporary table space of the temporary table and convert the data to store in the first permanent segment data block, and output the temporary data stored in the temporary memory of the temporary table to the second permanent segment data block through the data buffer when tracking that the temporary table is in the suspended state;
[0065] The data mapping unit 230 is used to map the first permanent segment data block and the second permanent segment data block to a pre-established permanent table, so as to read the temporary table data through the permanent table.
[0066] Optionally, as an embodiment of the present invention, the target positioning unit is specifically used for:
[0067] Query the system temporary segment view, and query the temporary segment name of the temporary table space where the temporary table is located according to the temporary table name; query the temporary block address information according to the temporary segment name, and record the temporary data block address information;
[0068] Query the database transaction or session view, query the transaction activity or session information corresponding to the temporary table according to the temporary table name, and track the relevant activities of the temporary table in real time;
[0069] When the transaction where the temporary table is located is completed or the session is ended, the file where the temporary table space is located is set to read-only. At this time, the temporary table is locked and cannot be modified, and the transaction or session related to the temporary table is in a suspended state.
[0070] Optionally, as an embodiment of the present invention, the data backup unit is specifically used for:
[0071] Locate the temporary data block according to the temporary data block address of the temporary table, copy the temporary data block, the copy content is the actual content of the data skipping the data block header information, and the copy destination is the pre-recorded first permanent segment data block;
[0072] The temporary memory buffer allocated for temporary data is located according to the temporary table information, a copy of the temporary memory buffer data is mirrored into the data buffer, and then the temporary data cached in the data buffer is flushed out of the data buffer into the pre-recorded second permanent segment data block.
[0073] Optionally, as an embodiment of the present invention, the data mapping unit is specifically used for:
[0074] Pre-create a permanent table with a table structure consistent with the temporary table, specify the permanent table storage table space as the permanent table space, automatically generate a permanent segment, query data block address information according to the permanent segment view, and record continuous data block address information in the permanent segment, wherein the data block address information includes a first permanent segment data block and a second permanent segment data block;
[0075] Set the file system where the temporary tablespace is located to read-write, unlock the temporary table and clear the data;
[0076] The data block is located according to the address information of the first permanent segment data block and the second permanent segment data block, the data content in the data block is parsed, and a one-to-one mapping is performed with the pre-generated permanent table fields according to the field attributes.
[0077] Figure 3 The present invention is a schematic diagram of the structure of a terminal 300 provided in an embodiment of the present invention. The terminal 300 can be used to execute the temporary table data backup method provided in an embodiment of the present invention.
[0078] The terminal 300 may include: a processor 310, a memory 320 and a communication unit 330. These components communicate via one or more buses. Those skilled in the art will appreciate that the server structure shown in the figure does not limit the present invention, and it may be a bus structure or a star structure, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0079] The memory 320 can be used to store the execution instructions of the processor 310, and the memory 320 can be implemented by any type of volatile or non-volatile storage terminal or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. When the execution instructions in the memory 320 are executed by the processor 310, the terminal 300 can perform some or all of the steps in the following method embodiments.
[0080] The processor 310 is the control center of the storage terminal, and uses various interfaces and lines to connect various parts of the entire electronic terminal. It runs or executes software programs and / or modules stored in the memory 320, and calls data stored in the memory to perform various functions of the electronic terminal and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of a plurality of packaged ICs with the same or different functions. For example, the processor 310 can include only a central processing unit (CPU). In the embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.
[0081] The communication unit 330 is used to establish a communication channel so that the storage terminal can communicate with other terminals, receive user data sent by other terminals or send user data to other terminals.
[0082] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0083] Therefore, the present invention tracks the transaction or session corresponding to the temporary table, and before the transaction where the temporary table is located is completed or the session ends, the temporary data blocks stored in the temporary table space of the temporary table are copied and converted and stored in the data blocks of the permanent segment, and at the same time, the temporary data in the temporary memory where the temporary table is located is output to the data blocks of the permanent segment through the data buffer, and finally the data of the data blocks of the permanent segment are parsed and read. The present invention does not need to modify the transaction or session content where the temporary table is located, nor does it need to re-execute the transaction or session, which saves time and reduces the cost caused by manual modification. The biggest benefit is that the goal of reading temporary table data through other transactions or sessions is achieved. The technical effects that can be achieved by this embodiment can be found in the description above, and will not be repeated here.
[0084] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present invention, in essence or in other words, the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes, including several instructions for enabling a computer terminal (which can be a personal computer, a server, or a second terminal, a network terminal, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention.
[0085] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the terminal embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.
[0086] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or units, which can be electrical, mechanical or other forms.
[0087] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0088] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0089] Although the present invention has been described in detail by referring to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, a person of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions shall be within the scope of the present invention. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, and all of these shall be within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A method for backing up temporary table data, characterized in that: include: By tracking the business location corresponding to the temporary table and tracking the temporary table; When it is tracked that the temporary table is in a suspended state, the temporary data blocks stored in the temporary table space of the temporary table are copied and converted and stored in the first permanent segment data block, and the temporary data stored in the temporary memory of the temporary table is output to the second permanent segment data block through the data buffer; Mapping the first permanent segment data block and the second permanent segment data block to a pre-established permanent table, so as to read temporary table data through the permanent table; By tracking the business location corresponding to the temporary table and tracking the temporary table, including: Query the system temporary segment view, and query the temporary segment name of the temporary table space where the temporary table is located according to the temporary table name; query the temporary block address information according to the temporary segment name, and record the temporary data block address information; Query the database transaction or session view, query the transaction activity or session information corresponding to the temporary table according to the temporary table name, and track the relevant activities of the temporary table in real time; When the transaction where the temporary table is located is completed or the session is ended, the file where the temporary table space is located is set to read-only. At this time, the temporary table is locked and cannot be modified, and the transaction or session related to the temporary table is in a suspended state; When it is tracked that the temporary table is in a suspended state, the temporary data blocks stored in the temporary table space of the temporary table are copied and converted and stored in the first permanent segment data block, and the temporary data stored in the temporary memory of the temporary table is output to the second permanent segment data block through the data buffer, including: Locate the temporary data block according to the temporary data block address of the temporary table, copy the temporary data block, the copy content is the actual content of the data skipping the data block header information, and the copy destination is the pre-recorded first permanent segment data block; Locate a temporary memory buffer allocated for temporary data according to the temporary table information, mirror the data in the temporary memory buffer to the data buffer, and then flush the temporary data cached in the data buffer out of the data buffer to the pre-recorded second permanent segment data block; Mapping the first permanent segment data block and the second permanent segment data block to a pre-established permanent table so as to read temporary table data through the permanent table includes: Pre-create a permanent table with a table structure consistent with the temporary table, specify the permanent table storage table space as the permanent table space, automatically generate a permanent segment, query data block address information according to the permanent segment view, and record continuous data block address information in the permanent segment, wherein the data block address information includes a first permanent segment data block and a second permanent segment data block; Set the file system where the temporary tablespace is located to read-write, unlock the temporary table and clear the data; The data block is located according to the address information of the first permanent segment data block and the second permanent segment data block, the data content in the data block is parsed, and a one-to-one mapping is performed with the pre-generated permanent table fields according to the field attributes.
2. A temporary table data backup system, characterized in that: include: A target positioning unit, used for locating a business corresponding to the temporary table and tracking the temporary table; A data backup unit is used to copy and convert the temporary data blocks stored in the temporary table space of the temporary table and store them in the first permanent segment data block when tracking that the temporary table is in a suspended state, and output the temporary data stored in the temporary memory of the temporary table to the second permanent segment data block through the data buffer; A data mapping unit, used for mapping the first permanent segment data block and the second permanent segment data block to a pre-established permanent table, so as to read the temporary table data through the permanent table; The target positioning unit is specifically used for: Query the system temporary segment view, and query the temporary segment name of the temporary table space where the temporary table is located according to the temporary table name; query the temporary block address information according to the temporary segment name, and record the temporary data block address information; Query the database transaction or session view, query the transaction activity or session information corresponding to the temporary table according to the temporary table name, and track the relevant activities of the temporary table in real time; When the transaction where the temporary table is located is completed or the session is ended, the file where the temporary table space is located is set to read-only. At this time, the temporary table is locked and cannot be modified, and the transaction or session related to the temporary table is in a suspended state; The data backup unit is specifically used for: Locate the temporary data block according to the temporary data block address of the temporary table, copy the temporary data block, the copy content is the actual content of the data skipping the data block header information, and the copy destination is the pre-recorded first permanent segment data block; Locate a temporary memory buffer allocated for temporary data according to the temporary table information, mirror the data in the temporary memory buffer to the data buffer, and then flush the temporary data cached in the data buffer out of the data buffer to the pre-recorded second permanent segment data block; The data mapping unit is specifically used for: Pre-create a permanent table with a table structure consistent with the temporary table, specify the permanent table storage table space as the permanent table space, automatically generate a permanent segment, query data block address information according to the permanent segment view, and record continuous data block address information in the permanent segment, wherein the data block address information includes a first permanent segment data block and a second permanent segment data block; Set the file system where the temporary tablespace is located to read-write, unlock the temporary table and clear the data; The data block is located according to the address information of the first permanent segment data block and the second permanent segment data block, the data content in the data block is parsed, and a one-to-one mapping is performed with the pre-generated permanent table fields according to the field attributes.
3. A terminal, characterized in that: include: processor; A memory for storing execution instructions of the processor; Wherein, the processor is configured to execute the method of claim 1.
4. A computer-readable storage medium storing a computer program, characterized in that: When the program is executed by a processor, the method according to claim 1 is implemented.
