apple=# create table test(id integer, info text);
CREATE TABLE
apple=# insert into test select generate_series(1, 100000), md5('test');
INSERT 0 100000
apple=# select * from test limit 1;
id | info
----+----------------------------------
1 | 098f6bcd4621d373cade4e832627b4f6
(1 row)
apple=# select pg_size_pretty(pg_relation_size('test'));
pg_size_pretty
----------------
6672 kB
(1 row)
apple=# create index idx_test_id on test(id);
CREATE INDEX
apple=# select * from pg_indexes_size('test');
pg_indexes_size
-----------------
2260992
(1 row)
apple=# select * from pg_size_pretty(pg_indexes_size('test'));
pg_size_pretty
----------------
2208 kB
(1 row)
apple=# truncate test;
TRUNCATE TABLE
apple=# select * from pg_size_pretty(pg_indexes_size('test&#
PostgreSQL truncate table会释放索引的空间
最新推荐文章于 2024-07-09 06:53:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)