Priority-based database Autovacuum process scheduling method, equipment, and media

CN122412111BActive Publication Date: 2026-08-14HIGHGO SOFTWARE
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-06-12
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

[0004]本申请实施例提供了一种基于优先级评分的数据库Autovacuum进程调度方法、设备及介质,用于解决如下技术问题:通过简单的先进先出队列,由有限数量的AutovacuumWorker进程依次进行表清理的方式,容易导致核心业务表清理延迟、系统资源利用失衡,以致整体运维效率低下

Benefits of technology

[0015]本申请实施例采用的上述至少一个技术方案能够达到以下有益效果:本申请实施例通过融合在线学习模型和时序预测模型,综合考量表的实时状态、历史趋势、业务重要性及系统全局负载,提高动态优先级分值计算的准确度,确保核心紧急的表优先得到处理。以及,本申请实施例通过时序模型预测未来死元组增长趋势,可在表膨胀达到静态阈值前提前提升其优先级,触发预防性清理,将Autovacuum的工作模式转变为主动预防。此外,本申请实施例通过维护多级优先级队列和动态时间片分配,确保高优先级表优先获得Workers资源,同时通过防饥饿算法保障低优先级表的基础清理权利,实现资源利用的公平与效率平衡。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122412111B_ABST
    Figure CN122412111B_ABST
Patent Text Reader

Abstract

This application discloses a database Autovacuum process scheduling method, device, and medium based on priority scoring, belonging to the field of database technology. It addresses the problem of low overall operational efficiency during table cleanup in high-concurrency scenarios using the Autovacuum process. The method includes: within each scheduling cycle, acquiring the running status information of the tables to be cleaned in the database and determining an initial priority score; performing a first dynamic correction on the initial priority score based on the running status information, the online learning model, and the current scheduling queue status; performing a second dynamic correction on the corrected score based on the future expansion risk value to obtain a dynamic priority score for the tables to be cleaned; placing each table to be cleaned into a scheduling queue of the corresponding priority based on the dynamic priority score; and dynamically allocating worker process resources according to real-time system resource information and the priority of the scheduling queue to execute the cleanup task.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technology, and in particular to a database Autovacuum process scheduling method, device and medium based on priority scoring. Background Technology

[0002] In the PostgreSQL database system, the Autovacuum process is responsible for automatically performing VACUUM (cleaning up dead tuples) and ANALYZE (updating statistics) operations to control table bloat and optimize query plans. The core of the existing technology is a trigger mechanism based on a static threshold. When the number of dead tuples in a table exceeds the threshold, the table is placed in a simple first-in-first-out queue, and a limited number of Autovacuum Worker processes clean it up sequentially.

[0003] However, in high-concurrency write scenarios, dead tuples in critical business tables accumulate rapidly, causing them to swell quickly and severely impact query performance. Furthermore, when one or more large tables enter the cleanup process, the sheer volume of data means the cleanup process can monopolize one or even multiple workers for extended periods. This severely blocks subsequent tables in the queue, especially critical core business tables that, while not large in volume, experience extremely urgent data demands. Excessive queuing times prevent timely responses to performance crises. Therefore, under resource-constrained conditions, core business table cleanup is delayed, system resource utilization is unbalanced, leading to overall low operational efficiency. Summary of the Invention

[0004] This application provides a database Autovacuum process scheduling method, device, and medium based on priority scoring to solve the following technical problem: the simple first-in-first-out queue method, in which a limited number of AutovacuumWorker processes perform table cleanup sequentially, can easily lead to delays in core business table cleanup, imbalances in system resource utilization, and ultimately, low overall operational efficiency.

[0005] The embodiments of this application adopt the following technical solutions: This application provides a method for scheduling Autovacuum processes in a database based on priority scoring. The method includes: within each scheduling cycle, acquiring the running status information of the tables to be cleaned in the database, and determining an initial priority score based on the running status information; determining a contention correction score based on the running status information and an online learning model, and determining a congestion penalty based on the current scheduling queue status and the contention correction score, so as to perform a first dynamic correction on the initial priority score through the congestion penalty; determining a future expansion risk value based on time-series model predictions and historical dead tuple data in the running status information, and performing a second dynamic correction on the score after the first dynamic correction based on the future expansion risk value, so as to obtain a dynamic priority score corresponding to the tables to be cleaned; placing each table to be cleaned into a scheduling queue of the corresponding priority based on the dynamic priority score; and dynamically allocating Autovacuum worker process resources in the database according to real-time system resource information and the priority of the scheduling queue to execute the cleanup task.

[0006] In one implementation of this application, a competition correction score is determined based on runtime status information and an online learning model. A congestion penalty is then determined based on the current scheduling queue status and the competition correction score. This congestion penalty is used to dynamically correct the initial priority score. Specifically, this includes: if the runtime value in the runtime status information is greater than a preset runtime value threshold, assigning the highest priority score to the table to be cleaned and directly allocating it to the queue; otherwise, constructing a multi-dimensional feature vector based on the runtime status information, inputting the multi-dimensional feature vector into a clustering model, outputting the behavior pattern category corresponding to the table to be cleaned through the clustering model, and using a preset weight allocation template corresponding to the behavior pattern category as the basic weight to determine the runtime value corresponding to the table to be cleaned. The deviation between the current value of the status indicator and the baseline value of historical similar tables is used to obtain a basic score item by weighted summation of the operational status indicators of each dimension of the table to be cleaned based on the deviation and the basic weights. Among them, the operational status indicators include one of the following: dead tuple ratio, update rate, and I / O load. The model contribution score is determined by calculating the feature vector corresponding to the current state of the table to be cleaned based on the online learning model. The queue congestion penalty score is determined according to the current priority level of the table to be cleaned and the real-time length of each global scheduling queue. The basic score item and the model contribution score are added to obtain the competition correction score. The initial priority score, the competition correction score, and the queue congestion penalty score are synthesized to complete the first dynamic correction.

[0007] In one implementation of this application, a future expansion risk value is determined based on time series model predictions and historical dead-bin data in the operational status information. A second dynamic correction is then applied to the score after the first dynamic correction based on the future expansion risk value. Specifically, this includes: predicting the proportion of dead-bins in the table to be cleaned within a preset future timeframe based on the additive decomposition time series model and historical dead-bin data of the table to be cleaned; if the predicted future dead-bin proportion is greater than a first risk threshold, and the current dead-bin proportion is not greater than a second risk threshold, then a trend prediction adjustment score is determined based on the degree to which the predicted future dead-bin proportion exceeds the first risk threshold; and the trend prediction adjustment score is added to the score after the first dynamic correction to complete the second dynamic correction.

[0008] In one implementation of this application, after predicting the proportion of dead tuples in the table to be cleaned within a preset future time based on the additive decomposition time-series model and historical dead tuple data of the table to be cleaned, the method further includes: if the proportion of dead tuples in the table to be cleaned within the preset future time is greater than the pre-cleaning trigger threshold, and the current proportion of dead tuples corresponding to the table to be cleaned is not greater than the pre-cleaning safety threshold, then a logical cleanup snapshot is created for the table to be cleaned; wherein, the logical cleanup snapshot is used to record the location information of dead tuples in the table to be cleaned that meet the safety cleanup conditions, and is associated with the corresponding database transaction snapshot; the metadata of the logical cleanup snapshot is persistently stored and associated with the table to be cleaned; when the table to be cleaned reaches the emergency cleanup trigger condition, the Autovacuum worker process loads the logical cleanup snapshot associated with the table to be cleaned before performing physical cleanup; if the loading is successful, the Autovacuum worker process performs incremental physical cleanup based on the dead tuple location information recorded in the logical cleanup snapshot and the dead tuples newly generated after the transaction snapshot corresponding to the logical cleanup snapshot.

[0009] In one implementation of this application, each table to be cleaned is placed into a scheduling queue of its corresponding priority based on a dynamic priority score. Specifically, this includes: comparing the dynamic priority score of the table to be cleaned with a preset priority interval threshold to determine the initial priority level; calculating an internal sorting key based on the current enqueue timestamp, the dynamic priority score, and a preset penalty coefficient; sorting all tables in the scheduling queue based on the internal sorting key to determine the scheduling order of the tables to be cleaned within the scheduling queue; if the table to be cleaned is determined to be at the lowest priority level, then before placing it into the lowest priority queue, a starvation prevention condition check is performed on the table to be cleaned; wherein, the starvation prevention condition includes not meeting any preset emergency cleanup conditions, the dynamic priority score being lower than a preset priority score threshold, or the time difference between the current time and the last time the table to be cleaned completed a cleanup operation being greater than a preset starvation time window; if the table to be cleaned meets the starvation prevention condition, then the dynamic priority score of the table to be cleaned is increased.

[0010] In one implementation of this application, Autovacuum worker process resources in the database are dynamically allocated based on real-time system resource information and the priority of the scheduling queue. Specifically, this includes: dividing the Autovacuum process resource pool to be allocated into a dedicated worker process pool and a shared worker process pool; wherein the dedicated worker process pool is used to handle tasks in the highest priority scheduling queue, and the shared worker process pool is used to handle tasks in other priority scheduling queues; if the highest priority scheduling queue is not empty, worker processes are allocated in the dedicated worker process pool, based on the capacity limit of the dedicated worker process pool, the current number of idle processes, and the highest priority scheduling queue. The minimum number of pending tasks in the queue determines the allocation quantity. After satisfying the allocation requirements of the highest priority scheduling queue, if there are remaining worker processes, a round-robin method is used to allocate processes to the next highest and lower priority scheduling queues until all worker processes are exhausted or all tasks in all queues have been allocated. If the execution time of any worker process's cleanup operation on a single table exceeds the maximum continuous execution time slice and is still not completed, the cleanup session is terminated and the worker process resources are released after the process completes the cleanup operation of the currently processing data page. The interrupted cleanup task is then placed back into the tail of its respective priority scheduling queue, waiting for the next scheduling.

[0011] In one implementation of this application, after executing the cleanup task, the method further includes: determining the comprehensive reward value generated by the current cleanup task based on a preset multi-objective reward function; wherein the multi-objective reward function includes the following dimensions: the efficiency of the cleanup in improving table bloat, the business importance level of the target table, the impact on I / O performance during the execution of the cleanup task, and the fairness reflected by the time since the last cleanup of the target table; obtaining the feature vector corresponding to the table to be cleaned at the scheduling decision time, and using the feature vector and the comprehensive reward value as training samples, inputting them into the online learning model to update the internal parameters of the online learning model; determining the moving average error in the first preset time period based on the error between the predicted reward value of the cleanup task corresponding to the online learning model and the actual comprehensive reward value obtained; when the moving average error continues to be greater than the preset anomaly threshold in the second preset time period, dynamically reducing the trust coefficient corresponding to the online learning model, and triggering a safety rollback mechanism when the trust coefficient decays to zero, switching to a working mode that makes scheduling decisions only based on preset rules and weights.

[0012] In one implementation of this application, updating the internal parameters of the online learning model specifically includes: obtaining historical parameters maintained by the online learning model for the cleanup table; wherein the historical parameters include parameter vectors and covariance inverse matrix; constructing first data based on the product of the covariance inverse matrix, eigenvectors, and the transpose of the eigenvectors; obtaining a correction term based on the first data and the ratio between the eigenvectors and the current covariance inverse matrix; incrementally updating the covariance inverse matrix based on the difference between the current covariance inverse matrix and the correction term; accumulating the product of the actual obtained comprehensive reward value and the eigenvectors into the reward vector maintained by the online learning model for the cleanup table; and multiplying the updated covariance inverse matrix and the updated reward vector to obtain the updated model parameter vector, thereby completing the parameter update.

[0013] This application provides a priority-based database Autovacuum process scheduling device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to: obtain, within each scheduling cycle, the running status information corresponding to the tables to be cleaned in the database, and determine an initial priority score based on the running status information; determine a contention correction score based on the running status information and an online learning model, and determine a congestion penalty based on the current scheduling queue status and the contention correction score, so as to perform a first dynamic correction on the initial priority score through the congestion penalty; determine a future expansion risk value based on time series model prediction and historical dead tuple data in the running status information, and perform a second dynamic correction on the score after the first dynamic correction based on the future expansion risk value, so as to obtain a dynamic priority score corresponding to the tables to be cleaned; place each table to be cleaned into a scheduling queue of the corresponding priority based on the dynamic priority score; and dynamically allocate Autovacuum worker process resources in the database according to the real-time resource information of the system and the priority of the scheduling queue to execute the cleanup task.

[0014] This application provides a non-volatile computer storage medium storing computer-executable instructions. These instructions are configured to: within each scheduling cycle, acquire the running status information corresponding to the tables to be cleaned in the database, and determine an initial priority score based on the running status information; determine a contention correction score based on the running status information and an online learning model, and determine a congestion penalty based on the current scheduling queue status and the contention correction score, so as to perform a first dynamic correction on the initial priority score through the congestion penalty; determine a future expansion risk value based on time-series model predictions and historical dead tuple data in the running status information, and perform a second dynamic correction on the score after the first dynamic correction based on the future expansion risk value, so as to obtain a dynamic priority score corresponding to the tables to be cleaned; based on the dynamic priority scores, place each table to be cleaned into a scheduling queue of the corresponding priority; and dynamically allocate resources for the Autovacuum worker process in the database according to the real-time system resource information and the priority of the scheduling queue, so as to execute the cleanup task.

[0015] The above-mentioned technical solutions adopted in this application embodiment can achieve the following beneficial effects: By integrating online learning models and time-series prediction models, this application embodiment comprehensively considers the real-time status, historical trends, business importance, and global system load of tables, improving the accuracy of dynamic priority score calculation and ensuring that core and urgent tables are processed first. Furthermore, this application embodiment predicts the future growth trend of dead tuples through time-series models, which can advance the priority of tables before they reach a static threshold, triggering preventative cleanup and transforming the Autovacuum working mode into proactive prevention. In addition, this application embodiment maintains multi-level priority queues and dynamic time slice allocation to ensure that high-priority tables receive worker resources first, while protecting the basic cleanup rights of low-priority tables through an anti-starvation algorithm, achieving a balance between fairness and efficiency in resource utilization. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 A flowchart of a database Autovacuum process scheduling method based on priority scoring provided in this application embodiment; Figure 2 This is a schematic diagram of the structure of the Autovacuum process scheduling device based on priority scoring provided in an embodiment of this application.

[0017] Figure label: 200: Priority-based database Autovacuum process scheduling device; 201: Processor; 202: Memory. Detailed Implementation

[0018] This application provides a method, device, and medium for scheduling Autovacuum processes in a database based on priority scoring.

[0019] To enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this application.

[0020] Figure 1 A flowchart illustrating a priority-based database Autovacuum process scheduling method provided in this application embodiment. Figure 1 As shown, the priority-based database Autovacuum process scheduling method includes the following steps: Step 101: Within each scheduling cycle, obtain the running status information of the table to be cleaned in the database, and determine the initial priority score based on the running status information.

[0021] In one implementation of this application, the embodiments of this application reconstruct the scheduling decision process of the Autovacuum process by introducing a table-level risk assessment model, a multi-level priority scheduling queue, and an adaptive Workers allocator into the PostgreSQL kernel.

[0022] Based on the existing user table statistics information system view, several new statistical columns are added. The new statistical columns include, but are not limited to, the time taken for the last cleanup, the average update rate, and the I / O intensity level, which can be divided into three levels: low, medium, and high. The business priority is used to store the business importance label that the user configures for the table through the GUC (Grand Unified Configuration) parameter.

[0023] Initialize the weight coefficients for the multi-dimensional priority scoring, including the expansion rate weight to measure the severity of table bloat, the update frequency weight to measure table activity, the business importance weight to reflect differences in business value, and the I / O pressure weight to reflect system resource pressure. Next, set priority grading thresholds for dividing scheduling queues. For example, tables with a dynamic priority score greater than or equal to 80 are assigned to the emergency queue, those with scores between 60 and 79 to the high-priority queue, those with scores between 30 and 59 to the medium-priority queue, and those with scores below 30 to the low-priority queue. Furthermore, parameters related to the intelligent algorithm need to be configured, such as the number of table behavioral feature clusters, the dimension of the feature vector, the order of the periodic Fourier series used for time series prediction, the exploration coefficients of the online learning model, the threshold for the number of scheduling attempts required for model cold start, and the maximum value of the model trust level.

[0024] In the shared memory of the database, data structures for this scheduling system are created and maintained, including: a four-level global priority queue for managing tasks to be cleaned up, with each queue storing table object identifiers and their calculated priority scores; a Workers status table for tracking resource status, recording the table currently being processed by each Autovacuum worker process, the timestamp of the start of processing, and the estimated remaining cleanup time; a historical trend cache for supporting trend analysis, storing the curves of the number of dead tuples in each table within a past time window in the form of a circular buffer; a table feature vector cache, cluster center table, LinUCB (Linear Upper Confidence Bound) parameter table (LinUCBParameter Table, LPT), and additive decomposition parameter table for storing intermediate data of machine learning models; a circular buffer for recording scheduling effect logs for decision feedback; and a global AI trust state variable for dynamically adjusting the fusion ratio of traditional rule models and online learning models in the final decision.

[0025] At the start of each preset scheduling cycle, real-time operational status metrics are collected for each table. These metrics include the current number of dead tuples and the number of active tuples in the table, from which the immediate dead tuple ratio can be calculated. The total number of data update and delete operations for the table in the previous scheduling cycle is also included, and the current update rate can be calculated by combining these with the time interval. Additionally, the business importance level is obtained by querying the preset business priority label for the table, and the current I / O load percentage or level is obtained by reading the real-time I / O statistics of the tablespace containing the table and comparing them with historical baselines.

[0026] After obtaining complete real-time operational status information, the collected metrics such as dead tuple ratio, update rate, business importance level, and I / O load level are normalized and mapped to comparable numerical ranges. The normalized metric values ​​are then multiplied by their corresponding preset weight coefficients to obtain the contribution score for that dimension. Finally, the contribution scores for all dimensions are summed to obtain the initial priority score.

[0027] Step 102: Based on the running status information and the online learning model, determine the contention correction score, and determine the congestion penalty based on the current scheduling queue status and the contention correction score, so as to make the first dynamic correction to the initial priority score through the congestion penalty.

[0028] In one implementation of this application, if the running value in the running status information is greater than a preset running value threshold, the table to be cleaned is assigned the highest priority score and directly allocated to a queue. Otherwise, a multi-dimensional feature vector is constructed based on the running status information, and the multi-dimensional feature vector is input into a clustering model to output the behavior pattern category corresponding to the table to be cleaned. The preset weight allocation template corresponding to the behavior pattern category is used as the basic weight to determine the current value of the running status indicator corresponding to the table to be cleaned and the deviation between it and the baseline value of historical similar tables. The basic score item is obtained by weighted summation of the running status indicators of each dimension of the table to be cleaned based on the deviation and the basic weight. The running status indicator includes one of the following: dead tuple ratio, update rate, and I / O load. The model calculates the feature vector corresponding to the current state of the table to be cleaned based on the online learning model to determine the model contribution score. Based on the current priority level of the table to be cleaned and the real-time length of each global scheduling queue, the queue congestion penalty score is determined. The basic score item is added to the model contribution score to obtain the competition correction score. The initial priority score, the competition correction score and the queue congestion penalty score are combined to complete the first dynamic correction.

[0029] Specifically, the system checks whether several key operational metrics of the table to be cleaned have reached preset maximum risk thresholds. These thresholds include whether the transaction ID age is close to the system's set freeze limit, or whether the current dead tuple ratio of the table exceeds a critical value. If any of the above conditions are met, the table is determined to be in an extremely dangerous state, directly assigned the highest priority score, and placed in the highest priority scheduling queue to ensure that the system's safety baseline is protected with the highest priority.

[0030] For tables that have not triggered emergency screening, a fixed-dimensional numerical feature vector is constructed based on multiple collected operational status indicators. This feature vector contains a quantitative description of the table size, activity, health status, business context, and time context. Subsequently, this feature vector is input into the Mini-Batch K-Means algorithm, which compares the table's feature vector with multiple cluster centers maintained in memory, classifying it into the closest behavioral pattern category, such as a core transaction table, a large log table, or a cold history table. Each predefined behavioral pattern category is associated with a corresponding scoring weight template, which specifies the initial weight proportions of various dimensions such as expansion rate, update frequency, business importance, and I / O load when calculating the basic score.

[0031] Secondly, the deviation of the table's real-time metric values ​​on key dimensions from the historical baseline values ​​of similar tables is calculated. Specifically, the current dead tuple ratio, update rate, and I / O load are calculated as multiples of their recent average levels relative to their respective behavioral pattern categories. The two dimensions with the largest deviations are identified, and their weight templates are dynamically adjusted with rewards. For example, the weight of the dimension with the highest deviation is increased by 15%, and the weight of the second highest deviation is increased by 5%, while the weights of other dimensions are reduced proportionally. Using this dynamically adjusted final weight, the normalized metric values ​​of each dimension of the table are weighted and summed to obtain a basic score item reflecting its current overall status.

[0032] The feature vector corresponding to the current table is input into a context-aware online decision-making model based on the LinUCB algorithm. This model, combined with historical scheduling feedback data, calculates an estimated exploratory reward. This value consists of two parts: the first part is a point estimate of the expected reward based on the model's current parameters, and the second part is the confidence interval width, which is proportional to the feature uncertainty. The calculated value is used as the contribution score of the online learning model to this round of scheduling decisions, i.e., the model contribution score. The current length of each priority queue is read in real time. If the length of the highest priority scheduling queue has accumulated to more than twice the maximum number of working processes in the system, it is determined that the system has a large backlog of urgent tasks. At this time, in order to slow down the queuing speed of non-urgent new tasks, different basic penalty scores are applied according to the estimated priority level of the new queuing table itself. For example, five, ten, and fifteen points are deducted for high, medium, and low priority tables, respectively. If the total length of the highest and second-highest priority queues further exceeds three times the maximum number of working processes in the system, it is determined that high-priority tasks are also severely backlogged, and an additional five-point penalty is added to the medium and low priority tables. The penalty value dynamically calculated through this mechanism is the queue congestion penalty score. After calculating the base score, the online learning model contribution score, and the queue congestion penalty score, the scheduler performs the final synthesis operation. The synthesis operation involves adding the base score and the model contribution score, then subtracting the queue congestion penalty score. The result of this synthesis operation is the priority score after the first dynamic correction.

[0033] Step 103: Based on the time series model prediction and the historical dead tuple data in the running status information, determine the future expansion risk value, and perform a second dynamic correction on the score after the first dynamic correction according to the future expansion risk value, so as to obtain the dynamic priority score corresponding to the table to be cleaned.

[0034] In one implementation of this application, based on an additive decomposition time series model and historical dead-bin data of the table to be cleaned, the proportion of dead-bins in the table to be cleaned within a preset future time period is predicted. If the predicted future dead-bin proportion is greater than a first risk threshold, and the current dead-bin proportion is not greater than a second risk threshold, then a trend prediction adjustment score is determined according to the degree to which the predicted future dead-bin proportion exceeds the first risk threshold. The trend prediction adjustment score is added to the score after the first dynamic correction to complete the second dynamic correction.

[0035] Specifically, in this embodiment, a time-series cache of historical dead tuple counts is set up for each table. When trend prediction is needed, the additive decomposition time-series model is invoked to process the cached data. This model decomposes the historical dead tuple growth sequence into four interpretable components: the first component is a long-term trend term, typically determined by methods such as linear regression to identify the overall growth or decline trend of the data; the second component is a daily periodic term, used to model the periodic fluctuations in dead tuple growth caused by business patterns within a 24-hour day, such as accelerated growth during peak daytime business periods; the third component is a weekly periodic term, used to model the periodic fluctuations caused by differences between weekdays and weekends within a 7-day week; and the fourth component is an event term, used to capture abnormal growth spikes caused by events such as sudden batch operations. The model uses recursive least squares to update the trend term parameters online and uses a Fourier series of a preset order to fit the daily and weekly periodic effects. Based on this decomposition model, the expected number of dead tuples in the table at a given future time point, such as one hour from now, is calculated. Add the predicted number of dead tuples to the current number of active tuples in the table, and then calculate the proportion of the predicted number of dead tuples in this sum to obtain the predicted proportion of future dead tuples.

[0036] Secondly, the predicted proportion of future dead units is compared with a preset risk threshold to determine whether priority needs to be increased. This application embodiment has a dual-condition judgment: First, the predicted proportion of future dead units must exceed a higher first risk threshold, which defines a state that will become dangerous in the short term. Second, the current real-time proportion of dead units in the table has not yet exceeded a lower second risk threshold, which defines a currently safe state. Through these dual conditions, intervention can be carried out in advance for tables that are not currently in a severely inflated state but are predicted to rapidly enter a dangerous state based on trends.

[0037] When the above dual judgment conditions are met, a specific trend prediction adjustment score is calculated based on the urgency of the predicted risk. The calculation principle is that the larger the proportion of predicted future dead tuples exceeds the first risk threshold, the higher the adjustment score is applied to reflect the severity of the risk. Specifically, the adjustment score is equal to the difference between the predicted proportion and the first risk threshold, multiplied by a preset scaling factor. To ensure the adjustment range is controllable, an upper limit is set on the calculation result. After calculating the trend prediction adjustment score, it is added to the priority score that has already undergone the first dynamic correction, thus completing the second dynamic correction. After this correction, tables predicted to experience severe expansion soon, even if their current state is acceptable, will have their final dynamic priority score increased, allowing them to be prioritized in the multi-level priority queue and thus scheduled and cleaned up earlier, completing preventative processing before the expansion actually occurs and affects performance.

[0038] Step 104: Based on the dynamic priority score, place each table to be cleaned into the scheduling queue of the corresponding priority.

[0039] In one implementation of this application, the dynamic priority score of the table to be cleaned is compared with a preset priority interval threshold to determine the initial priority level. An internal sorting key is calculated based on the current enqueue timestamp, the dynamic priority score, and a preset penalty coefficient. Based on this internal sorting key, all tables in the scheduling queue are sorted to determine the scheduling order of the table to be cleaned within the scheduling queue. If the table to be cleaned is determined to be at the lowest priority level, a starvation prevention check is performed on it before placing it in the lowest priority queue. The starvation prevention conditions include not meeting any preset emergency cleanup conditions, a dynamic priority score lower than a preset priority score threshold, or the time difference between the current time and the last time the table to be cleaned completed a cleanup operation being greater than a preset starvation time window. If the table to be cleaned meets the starvation prevention conditions, its dynamic priority score is increased.

[0040] After calculating the final dynamic priority score of the tables to be cleaned, they need to be assigned to appropriate scheduling queues based on this score, and their specific execution order within the queues needs to be determined. Simultaneously, to prevent low-activity tables from being ignored for extended periods, this embodiment also includes an anti-starvation boosting mechanism to ensure the fairness of long-term system operation. Specifically, this embodiment pre-defines multiple consecutive priority score intervals, each corresponding to a specific priority level. The calculated dynamic priority score is compared with the preset interval threshold to determine the initial priority level that the table should be assigned. Furthermore, if the transaction ID age of a table exceeds the system-defined mandatory freeze age threshold, regardless of its dynamic score, it will be directly designated as an emergency level.

[0041] After determining the priority queue to which a table should be added, a composite key, or internal sort key, is calculated for sorting within the queue. This internal sort key consists of two parts. The first part is the table's current enqueue timestamp, ensuring that tables enqueued earlier have smaller base key values. The second part is a penalty term related to the table's dynamic priority score, calculated by subtracting the table's dynamic score from 100 and then multiplying by a preset penalty coefficient. This ensures that, given the same enqueue time, tables with higher scores receive a better sorting position due to their smaller penalty term, thus being scheduled first. However, since enqueue time is the base term, even a newly enqueued high-scoring table may have a sort key larger than a low-scoring table already waiting in the queue. This prevents high-scoring tables from completely blocking earlier enqueuers, balancing efficiency and fairness. Based on this internal sort key, the scheduler sorts all tables in the target priority queue in ascending order to determine the order in which they are retrieved by the worker processes.

[0042] Before placing a table into its initial priority queue, if the table is determined to be at the lowest priority level, the scheduler will initiate an additional anti-starvation check. The anti-starvation check includes the following conditions: First, confirm that the table does not meet any preset emergency cleanup conditions, such as transaction ID age not exceeding limits or the proportion of dead tuples not exceeding extremely high thresholds, ensuring that high-risk tables that should be urgently handled are not mistakenly promoted. Second, confirm that the table's dynamic priority score is below a low anti-starvation trigger threshold, such as 30, indicating that it is indeed not urgent according to normal assessment. Third, calculate the difference between the current system time and the timestamp of the table's last successful cleanup operation, and confirm that this time difference exceeds a preset starvation time window, such as 24 hours. Only when all the above conditions are met simultaneously is the table determined to have triggered the anti-starvation mechanism, and the scheduler will perform a promotion operation. First, the table's dynamic priority score is forcibly raised to a preset value that would allow it to escape the lowest priority level. Second, based on the new score, its appropriate priority level is re-determined, allowing it to enter a higher-level queue. Subsequently, the internal sort key for the table is calculated and enqueued in a higher-level queue, thus avoiding potential risks or outdated statistics that may accumulate due to prolonged neglect.

[0043] Step 105: Based on the real-time resource information of the system and the priority of the scheduling queue, dynamically allocate resources of the Autovacuum worker process in the database to execute the cleanup task.

[0044] In one implementation of this application, the Autovacuum process resource pool to be allocated is divided into a dedicated worker process pool and a shared worker process pool. The dedicated worker process pool handles tasks in the highest priority scheduling queue, while the shared worker process pool handles tasks in other priority scheduling queues. If the highest priority scheduling queue is not empty, worker processes are allocated from the dedicated worker process pool, with the allocation number determined based on the minimum of the dedicated worker process pool's capacity limit, the current number of idle processes, and the number of tasks pending in the highest priority scheduling queue. After satisfying the allocation requirements of the highest priority scheduling queue, if there are remaining worker processes, processes are allocated to the next highest and lower priority scheduling queues using a round-robin approach until all worker processes are exhausted or all queues have been allocated tasks. If the execution time of a worker process's cleanup operation on a single table exceeds the maximum continuous execution time slice and is still not completed, the cleanup session is terminated and the worker process resources are released after the process completes the currently processing data page cleanup operation. The interrupted cleanup task is then re-placed at the tail of its respective priority scheduling queue, awaiting the next scheduling.

[0045] Specifically, in this embodiment, the available Autovacuum worker processes are divided into two resource pools. The first is a dedicated worker process pool, in which the processes are used to process tasks in the highest priority scheduling queue. The second is a shared worker process pool, in which the processes are used to process tasks in all priority queues except the highest priority, so as to ensure that the highest priority tasks always have dedicated and a certain amount of processing resources, avoiding the risk of being completely blocked by a large number of low priority tasks.

[0046] At each round of scheduling decisions, the scheduler first checks if the highest priority scheduling queue is not empty. If there are tasks waiting to be processed in this queue, the scheduler will prioritize allocating processes from the dedicated worker process pool, taking the minimum value among the preset capacity limit of the dedicated worker process pool, the number of processes currently idle in the dedicated worker process pool, and the number of tasks waiting to be processed in the highest priority scheduling queue. This allocation method ensures that urgent tasks receive a rapid response while preventing them from excessively consuming system resources. After allocating to the highest priority scheduling queue, if there are remaining resources in the shared worker process pool, the scheduler checks the next highest priority queue, the medium priority queue, and the low priority queue in sequence. Whenever a non-empty queue is checked, the task at the head of the queue is taken and an idle shared worker process is allocated to it. After completing one allocation, the scheduler continues to check the next lower priority queue. This process repeats until all idle shared worker processes are exhausted, or all tasks in all non-highest priority queues have been allocated.

[0047] When a worker process begins processing a table cleanup task, the scheduler starts timing. If the process's cleanup operation on a single table takes longer than the preset maximum continuous execution time slice, and the cleanup is still incomplete, the scheduler sends an interrupt signal to the worker process. Upon receiving the interrupt signal, the worker process continues cleaning up the currently processed data page to ensure data consistency. After completing the operation on the current page, the worker process terminates the cleanup session, releases its occupied process resources, and returns it to the idle process pool. Simultaneously, the scheduler retrieves the table identifier and its original priority for the task and places it back at the tail of its original priority scheduling queue, awaiting reallocation and processing in the next scheduling cycle. In this way, the cleanup of large tables is divided into multiple time slices, freeing up resources for other tasks while ensuring the large table cleanup task is eventually completed.

[0048] In one implementation of this application, after executing the cleanup task, the method further includes: determining the comprehensive reward value generated by the cleanup task based on a preset multi-objective reward function; wherein the multi-objective reward function includes the following dimensions: the efficiency of the cleanup in improving table bloat, the business importance level of the target table, the impact on I / O performance during the cleanup task execution, and the fairness reflected by the time since the last cleanup of the target table. The feature vector corresponding to the cleaned table at the scheduling decision time is obtained, and the feature vector and the comprehensive reward value are used as training samples and input into the online learning model to update the internal parameters of the online learning model. Based on the error between the predicted cleanup task reward value and the actual comprehensive reward value obtained by the online learning model, the moving average error within a first preset time period is determined. When the moving average error continues to exceed a preset anomaly threshold within a second preset time period, the trust coefficient corresponding to the online learning model is dynamically reduced, and when the trust coefficient decays to zero, a safety rollback mechanism is triggered, switching to a working mode that only makes scheduling decisions based on preset rules and weights.

[0049] Specifically, a pre-defined multi-objective reward function is invoked. This function quantifies the effect from four dimensions: the efficiency of the cleanup in reducing table bloat, the business importance level of the target table, the impact on I / O performance during the cleanup task, and the fairness reflected in the time elapsed since the last cleanup of the target table. The cleanup efficiency reward is calculated based on the ratio of the decrease in the proportion of dead tuples before and after cleanup to the cleanup time; the business value reward is calculated as a function of the table's business importance level and its current scheduling waiting time; the system penalty is calculated based on the increment of system I / O latency during cleanup; and the fairness reward is awarded a fixed score when the time elapsed since the last cleanup of the table exceeds twelve hours. The four sub-items are weighted and summed using pre-defined weights, and the result is rounded to a standard range of -100 to 100 to obtain the comprehensive reward value.

[0050] Furthermore, the feature vector of the current cleanup table at the initial decision time is obtained from the scheduling effect log. This feature vector and the actual comprehensive reward value are used as a set of training samples and input into an online learning model based on the LinUCB algorithm. The model uses this sample to adjust its internal parameter vector and matrix using an incremental update method, thereby optimizing the prediction of future rewards. The predicted reward value of the model at this scheduling time is read from the log, and the absolute error between the predicted value and the actual comprehensive reward value is calculated. This embodiment of the application also sets a sliding window to record the prediction errors of the most recent twenty times. The average value of all errors in this window is used as the model's recent moving average prediction error. The moving average error is continuously compared with a preset anomaly threshold, which is set to three times the average error of the model during the stable period after cold start. If the moving average error continuously exceeds this threshold in multiple consecutive scheduling cycles, the model performance is determined to be degraded. At this time, the global confidence coefficient is reduced by 0.2. This coefficient controls the weight of the model contribution score in the final priority score. If the trust coefficient decays to zero due to continuous deterioration, a safety rollback is triggered. That is, the system completely switches to a working mode that does not rely on the online learning model. All subsequent scheduling decisions are generated only based on preset static rules and weight templates until the model performance is restored and the trust is gradually rebuilt.

[0051] In one implementation of this application, updating the internal parameters of the online learning model specifically includes: obtaining historical parameters maintained by the online learning model for the cleanup table; wherein the historical parameters include parameter vectors and covariance inverse matrix. First data is constructed based on the product of the covariance inverse matrix, eigenvectors, and the transpose of the eigenvectors; a correction term is obtained based on the first data and the ratio between the eigenvectors and the current covariance inverse matrix. Based on the difference between the current covariance inverse matrix and the correction term, the covariance inverse matrix is ​​incrementally updated; the product of the actual obtained comprehensive reward value and the eigenvectors is accumulated into the reward vector maintained by the online learning model for the cleanup table; the updated covariance inverse matrix is ​​multiplied by the updated reward vector to obtain the updated model parameter vector, thus completing the parameter update.

[0052] Specifically, the online learning model parameter table is queried to obtain the historical parameters corresponding to the currently cleaned table. These parameters include a d-dimensional parameter vector theta, a d-by-d-dimensional covariance inverse matrix A_inv, and a d-dimensional reward vector b. Based on the obtained covariance inverse matrix A_inv and the eigenvector x at the time of decision-making, a scalar v is calculated. Its value is the result of multiplying the transpose of the eigenvector x by matrix A_inv, then multiplying by the dot product of the eigenvector x, plus one. Simultaneously, matrix M is calculated, which is the product of matrix A_inv, eigenvector x, and the transpose of eigenvector x. The covariance inverse matrix A_inv is updated using the Sherman-Morrison formula. The new covariance inverse matrix A_inv_new is obtained by subtracting matrix M from the original matrix A_inv and dividing by the scalar v. This computational complexity is proportional to the square of the eigenvector dimension d, avoiding the cubic complexity of matrix inversion in traditional methods. Multiply the actual comprehensive reward value *r* obtained from this cleanup task by the feature vector *x* to obtain a d-dimensional update vector. This update vector is then added to the historical reward vector *b*, completing the reward vector update. Multiply the updated covariance inverse matrix *A_inv_new* by the updated reward vector *b_new* to obtain a new d-dimensional parameter vector *theta_new*. This vector represents the updated internal parameters of the online learning model and will be used for predictive calculations in the next scheduling decision.

[0053] After predicting the future proportion of dead tuples, during periods of low system load (e.g., nighttime periods configured by the system), cleanup operations are triggered in advance for tables that have not yet reached an emergency expansion state but are predicted to expand rapidly in the short term based on trends. This smooths out system load and avoids future performance bottlenecks. When the predicted expansion rate exceeds the trigger threshold but the current expansion rate is below the safety threshold, and the system is in a preset off-peak period, the system will temporarily increase the priority score of the table and add it to the scheduling queue. Meanwhile, to ensure that the pre-cleanup operation does not affect normal business operations, it is only allowed to execute when the proportion of available worker processes is low and only when the overall system I / O load is below the threshold.

[0054] After predicting the future proportion of dead tuples, this predicted value is compared with a pre-cleanup trigger threshold, which defines a future state that will become dangerous. Simultaneously, it is checked whether the current real-time dead tuple proportion of the table is not higher than a pre-cleanup safety threshold, which defines a state that is currently still within a safe and operable range. Only when the predicted proportion exceeds the trigger threshold and the current proportion does not exceed the safety threshold is the table deemed to meet the logical snapshot creation conditions. This condition ensures that this advanced optimization is only enabled for tables that are currently safe but about to become dangerous, avoiding unnecessary operations on bloated tables or completely safe tables. When a table meets the creation conditions, a consistent transaction snapshot of the current database is obtained. Based on this transaction snapshot, the target table is scanned to identify all tuples that are dead in the snapshot view, i.e., no longer visible to any active transactions. The physical location information of these dead tuples is recorded and organized into a lightweight data structure, namely the logical cleanup snapshot. Simultaneously, this snapshot is associated with the identifier of the transaction snapshot used to create it. Subsequently, the metadata of this logical cleanup snapshot is persistently stored in the system directory table, and an associated index is created with the object identifier of the target table for subsequent fast retrieval.

[0055] At some point in the future, when the table is scheduled for emergency cleanup due to an accumulation of dead tuples, the assigned Autovacuum worker process will first attempt to load the latest logical cleanup snapshot associated with the table before performing physical cleanup. The worker process queries the system directory; if a valid snapshot record is found, it is loaded into memory. If the logical cleanup snapshot is successfully loaded, the worker process directly locates all historical dead tuple positions recorded in the logical snapshot and quickly reclaims these tuples. Since these positions are pre-calculated, this step avoids the overhead of scanning a large number of active tuples to find dead tuples. After cleaning up historical dead tuples, a regular incremental scan and cleanup is performed on newly generated dead tuples since the creation of the logical snapshot, based on the transaction snapshot associated with it. This embodiment of the application, through a two-stage model of snapshot-based historical incremental cleaning and regular processing of new additions, can shorten the time required for emergency cleanup, especially for large tables, enabling emergency response.

[0056] In one implementation of this application, before the scheduler prepares to allocate an Autovacuum worker process to a target table, it first checks the real-time I / O load level of the tablespace where the table resides. If the I / O load level of the tablespace has reached a preset high level, the scheduler will postpone the allocation of the original target table. Instead, it will attempt to select tables from other priority queues that are located in tablespaces with low I / O load levels as new scheduling targets. If, after searching, the I / O load level of all candidate tables does not meet the low condition, the scheduler will not force an allocation, but will enter a short waiting period (e.g., a 30-second delay) to reassess the I / O load of the target tablespace before deciding whether to proceed with the scheduling.

[0057] Furthermore, this application embodiment also includes concurrent cleanup optimization to accelerate the cleanup process of large tables. The triggering conditions include both table-level and system-level aspects: First, the data size of the target table must exceed a preset large table threshold; second, the current CPU utilization and I / O load rate of the system must simultaneously be lower than their respective idle thresholds. When both conditions are met, the scheduler determines that the current system is idle and suitable for handling large tasks, thereby automatically enabling PostgreSQL's parallel VACUUM function for a single cleanup operation of the large table. Specifically, the scheduler allocates multiple worker processes to the table to work collaboratively, scanning and cleaning data in parallel, thereby significantly shortening the overall cleanup time of the large table.

[0058] This application embodiment also automatically generates an interpretable decision log, recording priority scores, traditional model contributions, AI contributions, dominant deviation dimensions, UCB confidence intervals, congestion penalty values, and natural language decision suggestions. Furthermore, this application embodiment is fully compatible with existing PostgreSQL architectures, enhancing functionality through extended statistical information views and GUC parameters without requiring modifications to table structure definitions or the VACUUM core execution engine, thus reducing deployment risks and migration costs.

[0059] Figure 2 This is a schematic diagram of the structure of an Autovacuum process scheduling device based on priority scoring, provided as an embodiment of this application. Figure 2As shown, the Autovacuum process scheduling device 200 based on priority scoring includes: at least one processor 201; and a memory 202 communicatively connected to the at least one processor 201. The memory 202 stores instructions executable by the at least one processor 201. These instructions, when executed by the at least one processor 201, enable the at least one processor 201 to: obtain the running status information corresponding to the tables to be cleaned in the database during each scheduling cycle, and determine an initial priority score based on the running status information; determine a competition correction score based on the running status information and an online learning model, and adjust the score based on the current scheduling... The queue status and contention level correction score determine the congestion penalty, which is used to dynamically correct the initial priority score. Based on the time series model prediction and historical dead tuple data in the running status information, the future expansion risk value is determined, and the score after the first dynamic correction is dynamically corrected according to the future expansion risk value to obtain the dynamic priority score corresponding to the table to be cleaned. Based on the dynamic priority score, each table to be cleaned is placed into the scheduling queue of the corresponding priority. According to the real-time resource information of the system and the priority of the scheduling queue, the Autovacuum worker process resources in the database are dynamically allocated to execute the cleanup task.

[0060] This application provides a non-volatile computer storage medium storing computer-executable instructions. These instructions are configured to: within each scheduling cycle, acquire the running status information corresponding to the tables to be cleaned in the database, and determine an initial priority score based on the running status information; determine a contention correction score based on the running status information and an online learning model, and determine a congestion penalty based on the current scheduling queue status and the contention correction score, so as to perform a first dynamic correction on the initial priority score through the congestion penalty; determine a future expansion risk value based on time-series model predictions and historical dead tuple data in the running status information, and perform a second dynamic correction on the score after the first dynamic correction based on the future expansion risk value, so as to obtain a dynamic priority score corresponding to the tables to be cleaned; based on the dynamic priority scores, place each table to be cleaned into a scheduling queue of the corresponding priority; and dynamically allocate resources for the Autovacuum worker process in the database according to the real-time system resource information and the priority of the scheduling queue, so as to execute the cleanup task.

[0061] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments for devices and non-volatile computer storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0062] The above descriptions are merely embodiments of this application and are not intended to limit the scope of this application. For those skilled in the art, various modifications and variations can be made to the embodiments of this application. These modifications or substitutions do not cause the essence of the corresponding technical solutions to depart from the spirit and scope of the technical solutions in the embodiments of this application.

Claims

1. A database Autovacuum process scheduling method based on priority scoring, characterized in that, The method includes: Within each scheduling cycle, obtain the running status information of the table to be cleaned in the database, and determine the initial priority score based on the running status information; Based on the running status information and the online learning model, a contention correction score is determined, and a congestion penalty is determined based on the current scheduling queue status and the contention correction score, so as to perform a first dynamic correction on the initial priority score through the congestion penalty; Based on the time series model prediction and the historical dead tuple data in the running status information, the future expansion risk value is determined, and the score after the first dynamic correction is adjusted according to the future expansion risk value to obtain the dynamic priority score corresponding to the table to be cleaned. Based on the dynamic priority score, each of the tables to be cleaned is placed into the scheduling queue of the corresponding priority. Based on the system's real-time resource information and the priority of the scheduling queue, the resources of the Autovacuum worker processes in the database are dynamically allocated to execute cleanup tasks.

2. The database Autovacuum process scheduling method based on priority scoring according to claim 1, characterized in that, Based on the running status information and the online learning model, a contention correction score is determined, and a congestion penalty is determined based on the current scheduling queue status and the contention correction score. This congestion penalty is then used to dynamically correct the initial priority score. Specifically, this includes: If the running value in the running status information is greater than the preset running value threshold, the table to be cleaned is assigned the highest priority score and queue allocation is performed directly. Otherwise, a multidimensional feature vector is constructed based on the running status information, and the multidimensional feature vector is input into a clustering model to output the behavior pattern category corresponding to the table to be cleaned through the clustering model, and the preset weight allocation template corresponding to the behavior pattern category is used as the basic weight. The current value of the running status indicator corresponding to the table to be cleaned is determined, and the deviation between the current value and the baseline value of the historical similar table is determined. The running status indicators of each dimension of the table to be cleaned are weighted and summed based on the deviation and the basic weight to obtain the basic score item. The running status indicator includes one of the following: dead tuple ratio, update rate, and I / O load. The model contribution score is determined by calculating the feature vector corresponding to the current state of the table to be cleaned based on the online learning model. The dequeue congestion penalty score is determined based on the current priority level of the table to be cleared and the real-time length of each global scheduling queue. The basic scoring item is added to the model contribution score to obtain the competition correction score. The initial priority score, the competition correction score, and the queue congestion penalty score are then combined to complete the first dynamic correction.

3. The database Autovacuum process scheduling method based on priority scoring according to claim 1, characterized in that, Based on the time-series model prediction and historical dead tuple data in the operational status information, a future expansion risk value is determined, and a second dynamic correction is performed on the score after the first dynamic correction based on the future expansion risk value, specifically including: Based on the additive decomposition time series model and the historical dead tuple data of the table to be cleaned, the proportion of dead tuples in the table to be cleaned in the future within a preset time period is predicted. If the predicted proportion of future dead groups is greater than the first risk threshold, and the current proportion of dead groups is not greater than the second risk threshold, then the trend prediction adjustment score is determined according to the degree to which the predicted proportion of future dead groups exceeds the first risk threshold. The trend prediction adjustment score is added to the score after the first dynamic correction to complete the second dynamic correction.

4. The database Autovacuum process scheduling method based on priority scoring according to claim 3, characterized in that, After predicting the proportion of dead tuples in the table to be cleaned within a preset future time period based on the additive decomposition time series model and the historical dead tuple data of the table to be cleaned, the method further includes: If the proportion of dead tuples in the table to be cleaned is greater than the pre-cleaning trigger threshold within a preset future time, and the current proportion of dead tuples in the table to be cleaned is not greater than the pre-cleaning safety threshold, then a logical cleanup snapshot is created for the table to be cleaned; wherein, the logical cleanup snapshot is used to record the location information of dead tuples in the table to be cleaned that meet the safety cleanup conditions, and is associated with the corresponding database transaction snapshot; The metadata of the logical cleanup snapshot is persistently stored and associated with the table to be cleaned. When the table to be cleaned reaches the emergency cleanup trigger condition, the Autovacuum worker process loads the logical cleanup snapshot associated with the table to be cleaned before performing physical cleanup; If loading is successful, the Autovacuum worker process performs incremental physical cleanup based on the dead tuple location information recorded in the logical cleanup snapshot and the newly generated dead tuples after the transaction snapshot corresponding to the logical cleanup snapshot.

5. The database Autovacuum process scheduling method based on priority scoring according to claim 1, characterized in that, The step of placing each of the tables to be cleaned into a scheduling queue of the corresponding priority based on the dynamic priority score specifically includes: The dynamic priority score of the table to be cleaned is compared with the preset priority range threshold to determine the initial priority level; Based on the current enqueue timestamp, the dynamic priority score, and the preset penalty coefficient, an internal sorting key is calculated. Based on the internal sorting key, all tables in the scheduling queue are sorted to determine the scheduling order of the table to be cleared in the scheduling queue. If the table to be cleaned is determined to be of the lowest priority level, then before placing it into the lowest priority queue, the table to be cleaned is subjected to a starvation prevention condition detection. The starvation prevention condition includes one of the following: not meeting any preset emergency cleanup conditions, the dynamic priority score being lower than the preset priority score threshold, or the time difference between the current time and the time difference between the last time the table to be cleaned was completed being greater than the preset starvation time window. If the table to be cleaned meets the anti-starvation condition, then the dynamic priority score of the table to be cleaned will be increased.

6. The database Autovacuum process scheduling method based on priority scoring according to claim 1, characterized in that, The dynamic allocation of Autovacuum worker process resources in the database based on real-time system resource information and the priority of the scheduling queue specifically includes: The Autovacuum process resource pool to be allocated is divided into a dedicated worker process pool and a shared worker process pool; wherein, the dedicated worker process pool is used to process tasks in the highest priority scheduling queue, and the shared worker process pool is used to process tasks in other priority scheduling queues. If the highest priority scheduling queue is not empty, then worker processes are allocated in the dedicated worker process pool, and the allocation quantity is determined based on the minimum value among the upper limit of the capacity of the dedicated worker process pool, the current number of idle processes, and the number of tasks to be processed in the highest priority scheduling queue. After satisfying the allocation requirements of the highest priority scheduling queue, if there are remaining work processes, a round-robin method is used to allocate processes to the next highest and lower priority scheduling queues until all work processes are exhausted or all tasks in all queues have been allocated. If the execution time of any worker process's cleanup operation on a single table exceeds the maximum continuous execution time slice and is still not completed, then after the process completes the cleanup operation of the currently processing data page, the current cleanup session will be terminated and the worker process resources will be released. The task of this interrupted cleanup will be placed back into the tail of its priority scheduling queue, waiting for the next scheduling.

7. The database Autovacuum process scheduling method based on priority scoring according to claim 1, characterized in that, After performing the cleanup task, the method further includes: Based on a preset multi-objective reward function, the comprehensive reward value generated by this cleanup task is determined; wherein, the multi-objective reward function includes the following dimensions: the efficiency of this cleanup in improving table bloat, the business importance level of the target table, the degree of impact on I / O performance during the execution of the cleanup task, and the fairness reflected by the time since the last cleanup of the target table; Obtain the feature vector corresponding to the table being cleaned at the scheduling decision time, and use the feature vector and the comprehensive reward value as training samples to input into the online learning model to update the internal parameters of the online learning model; Based on the error between the predicted reward value of the cleanup task corresponding to the online learning model and the actual comprehensive reward value obtained, the moving average error within the first preset time period is determined. When the moving average error continues to exceed a preset anomaly threshold within a second preset time period, the trust coefficient corresponding to the online learning model is dynamically reduced, and when the trust coefficient decays to zero, a safety rollback mechanism is triggered, switching to a working mode that makes scheduling decisions only based on preset rules and weights.

8. The database Autovacuum process scheduling method based on priority scoring according to claim 7, characterized in that, The updating of the internal parameters of the online learning model specifically includes: Obtain the historical parameters used by the online learning model to maintain the table to be cleaned; wherein, the historical parameters include a parameter vector and a covariance inverse matrix; First data is constructed based on the product of the covariance inverse matrix, the eigenvector, and the transpose of the eigenvector. Based on the first data and the ratio between the eigenvector and the current covariance inverse matrix, a correction term is obtained. Based on the difference between the current covariance inverse matrix and the correction term, the covariance inverse matrix is ​​incrementally updated; The product of the actual obtained comprehensive reward value and the feature vector is added to the reward vector maintained by the online learning model for the table to be cleaned. The updated covariance inverse matrix is ​​multiplied by the updated reward vector to obtain the updated model parameter vector, thus completing the parameter update.

9. A database Autovacuum process scheduling device based on priority scoring, characterized in that, The device includes a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the device is triggered to perform the method according to any one of claims 1-8.

10. A non-volatile computer storage medium storing computer-executable instructions, characterized in that, The computer-executable instructions are capable of performing the method described in any one of claims 1-8.

Citation Information

Patent Citations

  • Database performance optimization method, storage medium and computer equipment

    CN115982130A

  • Method, system and equipment for resource management of database and medium

    CN120631596A