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;

猜你喜欢

转载自www.cnblogs.com/zhangfx01/p/10216227.html