Greenplum中的vacuum和analyze

来源:互联网 发布:软件测试考试题库 编辑:程序博客网 时间:2024/05/10 18:44
Greenplum中的vacuum和analyze
首先说说vacuum,该选项主要是清理数据库表中的垃圾空间
定义:
VACUUM reclaims storage occupied by deleted tuples. In normal Greenplum Database operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present on disk until a VACUUM is done. Therefore it is necessary to do VACUUM periodically, especially on frequently-updated tables.
With no parameter, VACUUM processes every table in the current database. With a parameter, VACUUM processes only that table.
即对于delete或update操作造成的实际物理空间没有从所对应的表中移除的话,vacuum操作可以将此磁盘释放出来,所以对那些经常性更新的表很有需要来做下vacuum操作。
举个例子:
新建普通堆栈表 tempuse.clq_test1(440行数据)
select count(1) from tempuse.clq_test1;
--440
select pg_relation_size('tempuse.clq_test1')
得到大小是327680Bytes
delete from tempuse.clq_test1 where create_time>='2010-11-26;
--查询成功: 共计 5 行受到影响,耗时: 47 毫秒(ms)。
select pg_relation_size('tempuse.clq_test1')
--大小还是327680Bytes
我们再来做下vacuum
vacuum tempuse.clq_test1
查询成功但无结果,耗时: 25578 毫秒(ms)。
select pg_relation_size('tempuse.clq_test1')
得到大小是262144Bytes
可以看到空间明显收缩了。
该动作会消耗系统一定的资源,引起系统的IO上升,对有一定系统瓶颈来说容易造成堵塞,严重会把GP宕掉,造成数据库瞬断。
一般不建议vacuum库中全表,通常做法是 vacuum 指定的表
但是在PG中VACUUM的效果并不明显,一般都可认为不回收空间,只有vacuum full才会。
0 0
原创粉丝点击