1. 程式人生 > >postgresql-查看錶大小

postgresql-查看錶大小

drop table tablesize create table tablesize( phone int) create table tablesize( phone text) create table tablesize( phone char(30)) create table tablesize( phone varchar(3000)) create index i_table_size_phone on tablesize(phone) insert into tablesize values('1111') insert into tablesize values(1111)   select pg_size_pretty(pg_relation_size('tablesize'))--表達小,不包含索引和toast   select pg_size_pretty(pg_relation_size('i_table_size_phone'))--索引大小 select pg_size_pretty(pg_total_relation_size('tablesize')); --表達小包含toast,和索引大小   select pg_size_pretty(pg_table_size('tablesize'))--表達小,包含toast大小     select oid from pg_database where datname = 'test'   select pg_relation_filepath('tablesize');   select pg_column_size('phone') --查看錶大小和索引大小 select relname,pg_size_pretty(pg_relation_size(oid)) from pg_class where relname like '%t1%' order by relname;   select oid,relfilenode,relname from pg_class where relfilenode = '20221126' select oid,relfilenode,relname from pg_class where relfilenode = '20221113'   pg查看錶膨脹: 查看錶膨脹(對所有表產進行膨脹率排序)   SQL文如下:   SELECT schemaname||'.'||relname as table_name, pg_size_pretty(pg_relation_size(schemaname||'.'||relname)) as table_size, n_dead_tup, n_live_tup, round(n_dead_tup * 100 / (n_live_tup + n_dead_tup),2) AS dead_tup_ratio FROM pg_stat_all_tables WHERE n_dead_tup >= 1000 ORDER BY dead_tup_ratio DESC LIMIT 10;