当前位置:网站首页>Process of vacuum and vacuum full
Process of vacuum and vacuum full
2022-06-25 19:09:00 【Daiyuanpei】
For concurrency control of database system ,PostgreSQL use MVCC( Multi version concurrency control ) To deal with . This mechanism has one drawback , As time goes on , Accumulated in data files dead tuples More and more . How to clean up these dead tuples, This is the time vacuum Handle .
PostgreSQL Systematic vacuum It is a routine maintenance process , The system will also start when the service is started autovacuum The daemon maintains this , Of course, there are vacuum The command allows the user to manually execute vacuum operation . Except for cleaning up dead tuples,vacuum And frozen transactions ID The function of , Because now PostgreSQL The business of ID Only support 32 position ( Probably 40 A hundred million things ), When a transaction ID After reaching the maximum value , It will re 0 Start , At this time, the previous affairs will become “ future ” The transaction becomes invisible .
Here is the main introduction vacuum clear dead tuples The process of . Cleaning up dead tuples when , The system has two processing methods :vacuum and vacuum full. The main differences are as follows :
| vacuum | vacuum full |
|---|---|
| Just put the... In the table dead tuples Make a deletion mark , There is no real physical deletion ;vacuum In the process , The data table can be accessed normally | Physically delete... In the table dead tuples, Free up space for the operating system ;vacuum full In the process , Table locked , Access not allowed |
Vacuum The process
vacuum The implementation process of is mainly divided into the following three steps :
1、 eliminate dead tuples Point to the index tuples
In the process ,vacuum Will scan the target table in sequence , And build a dead tuples Composed of list Linked list , The list The linked list will be stored in maintenance_work_mem In cache . then vacuum according to dead tuples list remove dead tuples Point to the index.
2、 remove dead tuples, to update VM and FSM
The removal here dead tuples Just mark the space as reusable , There is no real physical deletion . therefore vacuum After cleaning the table , The actual space of the table is not reduced .dead tuples After making the removal mark ,vacuum The remaining tuples are rearranged for defragmentation . then , Need to update the target table VM( Visibility mapping file ) and FSM( Free space mapping file ).
3、 Update statistics and related system tables
Last , You need to update vacuum Statistics of the target table ( To adapt to the latest query optimization ) And related system tables .
Vacuum Full The process
Vacuum Full and Vacuum The big difference is this ,Vacuum Full It's physical deletion dead tuples, Free up space for the operating system , So in vacuum full after , The size of the table will be reduced to the actual space size . Its processing process and vacuum Very different , The processing steps are as follows :
1、vacuum full At the beginning of execution , The system will first create a AccessExclusiveLock, No more outside access is allowed ( Prepare for later copies ), Then create a new table with the same table structure as the target table .
2、 Scan target table , Put... In the watch live tuples Copy to new table .
3、 Delete target table , On the new watch , Recreate index , to update VM,FSM And Statistics , Relevant system tables, etc .
therefore ,vacuum full The essence of is to generate a new data file , Then put the original table live tuples Stored in the data file . contrast vacuum,vacuum full The disadvantage is that the table cannot be accessed during execution , Due to the need to import into the new table live tuples data , Its execution efficiency will also be very slow . The advantage is that after execution , Tablespaces only store live tuples, No redundancy dead tuples, It will improve the efficiency of executing queries .
AutoVacuum Daemon
because vacuum It is a routine maintenance of database system , So after the system starts , Will open a autovacuum Daemons deal specifically with this .autovacuum The cleaning process is generally used vacuum Avoid using vacuum full. The reason is that ,vacuum Although the minimum size of the table can be maintained , But if the table still has room to grow , It doesn't make much sense , Especially for frequently written tables . and vacuum It is also more efficient than vacuum full good .
Above mentioned autovacuum The process is a launcher process , It doesn't do vacuum operation , It starts vacuum worker process , Then from vacuum worker The process proceeds accordingly vacuum and analyze operation .

autovacuum The process will autovacuum_naptime Start the database within the time interval autovacuum worker process . Then each worker The process checks every table in the database , Execute when needed vacuum or analyze operation . If there is N A database , Then every autovacuum_naptime/N Seconds will start a new worker process , Only up to... Are allowed at one time autovacuum_max_workers individual worker Process is running , If there is more than autovacuum_max_workers Databases need to be processed , The next database will be in the first worker It will be handled immediately after completion .
边栏推荐
- 广州华锐互动VR全景为各行各业带来发展
- 网络安全检测与防范 测试题(四)
- Current situation and development suggestions of China's green PPP project industry: the investment scale is expanding, and the existing problems need to be improved to further promote the healthy dev
- Lilda Bluetooth air conditioning receiver helps create a more comfortable road life
- Network security detection and prevention test questions (I)
- Sorting out the latest data mining competition scheme!
- Huawei released two promotion plans to promote AI talent development and scientific research innovation
- Analysis on China's aluminum foil output, trade and enterprise leading operation in 2021: dongyangguang aluminum foil output is stable [figure]
- Training of long and difficult sentences in postgraduate entrance examination day88
- Analysis of China's medical device industry development environment (PEST) in 2021: the awareness of medical care is enhanced, and the demand for medical device products is also rising [figure]
猜你喜欢
![Analysis on development scale and development trend of China's night economy industry in 2021 [figure]](/img/57/d6821fca9a608bf33e78287cf26bae.jpg)
Analysis on development scale and development trend of China's night economy industry in 2021 [figure]

Apifox simple understanding -- the integrator of web side testing

Laravel validation rule followed Role of auth:: id()

Sorting out the latest data mining competition scheme!

Why are life science enterprises on the cloud in succession?
![Analysis on the development trend of China's intense pulsed light equipment industry in 2021: the market scale is growing, and the proportion of imported brands is large [figure]](/img/15/4477a850044136bb4b1ee92ab6df45.jpg)
Analysis on the development trend of China's intense pulsed light equipment industry in 2021: the market scale is growing, and the proportion of imported brands is large [figure]
![QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]](/img/25/298dc7b79dddd05914d5f3ba070555.png)
QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]
![Current situation and trend analysis of China's glass packaging containers in 2021: the revenue of glass packaging containers increases year by year [figure]](/img/19/d93c8647415c593de9c3c959f72d64.jpg)
Current situation and trend analysis of China's glass packaging containers in 2021: the revenue of glass packaging containers increases year by year [figure]

Paddleocr learning (II) paddleocr detection model training
![[C language practice - print the upper triangle and its deformation (with blank version)]](/img/df/f38dc57c6a2de522acd91929ced1ad.png)
[C language practice - print the upper triangle and its deformation (with blank version)]
随机推荐
QQ机器人:群成员自我禁言管理【最新beta2版本】
Guangzhou Sinovel interactive VR panorama brings development to all walks of life
网络安全检测与防范 测试题(五)
Training of long and difficult sentences in postgraduate entrance examination day90
[elt.zip] openharmony paper Club - witness file compression system erofs
Network security detection and prevention test questions (I)
Training of long and difficult sentences in postgraduate entrance examination day92
TCP/IP 测试题(三)
2017 reading (word memory)
Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
Under what circumstances do you need to manually write the @bean to the container to complete the implementation class
Electronic basic project construction & communication between main thread and rendering thread
请问同花顺开户安全吗?
2021 development status of China's cloud game industry and analysis of major service providers: Although cloud games are still in their infancy, the market prospect is huge [figure]
Overview and trend analysis of China's foreign direct investment industry in 2020 [figure]
mysql视图讲解
Solidity date tool
mysql my. Understanding CNF depends on configuration
PHP database connection version1.1
想知道新股民怎样炒股票开户?在线开户安全么?