vacuum full table释放表占用的空间

可以做这样一个实验:

create table test3 (a int primary key, b text);

insert into test3 select generate_series(1, 1000000), md5(random()::text);

select pg_size_pretty(pg_relation_size('test3'));

delete from test3 where mod(a, 2) = 0;

select pg_size_pretty(pg_relation_size('test3'));

vacuum full test3

select pg_size_pretty(pg_relation_size('test3'));

表经过一系列删改操作后,虽然空间可以被重复使用,但空间并不一定释放,给操作系统,vacuum full tablename,可以对表的空间进行碎片整理和释放,但是这样会锁住表。

你可能感兴趣的:(PostgreSQL,数据库)