CN107145582B - Control method of database cursor and database system - Google Patents
Control method of database cursor and database system Download PDFInfo
- Publication number
- CN107145582B CN107145582B CN201710323310.0A CN201710323310A CN107145582B CN 107145582 B CN107145582 B CN 107145582B CN 201710323310 A CN201710323310 A CN 201710323310A CN 107145582 B CN107145582 B CN 107145582B
- Authority
- CN
- China
- Prior art keywords
- cursor
- activated
- cursors
- memory resources
- database
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
- G06F16/217—Database tuning
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a control method of a database cursor and a database system, wherein the control method of the database cursor comprises the following steps: when detecting that the database activates the cursor, recording the activated cursor and the cursor level thereof to obtain a sorted list of all activated cursors; and when detecting that the activated and idle low-level cursor exists in the sorted list, releasing the memory resource occupied by the low-level cursor. According to the invention, when the memory resources are insufficient, the cursor is closed according to the cursor level to release the resources, so that the memory leakage caused by the database cursor is effectively solved.
Description
Technical Field
The invention relates to the technical field of databases, in particular to a method for controlling a database cursor and a database system.
Background
In a database system, there are often memory resources that cannot be recovered or memory resources that are being used are too much, resulting in less and less available memory in the system, resulting in unsmooth operation of the system.
Cursors are commonly applied to database systems, and when a cursor is not turned off in time after being referenced, the probability of memory overflow is easily increased, so that the system runs more and more slowly until the system is down. At present, a memory leakage tool generally adopts a memory checking tool to analyze static memory errors of a system, but cannot monitor and close a cursor in real time, which causes the problems of blockage, downtime, system breakdown and the like of the system due to lack of memory operation resources when a database system has insufficient memory resources.
Disclosure of Invention
The invention mainly aims to provide a control method of a database cursor and a database system, and aims to solve the technical problem that the database system cannot normally operate due to insufficient system memory resources caused by the fact that the cursor is not closed.
To achieve the above object, an embodiment of the present invention provides a method for controlling a database cursor, where the cursor is provided with a cursor level, and includes a low-level cursor, and the method for controlling a database cursor includes:
when detecting that the database activates the cursor, recording the activated cursor and the cursor level thereof to obtain a sorted list of all activated cursors;
and when detecting that the activated and idle low-level cursor exists in the sorted list, releasing the memory resource occupied by the low-level cursor.
Optionally, the step of releasing the memory resource occupied by the low-level cursor when detecting that there is an activated and idle low-level cursor in the sorted list further includes:
counting idle memory resources of the current database system to obtain corresponding statistical parameters;
and when the statistical parameter is detected to be smaller than the preset threshold value, releasing the memory resources occupied by all the activated cursors in the sorted list.
Optionally, when it is detected that the statistical parameter is smaller than the preset threshold, the step of releasing the memory resources occupied by all activated cursors in the sorted list further includes:
and storing all event information of the released memory resources at this time as the basis for optimizing the memory resources.
Optionally, when it is detected that the statistical parameter is smaller than the preset threshold, the step of releasing memory resources occupied by all activated cursors in the sorted list includes:
when the statistical parameter is detected to be smaller than the preset threshold value, displaying all activated cursors in the current sorted list for the user to select;
and releasing the memory resources occupied by the preselected cursor based on the preselected cursor selected by the user.
Optionally, when it is detected that the statistical parameter is smaller than the preset threshold, the step of releasing memory resources occupied by all activated cursors in the sorted list includes:
when the statistical parameter is detected to be smaller than a preset threshold value, acquiring the release permission of the memory resources of all activated cursors in the sorted list;
when the condition that the release authority cannot successfully release all the memory resources occupied by the activated cursors is detected, the highest authority of the database system is forcibly acquired;
and releasing all memory resources occupied by the activated cursors based on the highest authority.
In addition, to achieve the above object, the present invention further provides a database system, in which a cursor is disposed, and the cursor is provided with a cursor level, including a low-level cursor, the database system includes:
the recording module is used for recording the activated cursors and the cursor levels thereof when detecting that the database activates the cursors so as to obtain a sorted list of all the activated cursors;
the first releasing module is used for releasing the memory resources occupied by the low-level cursors when detecting that the activated and idle low-level cursors exist in the sorted list.
Optionally, the database system further comprises:
the statistical module is used for counting the idle memory resources of the current database system to obtain corresponding statistical parameters;
and the second releasing module is used for releasing the memory resources occupied by all the activated cursors in the sorted list when the statistical parameter is detected to be smaller than the preset threshold.
Optionally, the database system further comprises:
and the storage module is used for storing all event information of the released memory resource at this time as the basis for optimizing the memory resource.
Optionally, the second release module comprises:
the display unit is used for displaying all activated cursors in the current sorted list for a user to select when the statistical parameter is detected to be smaller than the preset threshold;
the first releasing unit is used for releasing the memory resources occupied by the preselected cursor based on the preselected cursor selected by the user.
Optionally, the second release module comprises:
the acquisition unit is used for acquiring the release permission of the memory resources of all the activated cursors in the sorted list when the statistical parameter is detected to be smaller than the preset threshold;
the authority unit is used for forcibly acquiring the highest authority of the database system when detecting that the authority release fails to release all the memory resources occupied by the activated cursors;
and the second release unit is used for releasing all the memory resources occupied by the activated cursors based on the highest authority.
According to the technical scheme, when the database activation cursor is detected, activated cursors and cursor levels thereof are recorded so as to obtain a sorted list of all activated cursors; and when detecting that the activated and idle low-level cursor exists in the sorted list, releasing the memory resource occupied by the low-level cursor. The invention adopts a mode of monitoring the use state of the database cursor in real time, and closes the cursor according to the cursor level to release resources when the memory resources are insufficient, thereby avoiding the problems of system failure, stagnation, crash and the like caused by insufficient memory resources occupied by the cursor, and effectively solving the memory leakage caused by the database cursor.
Drawings
FIG. 1 is a schematic flow chart illustrating a method for controlling a cursor of a database according to a first embodiment of the present invention;
FIG. 2 is a flowchart illustrating a method for controlling a database cursor according to a second embodiment of the present invention;
FIG. 3 is a flowchart illustrating a method for controlling a database cursor according to a third embodiment of the present invention;
fig. 4 is a detailed flowchart of the step of releasing the memory resources occupied by all activated cursors in the ordered list when the statistical parameter is detected to be smaller than the preset threshold value in the fourth embodiment of the method for controlling a database cursor of the present invention;
fig. 5 is a flowchart illustrating a detailed process of the step of releasing the memory resources occupied by all activated cursors in the ordered list when the detected statistical parameter is smaller than the preset threshold value in the fifth embodiment of the method for controlling a database cursor of the present invention;
FIG. 6 is a block diagram of a database system according to a first embodiment of the present invention;
FIG. 7 is a block diagram of a database system according to a second embodiment of the present invention;
FIG. 8 is a block diagram of a database system according to a third embodiment of the present invention;
FIG. 9 is a block diagram illustrating a refinement of a second release module in a fourth embodiment of a database system according to the present invention;
fig. 10 is a schematic diagram of a refinement module of the second release module in the fifth embodiment of the database system according to the present invention.
The objects, features, and advantages of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
A database system implementing various embodiments of the present invention will now be described with reference to the accompanying drawings. In the following description, suffixes such as "module", "component", or "unit" used to denote elements are used only for facilitating the explanation of the present invention, and have no specific meaning in themselves. Thus, "module" and "component" may be used in a mixture.
The cursor is a data buffer area which is set up by the database system for the user and stores the execution result of the database execution statement. In a database system, cursors can enable object references by opening or closing. Through the use of the cursor, the database system can conveniently acquire the specific data record mapped by the cursor. In practical use, even if the cursor is not called any more after the use of the cursor is finished, some cursors are often missed in the asynchronous processing process of the system, so that the cursors are not called but remain in an activated state, certain system memory resources are occupied, and the normal operation of the database system is influenced.
Referring to fig. 1, the present invention provides a method for controlling a database cursor, which is mainly applied to a database system, in a first embodiment of the method for controlling a database cursor, the cursor is provided with a cursor level, which includes low-level cursors, and the method for controlling a database cursor includes:
step S10, when detecting the database activation cursor, recording the activation cursor and the cursor level to obtain the ordered list of all activated cursors;
and when the database system activates the cursor, recording the activated database cursor, recording the cursor level of the database cursor, and acquiring a sorted list of all activated cursors.
The cursor level refers to the existence level of the cursor, and the level is high or low, which means the influence degree of the cursor on the functional application of the database system. For example, the a vernier belongs to a system-level vernier, and the execution of the functional utility plays a critical role in the normal operation of the database system, so the a vernier is a high-level vernier; the B cursor belongs to a common cursor, the execution of the functional utility of the B cursor has almost no influence on the normal operation of the database system, the B cursor can be easily reproduced only as a medium of buffer data or temporary data, and the execution cost is low, so the B cursor is a low-level cursor.
Generally, the list is used to hold all active sets of database cursor objects. If the state of the cursor changes, for example, is released or abnormal, the database system tracks the cursor in real time, and updates or edits the ordered list in real time according to the state of the cursor itself, for example, query, insert, delete, etc. the ordered list is maintained by performing operations on the corresponding cursor in the ordered list.
In step S20, when it is detected that there is an activated and idle low-level cursor in the sorted list, the memory resource occupied by the low-level cursor is released.
To prevent the cursor from occupying too many memory resources in the database system, the sorted list needs to be monitored in real time, for example, the active states of all the cursors in the sorted list are detected at preset time intervals. The preset time interval may be a default preset value, or may be specific data generated by human customization, such as 5 seconds, 10 seconds, and the like. Different states of the cursor have different use meanings, and the cursor does not exist when being closed, and if being activated, the cursor can be in a called state or an idle state.
In a database system, a cursor can be activated by an available process or thread in the database system and, after activation, invokes an application for the calling subject (which can be a process or thread). When the cursor is activated, the cursor in the activated state is called by the cursor and enters the application state, and at the same time, the cursor occupies a considerable amount of system memory resources to serve as a running space for the cursor to execute the function. When the process or the thread is called, the cursor is no longer used as a demand object for function calling, the cursor is in an idle state at the moment, and if the cursor is not closed, the cursor in an activated state still occupies part of the memory resources.
In the cursor state, the cursor in the activated state occupies system resources, but the cursor in the activated and called state is being used, and if the cursor is forcibly suspended, the normal execution of the current database system may be affected. The cursor in the activated and idle state does not exert its functional utility under the current condition, but consumes the memory resources of the system itself, which is easy to affect the normal operation of the database system. It is therefore necessary to troubleshoot the cursor in the active and idle state. In this embodiment, the active and simultaneously inactive cursors in the sorted list are detected, and only low-level cursors are selected according to their cursor levels. Because the low-level cursors do not affect the normal operation of the database system itself. Only the cursors satisfying the three conditions of activated, idle and low level simultaneously are the objects to be screened for performing the timing detection in the present embodiment.
If a cursor satisfying the three conditions of activated, idle, and low level is detected in the sorted list, the cursor is the detection object to be subjected to resource release in this embodiment. Because the cursor is in the idle state at this time, the memory resources occupied by the cursor in the activated and idle state can be directly released without releasing the operation of the cursor occupied by the process or the thread.
It should be noted that, although the low-level cursor in the active and idle state is not called to perform its functional utility, it is still in the state to be called and can be called again by the calling main body (which may be a process or a thread) at any time, so that the cursor object still maintains the data interface with the calling main body and the data interface of other objects implementing its function, and the implementation of the data interface itself consumes the system memory resources. The part of the memory resources are still occupied and not released under the condition that the cursor is idle, so that the memory resources of the system can be utilized to the maximum extent by releasing the memory resources, the application efficiency of the memory resources is improved, and the problems of unsmooth operation, blockage and the like of the system caused by insufficient memory resources are prevented.
Preferably, a large number of active cursors are maintained in the ordered list, and when a low-level cursor is released, the low-level cursor needs to be deleted from the list. Assuming that it is not deleted, both the active state and the released cursor are saved in the list, and the released cursor is not useful in the sorted list. What this embodiment will realize is the cleaning release of the cursor in the activated state, and there is no processing mechanism for the released cursor. Therefore, the released cursor needs to be cleaned and deleted, so as to improve the working efficiency of cursor detection and query. Meanwhile, if the released cursor is not deleted, as the running time of the database system increases, more and more records with the released cursor are available, that is, the memory resources occupied by the sorted list are increased, and the normal running of the database system is affected from another aspect.
According to the technical scheme, when the database activation cursor is detected, activated cursors and cursor levels thereof are recorded so as to obtain a sorted list of all activated cursors; and when detecting that the activated and idle low-level cursor exists in the sorted list, releasing the memory resource occupied by the low-level cursor. The invention adopts a mode of monitoring the use state of the database cursor in real time, and closes the cursor according to the cursor level to release resources when the memory resources are insufficient, thereby avoiding the problems of system failure, stagnation, crash and the like caused by insufficient memory resources occupied by the cursor, and effectively solving the memory leakage caused by the database cursor. The invention adopts a mode of monitoring the use state of the database cursor in real time, and closes the cursor according to the cursor level to release resources when the memory resources are insufficient, thereby avoiding the problems of system failure, stagnation, crash and the like caused by insufficient memory resources occupied by the cursor, and effectively solving the memory leakage caused by the database cursor.
Further, on the basis of the first embodiment of the method for controlling a database cursor of the present invention, a second embodiment of the method for controlling a database cursor is provided, referring to fig. 2, the difference between the second embodiment and the first embodiment is that the step of releasing the memory resources occupied by the low-level cursor when detecting that there is an activated and idle low-level cursor in the sorted list further includes:
step S30, counting the idle memory resources of the current database system to obtain corresponding statistical parameters;
the idle memory resource refers to a memory resource which is in an idle state and is not called currently in the database system. Generally, the system resource needs a part of the idle memory resource in addition to the called memory resource as a default resource to be called when the subsequent function is executed. After the memory resources in the idle state are queried and obtained, since the storage modes of the memory resources are not necessarily connected, the memory resources in the segmented partition form may exist, and therefore, all the memory resources in the idle state need to be counted to obtain corresponding statistical parameters. The statistical parameter refers to the remaining capacity of the memory resource in the idle state.
Step S40, when it is detected that the statistical parameter is smaller than the preset threshold, releasing the memory resources occupied by all activated cursors in the sorted list.
In this embodiment, the database system sets a preset threshold, where the preset threshold is used as a boundary reference value of the statistical parameter, and the value refers to a minimum threshold of the remaining capacity of the memory resource in an idle state in the database system. When the statistical parameters obtained by statistics are smaller than the preset threshold, it is proved that the memory resources in the idle state as buffers in the database system reach the minimum threshold, and if no new memory resources in the idle state are used as supplements, the database system is located at the edge where the operation is not smooth and even the system is crashed. Therefore, at this time, all the memory resources occupied by all the cursors in the activated state in the sorted list need to be released, so as to expand the idle memory resources of the current database system. Of course, there may be high-level cursors in all the activated cursors, and in order to prevent the database system from being extremely jammed or even broken, the high-level cursors need to be released all together.
Further, on the basis of the second embodiment of the method for controlling a database cursor of the present invention, a third embodiment of the method for controlling a database cursor is provided, referring to fig. 3, the difference between the third embodiment and the second embodiment is that, after the step of releasing memory resources occupied by all activated cursors in the ordered list when the statistical parameter is detected to be smaller than the preset threshold, the method further includes:
step S50, storing all event information of the released memory resource this time as the basis for optimizing the memory resource.
In this embodiment, after the system resource release is completed, the remaining capacity of the idle memory resource is increased since it is obtained after the cursor has been activated to release. Therefore, all event information (including information of the released cursor object, the step at which each cursor object is released, the released memory resource of the cursor released, and the like) participating in the release of the memory resource in the current operation can be stored. The information reflects the technical problem that the cursor in the database system is activated but not closed in time, and exposes the system design problem of the database system from the side, such as unreasonable logic design or unreasonable operation principle implementation. Based on these technical problems, the system operator or designer can analyze and process the data in a targeted manner to eliminate the unreasonable application of the system cursor and realize the effective optimization of the memory resources.
Further, on the basis of the third embodiment of the method for controlling a database cursor of the present invention, a fourth embodiment of the method for controlling a database cursor is proposed, referring to fig. 4, where a difference between the fourth embodiment and the third embodiment is that the step of releasing memory resources occupied by all activated cursors in the sorted list when the statistical parameter is detected to be smaller than the preset threshold includes:
step S41, when the statistical parameter is detected to be smaller than the preset threshold, displaying all activated cursors in the current sorted list for the user to select;
in step S42, based on the pre-selection cursor selected by the user, the memory resource occupied by the pre-selection cursor is released.
And when the statistical parameter is smaller than the preset threshold value, releasing all activated cursors. However, if the user wants to purposefully release part of the activated cursor, part of the cursor remains to be executed. For example, all activated cursors include three cursors a, B, and C, and at this time, the statistical parameter is smaller than the preset threshold, and the three cursors a, B, and C need to be released in the normal process, but the user only wants to release the cursors B and C and keep the cursors a. At this time, the database system may provide a display interface to display all the activated cursors in the current sorted list and provide an editing mode for selecting the activated cursors for the user to select. The user selects the preselected cursor by editing as the cursor object for really executing the release function. And according to the preselected cursor, releasing the memory resource occupied by the preselected cursor by the database system.
Further, on the basis of the second embodiment of the method for controlling a database cursor of the present invention, a fifth embodiment of the method for controlling a database cursor is provided, referring to fig. 5, the difference between the fifth embodiment and the second embodiment is that the step of releasing the memory resources occupied by all activated cursors in the ordered list when the statistical parameter is detected to be smaller than the preset threshold value includes:
step S43, when the statistical parameter is detected to be smaller than the preset threshold value, the releasing authority of the memory resources of all the activated cursors in the sorted list is obtained;
step S44, when detecting that the release authority can not successfully release all the memory resources occupied by the activated cursors, forcibly acquiring the highest authority of the database system;
in step S45, the memory resources occupied by all activated cursors are released based on the highest authority.
In a database system, a certain operation authority is required to release the cursor, and the acquisition of the release authority may be based on the current database system account. In a real scene, a phenomenon may occur in which some cursors cannot be released. There may be reasons why the cursor is abnormal, or the cursor is in a protection state, etc. At this time, a specific cursor release authority needs to be acquired, and release operation is performed based on the release authority. However, when the right acquisition request cannot acquire the release right of the activated cursor, it proves that the release operation of the activated cursor cannot be completed with the current operation right. The highest authority of the database system can be obtained forcibly. The highest authority means that all operation steps of the current database system can be executed without any trouble. For the same reason, having the highest authority means that all the activated euro-rated memory resources can be released without any trouble. Based on the highest authority, the database system can normally execute the memory resources occupied by all the activated cursors.
Of course, the embodiment and the fourth embodiment can complement each other, the embodiment of obtaining the highest authority of the system to release the memory resource occupied by the cursor and the embodiment of the user-defined selection of the cursor to be released are not contradictory to each other, and the two embodiments can be combined with each other to form a preferred technical scheme for solving the problem of insufficient memory resource of the system in different embodiments of the present invention.
Referring to fig. 6, the present invention further provides a database system, in a first embodiment of the database system, a cursor is disposed in the database system, and the cursor is disposed at a cursor level, which includes a low-level cursor, and the database system includes:
the recording module 10 is used for recording the activated cursors and the cursor levels thereof when detecting that the database activates the cursors, so as to obtain a sorted list of all the activated cursors;
when the database system activates the cursor, the recording module 10 records the activated database cursor, records the cursor level thereof, and obtains a sorted list of all activated cursors.
The cursor level refers to the existence level of the cursor, and the level is high or low, which means the influence degree of the cursor on the functional application of the database system. For example, the a vernier belongs to a system-level vernier, and the execution of the functional utility plays a critical role in the normal operation of the database system, so the a vernier is a high-level vernier; the B cursor belongs to a common cursor, the execution of the functional utility of the B cursor has almost no influence on the normal operation of the database system, the B cursor can be easily reproduced only as a medium of buffer data or temporary data, and the execution cost is low, so the B cursor is a low-level cursor.
Generally, the list is used to hold all active sets of database cursor objects. If the state of the cursor changes, for example, is released or abnormal, the database system tracks the cursor in real time, and updates or edits the ordered list in real time according to the state of the cursor itself, for example, query, insert, delete, etc. the ordered list is maintained by performing operations on the corresponding cursor in the ordered list.
The first releasing module 20 is configured to release the memory resource occupied by the low-level cursor when detecting that there is an activated and idle low-level cursor in the sorted list.
To prevent the cursor from occupying too many memory resources in the database system, the first releasing module 20 monitors the sorted list in real time, for example, detects the active states of all the cursors in the sorted list at preset time intervals. The preset time interval may be a default preset value, or may be specific data generated by human customization, such as 5 seconds, 10 seconds, and the like. Different states of the cursor have different use meanings, and the cursor does not exist when being closed, and if being activated, the cursor can be in a called state or an idle state.
In a database system, a cursor can be activated by an available process or thread in the database system and, after activation, invokes an application for the calling subject (which can be a process or thread). When the cursor is activated, the cursor in the activated state is called by the cursor and enters the application state, and at the same time, the cursor occupies a considerable amount of system memory resources to serve as a running space for the cursor to execute the function. When the process or the thread is called, the cursor is no longer used as a demand object for function calling, the cursor is in an idle state at the moment, and if the cursor is not closed, the cursor in an activated state still occupies part of the memory resources.
In the cursor state, the cursor in the activated state occupies system resources, but the cursor in the activated and called state is being used, and if the cursor is forcibly suspended, the normal execution of the current database system may be affected. The cursor in the activated and idle state does not exert its functional utility under the current condition, but consumes the memory resources of the system itself, which is easy to affect the normal operation of the database system. It is therefore necessary to troubleshoot the cursor in the active and idle state. In the present embodiment, the first releasing module 20 detects the cursors in the ordered list that are active and idle at the same time, and only filters out the low-level cursors according to their cursor levels. Because the low-level cursors do not affect the normal operation of the database system itself. Only the cursors satisfying the three conditions of activated, idle and low level simultaneously are the objects to be screened for performing the timing detection in the present embodiment.
If a cursor satisfying the three conditions of activated, idle, and low level is detected in the sorted list, the cursor is the detection object to be subjected to resource release in this embodiment. Because the cursor is in the idle state at this time, the memory resources occupied by the cursor in the activated and idle state can be directly released without releasing the operation of the cursor occupied by the process or the thread.
It should be noted that, although the low-level cursor in the active and idle state is not called to perform its functional utility, it is still in the state to be called and can be called again by the calling main body (which may be a process or a thread) at any time, so that the cursor object still maintains the data interface with the calling main body and the data interface of other objects implementing its function, and the implementation of the data interface itself consumes the system memory resources. The part of the memory resources are still occupied and not released under the condition that the cursor is idle, so that the memory resources of the system can be utilized to the maximum extent by releasing the memory resources, the application efficiency of the memory resources is improved, and the problems of unsmooth operation, blockage and the like of the system caused by insufficient memory resources are prevented.
Preferably, a large number of active cursors are maintained in the ordered list, and when a low-level cursor is released, the low-level cursor needs to be deleted from the list. Assuming that it is not deleted, both the active state and the released cursor are saved in the list, and the released cursor is not useful in the sorted list. What this embodiment will realize is the cleaning release of the cursor in the activated state, and there is no processing mechanism for the released cursor. Therefore, the released cursor needs to be cleaned and deleted, so as to improve the working efficiency of cursor detection and query. Meanwhile, if the released cursor is not deleted, as the running time of the database system increases, more and more records with the released cursor are available, that is, the memory resources occupied by the sorted list are increased, and the normal running of the database system is affected from another aspect.
In the technical scheme of the invention, when the recording module 10 detects that the database activates the cursor, the activated cursor and the cursor level thereof are recorded to obtain a sorted list of all activated cursors; when the first releasing module 20 detects that there is an activated and idle low-level cursor in the ordered list, the memory resources occupied by the low-level cursor are released. The invention adopts a mode of monitoring the use state of the database cursor in real time, and closes the cursor according to the cursor level to release resources when the memory resources are insufficient, thereby avoiding the problems of system failure, stagnation, crash and the like caused by insufficient memory resources occupied by the cursor, and effectively solving the memory leakage caused by the database cursor. The invention adopts a mode of monitoring the use state of the database cursor in real time, and closes the cursor according to the cursor level to release resources when the memory resources are insufficient, thereby avoiding the problems of system failure, stagnation, crash and the like caused by insufficient memory resources occupied by the cursor, and effectively solving the memory leakage caused by the database cursor.
Further, on the basis of the first embodiment of the database system of the present invention, a second embodiment of the database system is proposed, and referring to fig. 7, the difference between the second embodiment and the first embodiment is that the database system further includes:
the statistical module 30 is configured to count idle memory resources of the current database system to obtain corresponding statistical parameters;
the idle memory resource refers to a memory resource which is in an idle state and is not called currently in the database system. Generally, the system resource needs a part of the idle memory resource in addition to the called memory resource as a default resource to be called when the subsequent function is executed. The statistical module 50 may query and acquire the memory resources in the idle state, and since the storage modes of the memory resources are not necessarily connected, and there may be memory resources in a segmented partition form, it is necessary to perform statistics on all the memory resources in the idle state to obtain corresponding statistical parameters. The statistical parameter refers to the remaining capacity of the memory resource in the idle state.
And a second releasing module 40, configured to release, when it is detected that the statistical parameter is smaller than the preset threshold, all memory resources occupied by the activated cursors in the sorted list.
In this embodiment, the database system sets a preset threshold, where the preset threshold is used as a boundary reference value of the statistical parameter, and the value refers to a minimum threshold of the remaining capacity of the memory resource in an idle state in the database system. When the statistical parameters obtained by statistics are smaller than the preset threshold, it is proved that the memory resources in the idle state as buffers in the database system reach the minimum threshold, and if no new memory resources in the idle state are used as supplements, the database system is located at the edge where the operation is not smooth and even the system is crashed. Therefore, at this time, all the memory resources occupied by all the cursors in the activated state in the sorted list need to be released, so as to expand the idle memory resources of the current database system. Of course, there may be high-level cursors in all the activated cursors, and in order to prevent the database system from being extremely jammed or even broken, the high-level cursors need to be released all together.
Further, on the basis of the second embodiment of the database system of the present invention, a third embodiment of the database system is proposed, and referring to fig. 8, the difference between the third embodiment and the second embodiment is that the database system further includes:
the storage module 50 is configured to store all event information of the released memory resource this time, so as to serve as a basis for optimizing the memory resource.
In this embodiment, after the system resource release is completed, the remaining capacity of the idle memory resource is increased since it is obtained after the cursor has been activated to release. Therefore, all event information (including information of the released cursor object, the step at which each cursor object is released, the released memory resource of the cursor released, and the like) participating in the release of the memory resource in the current operation can be stored. The information reflects the technical problem that the cursor in the database system is activated but not closed in time, and exposes the system design problem of the database system from the side, such as unreasonable logic design or unreasonable operation principle implementation. Based on these technical problems, the system operator or designer can analyze and process the data in a targeted manner to eliminate the unreasonable application of the system cursor and realize the effective optimization of the memory resources.
Further, on the basis of the third embodiment of the database system of the present invention, a fourth embodiment of the database system is proposed, and referring to fig. 9, the difference between the fourth embodiment and the third embodiment is that the second releasing module 40 includes:
a display unit 41, configured to display all activated cursors in the current sorted list for a user to select when it is detected that the statistical parameter is smaller than a preset threshold;
the first releasing unit 42 is configured to release the memory resource occupied by the preselected cursor based on the preselected cursor selected by the user.
And when the statistical parameter is smaller than the preset threshold value, releasing all activated cursors. However, if the user wants to purposefully release part of the activated cursor, part of the cursor remains to be executed. For example, all activated cursors include three cursors a, B, and C, and at this time, the statistical parameter is smaller than the preset threshold, and the three cursors a, B, and C need to be released in the normal process, but the user only wants to release the cursors B and C and keep the cursors a. At this time, the database system may provide a display interface to display all the activated cursors in the current sorted list and provide an editing mode for selecting the activated cursors for the user to select. The user selects the preselected cursor by editing as the cursor object for really executing the release function. And according to the preselected cursor, releasing the memory resource occupied by the preselected cursor by the database system.
Further, on the basis of the first embodiment of the database system of the present invention, a fifth embodiment of the database system is proposed, and referring to fig. 10, the difference between the fifth embodiment and the first embodiment is that the second releasing module 40 includes:
an obtaining unit 43, configured to obtain, when it is detected that the statistical parameter is smaller than the preset threshold, release permissions of memory resources of all activated cursors in the sorted list;
the authority unit 44 is configured to, when it is detected that the release authority fails to release all the memory resources occupied by the activated cursor, forcibly obtain the highest authority of the database system;
and a second releasing unit 45, configured to release, based on the highest authority, all memory resources occupied by the activated cursor.
In a database system, a certain operation authority is required to release the cursor, and the acquisition of the release authority may be based on the current database system account. In a real scene, a phenomenon may occur in which some cursors cannot be released. There may be reasons why the cursor is abnormal, or the cursor is in a protection state, etc. At this time, a specific cursor release authority needs to be acquired, and release operation is performed based on the release authority. However, when the right acquisition request cannot acquire the release right of the activated cursor, it proves that the release operation of the activated cursor cannot be completed with the current operation right. The highest authority of the database system can be obtained forcibly. The highest authority means that all operation steps of the current database system can be executed without any trouble. For the same reason, having the highest authority means that all the activated euro-rated memory resources can be released without any trouble. Based on the highest authority, the database system can normally execute the memory resources occupied by all the activated cursors.
Of course, the embodiment and the fourth embodiment can complement each other, the embodiment of obtaining the highest authority of the system to release the memory resource occupied by the cursor and the embodiment of the user-defined selection of the cursor to be released are not contradictory to each other, and the two embodiments can be combined with each other to form a preferred technical scheme for solving the problem of insufficient memory resource of the system in different embodiments of the present invention.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.
Claims (8)
1. A control method of a database cursor is characterized in that the cursor is provided with a cursor level, wherein the cursor level comprises a low-level cursor, and the control method of the database cursor comprises the following steps:
when detecting that the database activates the cursor, recording the activated cursor and the cursor level thereof to obtain a sorted list of all activated cursors;
when detecting that the activated and idle low-level cursor exists in the sorted list, releasing the memory resource occupied by the low-level cursor;
counting idle memory resources of the current database system to obtain corresponding statistical parameters; the idle memory resource is a memory resource which is in an idle state at present and is not called;
and when the statistical parameter is detected to be smaller than the preset threshold value, releasing the memory resources occupied by all the activated cursors in the sorted list.
2. The method for controlling a database cursor of claim 1,
when the statistical parameter is detected to be smaller than the preset threshold value, the step of releasing the memory resources occupied by all activated cursors in the sorted list further comprises:
and storing all event information of the released memory resources at this time as the basis for optimizing the memory resources.
3. The method for controlling a database cursor of claim 2,
when the statistical parameter is detected to be smaller than the preset threshold value, the step of releasing the memory resources occupied by all the activated cursors in the sorted list comprises the following steps:
when the statistical parameter is detected to be smaller than the preset threshold value, displaying all activated cursors in the current sorted list for the user to select;
and releasing the memory resources occupied by the preselected cursor based on the preselected cursor selected by the user.
4. The method for controlling a cursor in a database according to any one of claims 1 to 3,
when the statistical parameter is detected to be smaller than the preset threshold value, the step of releasing the memory resources occupied by all the activated cursors in the sorted list comprises the following steps:
when the statistical parameter is detected to be smaller than a preset threshold value, acquiring the release permission of the memory resources of all activated cursors in the sorted list;
when the condition that the release authority cannot successfully release all the memory resources occupied by the activated cursors is detected, the highest authority of the database system is forcibly acquired;
and releasing all memory resources occupied by the activated cursors based on the highest authority.
5. A database system, wherein a cursor is disposed in the database system, and the cursor is disposed at a cursor level, including a low-level cursor, the database system comprising:
the recording module is used for recording the activated cursors and the cursor levels thereof when detecting that the database activates the cursors so as to obtain a sorted list of all the activated cursors;
the first release module is used for releasing the memory resources occupied by the low-level cursors when the activated and idle low-level cursors in the sorted list are detected;
the statistical module is used for counting the idle memory resources of the current database system to obtain corresponding statistical parameters; the idle memory resource is a memory resource which is in an idle state at present and is not called;
and the second releasing module is used for releasing the memory resources occupied by all the activated cursors in the sorted list when the statistical parameter is detected to be smaller than the preset threshold.
6. The database system of claim 5, wherein the database system further comprises:
and the storage module is used for storing all event information of the released memory resource at this time as the basis for optimizing the memory resource.
7. The database system of claim 6, wherein the second release module comprises:
the display unit is used for displaying all activated cursors in the current sorted list for a user to select when the statistical parameter is detected to be smaller than the preset threshold;
the first releasing unit is used for releasing the memory resources occupied by the preselected cursor based on the preselected cursor selected by the user.
8. The database system of any of claims 5 to 7, wherein the second release module comprises:
the acquisition unit is used for acquiring the release permission of the memory resources of all the activated cursors in the sorted list when the statistical parameter is detected to be smaller than the preset threshold;
the authority unit is used for forcibly acquiring the highest authority of the database system when detecting that the authority release fails to release all the memory resources occupied by the activated cursors;
and the second release unit is used for releasing all the memory resources occupied by the activated cursors based on the highest authority.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710323310.0A CN107145582B (en) | 2017-05-09 | 2017-05-09 | Control method of database cursor and database system |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710323310.0A CN107145582B (en) | 2017-05-09 | 2017-05-09 | Control method of database cursor and database system |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN107145582A CN107145582A (en) | 2017-09-08 |
| CN107145582B true CN107145582B (en) | 2022-01-04 |
Family
ID=59778286
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201710323310.0A Active CN107145582B (en) | 2017-05-09 | 2017-05-09 | Control method of database cursor and database system |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN107145582B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111737295B (en) * | 2020-06-11 | 2023-02-03 | 上海达梦数据库有限公司 | Database cursor query method, device, equipment and storage medium |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101859261A (en) * | 2010-06-09 | 2010-10-13 | 中兴通讯股份有限公司 | Control method and control equipment for releasing memory |
| CN104375828A (en) * | 2014-10-27 | 2015-02-25 | 小米科技有限责任公司 | Method and device for optimizing memory |
| CN105243003A (en) * | 2015-09-09 | 2016-01-13 | 浪潮(北京)电子信息产业有限公司 | Memory allocation monitoring method and apparatus |
| CN106326137A (en) * | 2015-07-02 | 2017-01-11 | 腾讯科技(深圳)有限公司 | Memory optimization method and apparatus, and user equipment |
| CN106326094A (en) * | 2015-06-29 | 2017-01-11 | 联芯科技有限公司 | Method and system for inspecting abnormity of pointer |
Family Cites Families (9)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20040010502A1 (en) * | 2002-07-12 | 2004-01-15 | Bomfim Joanes Depaula | In-memory database for high performance, parallel transaction processing |
| CN101315628B (en) * | 2007-06-01 | 2011-01-05 | 华为技术有限公司 | Internal memory database system and method and device for implementing internal memory data base |
| EP2290562A1 (en) * | 2009-08-24 | 2011-03-02 | Amadeus S.A.S. | Segmented main-memory stored relational database table system with improved collaborative scan algorithm |
| CN101847127B (en) * | 2010-06-18 | 2012-01-25 | 福建星网锐捷网络有限公司 | Memory management method and device |
| US9223618B2 (en) * | 2011-09-20 | 2015-12-29 | Intel Corporation | Multi-threaded queuing system for pattern matching |
| US8786620B2 (en) * | 2011-11-14 | 2014-07-22 | Microsoft Corporation | Discarding idle graphical display components from memory and processing |
| CN103914337B (en) * | 2014-03-24 | 2016-04-13 | 小米科技有限责任公司 | Service calling method, device and terminal |
| CN105786939A (en) * | 2014-12-26 | 2016-07-20 | 中兴通讯股份有限公司 | Memory database optimization method and apparatus |
| CN105700968A (en) * | 2016-01-11 | 2016-06-22 | 厦门雅迅网络股份有限公司 | Method and device for memory leakage diagnosis processing in embedded system |
-
2017
- 2017-05-09 CN CN201710323310.0A patent/CN107145582B/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101859261A (en) * | 2010-06-09 | 2010-10-13 | 中兴通讯股份有限公司 | Control method and control equipment for releasing memory |
| CN104375828A (en) * | 2014-10-27 | 2015-02-25 | 小米科技有限责任公司 | Method and device for optimizing memory |
| CN106326094A (en) * | 2015-06-29 | 2017-01-11 | 联芯科技有限公司 | Method and system for inspecting abnormity of pointer |
| CN106326137A (en) * | 2015-07-02 | 2017-01-11 | 腾讯科技(深圳)有限公司 | Memory optimization method and apparatus, and user equipment |
| CN105243003A (en) * | 2015-09-09 | 2016-01-13 | 浪潮(北京)电子信息产业有限公司 | Memory allocation monitoring method and apparatus |
Also Published As
| Publication number | Publication date |
|---|---|
| CN107145582A (en) | 2017-09-08 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US20180365085A1 (en) | Method and apparatus for monitoring client applications | |
| US8181161B2 (en) | System for automatically collecting trace detail and history data | |
| US7900011B2 (en) | Apparatus, system, and method for improving system performance in a large memory heap environment | |
| US6892378B2 (en) | Method to detect unbounded growth of linked lists in a running application | |
| CN101154180B (en) | Method for monitoring task stack overflow | |
| US8516462B2 (en) | Method and apparatus for managing a stack | |
| US20100106933A1 (en) | Method and system for managing storage capacity in a storage network | |
| CN113806183B (en) | Application clamping and processing method, device, equipment, storage medium and program product | |
| CN101169752A (en) | A way to catch functions that cause memory to be overwritten by wild pointers | |
| CN107453932A (en) | A kind of distributed memory system management method and its device | |
| CN111159051B (en) | Deadlock detection method, deadlock detection device, electronic equipment and readable storage medium | |
| CN106997316A (en) | Detecting system and method that memory abnormal increases | |
| CN109542341B (en) | A kind of reading and writing IO monitoring method, device, terminal and computer readable storage medium | |
| CN108536822A (en) | Data migration method, device, system and storage medium | |
| CN107145582B (en) | Control method of database cursor and database system | |
| CN102981939A (en) | Disc monitoring method | |
| CN103188103A (en) | A self-monitoring method for a network management system | |
| CN106951318A (en) | The management method and electronic equipment of a kind of electronic equipment background process | |
| CN106528582B (en) | The backup method and device of database | |
| CN108920344B (en) | Storage method and device and computer readable storage medium | |
| CN107066625A (en) | A kind of oracle database table statistical information collection method and system | |
| CN112559445B (en) | Data writing method and device | |
| US6182244B1 (en) | System and method for automatically initiating a tracing facility and dynamically changing the levels of tracing currently active | |
| JP4641443B2 (en) | Log information management apparatus, log information management method, and log information management program | |
| CN112463079A (en) | Data storage control method, device, equipment and readable storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |