当前位置:网站首页>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 .
边栏推荐
- Guangzhou Sinovel interactive VR panorama brings development to all walks of life
- Connecting PHP to MySQL instances in the lamp environment of alicloud's liunx system
- Electronic package to generate EXE file
- Combing the latest Data Mining Event Scheme!
- Solidity date tool
- SVN介绍及使用总结
- Google cloud SSH enable root password login
- Tcp/ip test questions (II)
- ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS
- Miner's Diary: why should I go mining on April 5, 2021
猜你喜欢

Ali vision AI training camp-day01

SVN介绍及使用总结

QQ机器人疫情查询/疫情关注等【最新beta2版本】
![Analysis on planting area, output and import of sugarcane in Guangxi in 2021: the output of sugarcane in Guangxi accounts for 68.56% of the total output of sugarcane in China [figure]](/img/c9/f2a8c3c4ddf28d96d8bfc7bc31a4fe.jpg)
Analysis on planting area, output and import of sugarcane in Guangxi in 2021: the output of sugarcane in Guangxi accounts for 68.56% of the total output of sugarcane in China [figure]

为什么生命科学企业都在陆续上云?

云上弹性高性能计算,支持生命科学产业高速发展、降本增效
![[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)]

158_ Model_ Power Bi uses DAX + SVG to open up almost all possibilities for making business charts
![Analysis on market scale and supply of China's needle coke industry in 2020 [figure]](/img/79/6b08b62be8768484f548b6e18bd810.jpg)
Analysis on market scale and supply of China's needle coke industry in 2020 [figure]

Elastic high-performance computing on the cloud supports the rapid development of the life science industry, reducing costs and increasing efficiency
随机推荐
158_模型_Power BI 使用 DAX + SVG 打通制作商業圖錶幾乎所有可能
QQ robot official plug-in loading configuration method [beta2 version]
GenICam GenTL 标准 ver1.5(1)
Oriental Wealth function (the most complete edition of Childe Yong)
Network security detection and prevention test questions (I)
两轮市场红海,利尔达芯智行如何乘风破浪?
Google cloud SSH enable root password login
JVM|运行时数据区(堆空间)
IDEA常用插件
Error record: preg_ match(): Compilation failed: range out of order in character class at offset 13
Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)
Analysis of China's road freight volume, market scale and competition pattern in 2020 [figure]
Training of long and difficult sentences in postgraduate entrance examination day89
Training of long and difficult sentences in postgraduate entrance examination day88
Detailed explanation of oauth2 - Introduction (I)
Cutting feet to fit shoes - talking about the ramp reconstruction on the track
Training of long and difficult sentences in postgraduate entrance examination day90
Laravel validation rule followed Role of auth:: id()
Ruffian Heng embedded semimonthly issue 57
Shell jump loop shift parameter left use of function