博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PostgreSQL的autovacuum 与 vacuum full
阅读量:5798 次
发布时间:2019-06-18

本文共 2825 字,大约阅读时间需要 9 分钟。

首先要了解 vacuum 与  vacuum all的区别:

vacuum 就是进行扫除,找到那些旧的“死”数据,把它们所知的行标记为可用状态。但是它不进行空间合并。

vacuum full,就是除了 vacuum,还进行空间合并,因此它需要lock table。

而 autovacuum,可以理解为 定时自动进行  vacuum 。

对于有大量update 的表,vacuum full是没有必要的,因为它的空间还会再次增长,所以vacuum就足够了。

所以说: standard VACUUMs often enough to avoid needing VACUUM FULL

并且:    The autovacuum daemon attempts to work this way, and in fact will never issue VACUUM FULL. 

The usual goal of routine vacuuming is to do standard VACUUMs often enough to avoid needing VACUUM FULL. The autovacuum daemon attempts to work this way, and in fact will never issue VACUUM FULL. In this approach, the idea is not to keep tables at their minimum size, but to maintain steady-state usage of disk space: each table occupies space equivalent to its minimum size plus however much space gets used up between vacuumings. Although VACUUM FULL can be used to shrink a table back to its minimum size and return the disk space to the operating system, there is not much point in this if the table will just grow again in the future. Thus, moderately-frequent standard VACUUM runs are a better approach than infrequent VACUUM FULL runs for maintaining heavily-updated tables.

因此:

Moderately-frequent standard VACUUM runs are a better approach than infrequent VACUUM FULL runs for maintaining heavily-updated tables.

 关于 VACUUM FULL:

VACUUM FULL requires exclusive lock on the table it is working on, and therefore cannot be done in parallel with other use of the table. Generally, therefore, administrators should strive to use standard VACUUM and avoid VACUUM FULL.

VACUUM FULL要写新表、新文件的:

The standard form of VACUUM removes dead row versions in tables and indexes and marks the space available for future reuse. However, it will not return the space to the operating system, except in the special case where one or more pages at the end of a table become entirely free and an exclusive table lock can be easily obtained. In contrast, VACUUM FULL actively compacts tables by writing a complete new version of the table file with no dead space. This minimizes the size of the table, but can take a long time. It also requires extra disk space for the new copy of the table, until the operation completes.

对于 大量 update/delete 的表,普通的vacuum可能是不合适的,此时需要VACUUM FULL:

(有点前后矛盾,可能是指数据变更量更大的情况)

Plain VACUUM may not be satisfactory when a table contains large numbers of dead row versions as a result of massive update or delete activity. If you have such a table and you need to reclaim the excess disk space it occupies, you will need to use VACUUM FULL, or alternatively CLUSTER or one of the table-rewriting variants of ALTER TABLE. These commands rewrite an entire new copy of the table and build new indexes for it. All these options require exclusive lock.

 

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/3272620.html,如需转载请自行联系原作者

你可能感兴趣的文章
Android图片添加水印图片并把图片保存到文件存储
查看>>
C#字符串的不变性
查看>>
前端路由简介以及vue-router实现原理
查看>>
比特币系统采用的公钥密码学方案和ECDSA签名算法介绍——第二部分:代码实现(C语言)...
查看>>
分享15款很实用的 Sass 和 Compass 工具
查看>>
AMD优势: 与众不同 选择丰富
查看>>
玩转高性能超猛防火墙nf-HiPAC
查看>>
简单按日期查询mysql某张表中的记录数
查看>>
自动化部署之jenkins发布PHP项目
查看>>
C/C++编程可用的Linux自带工具
查看>>
Oracle ASM 翻译系列第六弹:高级知识 如何映射asmlib管理的盘到它对应的设备名...
查看>>
多线程之volatile关键字
查看>>
如何判断webview是不是滑到底部
查看>>
Raptor实践2——控制结构
查看>>
Smartisan OS一步之自定义拖拽内容
查看>>
海贼王十大悲催人物
查看>>
org.hibernate.MappingException: No Dialect mapping for JDBC type: -1 搞定!
查看>>
热点热词新闻资讯API开放接口(永久免费开放)
查看>>
【第二章】 IoC 之 2.2 IoC 容器基本原理 —— 跟我学Spring3
查看>>
8.1_Linux习题和作业
查看>>