• PG数据库表占用空间大小查询


    1.查看所有表所占磁盘空间大小

    select sum(t.size) from (
    SELECT table_schema || '.' || table_name AS table_full_name, pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')AS size
    FROM information_schema.tables
    ORDER BY
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC
    ) t

    2.查看每个表所占用磁盘空间大小

    SELECT table_schema || '.' || table_name AS table_full_name, pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')AS size
    FROM information_schema.tables
    ORDER BY
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC

    3.查看数据库大小

    -- \加上字母l,相当于mysql的,mysql> show databases;
    playboy=> \l                         
            List of databases  
       Name    |  Owner   | Encoding  
    -----------+----------+----------  
     playboy   | postgres | UTF8  
     postgres  | postgres | UTF8  
     template0 | postgres | UTF8  
     template1 | postgres | UTF8  
      
    -- 查看playboy数据库的大小
    playboy=> select pg_database_size('playboy');      
     pg_database_size  
    ------------------  
              3637896  
    (1 row)  
      
    -- 查看所有数据库的大小
    playboy=> select pg_database.datname, pg_database_size(pg_database.datname) AS size from pg_database;      
      datname  |  size  
    -----------+---------  
     postgres  | 3621512  
     playboy   | 3637896  
     template1 | 3563524  
     template0 | 3563524  
    (4 rows)  
      
    -- 以KB,MB,GB的方式来查看数据库大小
    playboy=> select pg_size_pretty(pg_database_size('playboy'));        
     pg_size_pretty  
    ----------------  
     3553 kB  
    (1 row)  

    4.查看表大小

    -- 相当于mysql的,mysql> desc test; 
    playboy=> \d test;                  
                Table "public.test"  
     Column |         Type          | Modifiers  
    --------+-----------------------+-----------  
     id     | integer               | not null  
     name   | character varying(32) |  
    Indexes: "playboy_id_pk" PRIMARY KEY, btree (id)  
      
    -- 查看表大小
    playboy=> select pg_relation_size('test');     
     pg_relation_size  
    ------------------  
                    0  
    (1 row)  
      
    -- 以KB,MB,GB的方式来查看表大小  
    playboy=> select pg_size_pretty(pg_relation_size('test'));   
     pg_size_pretty  
    ----------------  
     0 bytes  
    (1 row)  
      
    -- 查看表的总大小,包括索引大小
    playboy=> select pg_size_pretty(pg_total_relation_size('test'));     
     pg_size_pretty  
    ----------------  
     8192 bytes  
    (1 row)  

    5.查看所有所占磁盘空间大小

    -- 相当于mysql的,mysql> show index from test; 
    playboy=> \di                       
                    List of relations  
     Schema |     Name      | Type  |  Owner  | Table  
    --------+---------------+-------+---------+-------  
     public | playboy_id_pk | index | playboy | test  
    (1 row)  
      
    -- 查看索引大小
    playboy=> select pg_size_pretty(pg_relation_size('playboy_id_pk'));      
     pg_size_pretty  
    ----------------  
     8192 bytes  
    (1 row)  

    6.查看表空间大小

    -- 查看所有表空间  
    playboy=> select spcname from pg_tablespace;         
      spcname  
    ------------  
     pg_default  
     pg_global  
    (2 rows)  
      
    -- 查看表空间大小
    playboy=> select pg_size_pretty(pg_tablespace_size('pg_default'));     
     pg_size_pretty  
    ----------------  
     14 MB  
    (1 row)  
  • 相关阅读:
    Vsftpd 3.0.2 正式版发布
    Putdb WebBuilder 6.5 正式版本发布
    SoaBox 1.1.6 GA 发布,SOA 模拟环境
    pynag 0.4.6 发布,Nagios配置和插件管理
    Percona Playback 0.4,MySQL 负荷回放工具
    xombrero 1.3.1 发布,微型 Web 浏览器
    Hypertable 0.9.6.4 发布,分布式数据库
    libmemcached 1.0.11 发布
    CryptoHeaven 3.7 发布,安全邮件解决方案
    Android Activity生命周期
  • 原文地址:https://www.cnblogs.com/limaosheng/p/15839276.html
Copyright © 2020-2023  润新知