当前位置:   article > 正文

PG数据库中表 索引 所占用空间大小查询_pg 查看索引大小

pg 查看索引大小

 

  • 查看所有表所占磁盘空间大小
  1. select sum(t.size) from (
  2. SELECT table_schema || '.' || table_name AS table_full_name, pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')AS size
  3. FROM information_schema.tables
  4. ORDER BY
  5. pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC
  6. ) t
  • 查看每个表所占用磁盘空间大小
  1. SELECT table_schema || '.' || table_name AS table_full_name, pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')AS size
  2. FROM information_schema.tables
  3. ORDER BY
  4. pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC
  • 查看数据库大小
  1. playboy=> \l //\加上字母l,相当于mysql的,mysql> show databases;
  2. List of databases
  3. Name | Owner | Encoding
  4. -----------+----------+----------
  5. playboy | postgres | UTF8
  6. postgres | postgres | UTF8
  7. template0 | postgres | UTF8
  8. template1 | postgres | UTF8
  9. playboy=> select pg_database_size('playboy'); //查看playboy数据库的大小
  10. pg_database_size
  11. ------------------
  12. 3637896
  13. (1 row)
  14. playboy=> select pg_database.datname, pg_database_size(pg_database.datname) AS size from pg_database; //查看所有数据库的大小
  15. datname | size
  16. -----------+---------
  17. postgres | 3621512
  18. playboy | 3637896
  19. template1 | 3563524
  20. template0 | 3563524
  21. (4 rows)
  22. playboy=> select pg_size_pretty(pg_database_size('playboy')); //以KB,MB,GB的方式来查看数据库大小
  23. pg_size_pretty
  24. ----------------
  25. 3553 kB
  26. (1 row)
  • 查看表大小
  1. playboy=> \d test; //相当于mysql的,mysql> desc test;
  2. Table "public.test"
  3. Column | Type | Modifiers
  4. --------+-----------------------+-----------
  5. id | integer | not null
  6. name | character varying(32) |
  7. Indexes: "playboy_id_pk" PRIMARY KEY, btree (id)
  8. playboy=> select pg_relation_size('test'); //查看表大小
  9. pg_relation_size
  10. ------------------
  11. 0
  12. (1 row)
  13. playboy=> select pg_size_pretty(pg_relation_size('test')); //以KB,MB,GB的方式来查看表大小
  14. pg_size_pretty
  15. ----------------
  16. 0 bytes
  17. (1 row)
  18. playboy=> select pg_size_pretty(pg_total_relation_size('test')); //查看表的总大小,包括索引大小
  19. pg_size_pretty
  20. ----------------
  21. 8192 bytes
  22. (1 row)
  • 查看所有所占磁盘空间大小
  1. playboy=> \di //相当于mysql的,mysql> show index from test;
  2. List of relations
  3. Schema | Name | Type | Owner | Table
  4. --------+---------------+-------+---------+-------
  5. public | playboy_id_pk | index | playboy | test
  6. (1 row)
  7. playboy=> select pg_size_pretty(pg_relation_size('playboy_id_pk')); //查看索大小
  8. pg_size_pretty
  9. ----------------
  10. 8192 bytes
  11. (1 row)
  • 查看表空间大小
  1. playboy=> select spcname from pg_tablespace; //查看所有表空间
  2. spcname
  3. ------------
  4. pg_default
  5. pg_global
  6. (2 rows)
  7. playboy=> select pg_size_pretty(pg_tablespace_size('pg_default')); //查看表空间大小
  8. pg_size_pretty
  9. ----------------
  10. 14 MB
  11. (1 row)

查看表索引大小 

select pg_size_pretty(pg_indexes_size('bu_table'));

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/266618
推荐阅读
相关标签
  

闽ICP备14008679号