zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    Mac OS X上安装 Ruby运行环境
    MAC 命令行工具(Command Line Tools)安装
    如何快速正确的安装 Ruby, Rails 运行环境
    安裝 Rails 開發環境
    用模块化编程
    阅读技术书籍
    NHibernate构建一个ASP.NET MVC应用程序
    SQL注入
    Redis
    Code digest
  • 原文地址:https://www.cnblogs.com/zhangfx01/p/10216227.html
Copyright © 2011-2022 走看看