postgresql 查看数据库,表,索引,表空间以及大小

浏览: 2515

1,查看数据库

查看复制打印?

  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.   
  10. playboy=> select pg_database_size('playboy');    //查看playboy数据库的大小  
  11.  pg_database_size  
  12. ------------------  
  13.           3637896  
  14. (1 row)  
  15.   
  16. playboy=> select pg_database.datname, pg_database_size(pg_database.datname) AS size from pg_database;    //查看所有数据库的大小  
  17.   datname  |  size  
  18. -----------+---------  
  19.  postgres  | 3621512  
  20.  playboy   | 3637896  
  21.  template1 | 3563524  
  22.  template0 | 3563524  
  23. (4 rows)  
  24.   
  25. playboy=> select pg_size_pretty(pg_database_size('playboy'));      //以KB,MB,GB的方式来查看数据库大小  
  26.  pg_size_pretty  
  27. ----------------  
  28.  3553 kB  
  29. (1 row)  

2,查看多表

查看复制打印?

  1. playboy=> \dt                      //相当于mysql的,mysql> show tables;  
  2.         List of relations  
  3.  Schema | Name | Type  |  Owner  
  4. --------+------+-------+---------  
  5.  public | test | table | playboy  
  6. (1 row)  

3,查看单表

查看复制打印?

  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.   
  9. playboy=> select pg_relation_size('test');   //查看表大小  
  10.  pg_relation_size  
  11. ------------------  
  12.                 0  
  13. (1 row)  
  14.   
  15. playboy=> select pg_size_pretty(pg_relation_size('test'));   //以KB,MB,GB的方式来查看表大小  
  16.  pg_size_pretty  
  17. ----------------  
  18.  0 bytes  
  19. (1 row)  
  20.   
  21. playboy=> select pg_size_pretty(pg_total_relation_size('test'));   //查看表的总大小,包括索引大小  
  22.  pg_size_pretty  
  23. ----------------  
  24.  8192 bytes  
  25. (1 row)  

4,查看索引

查看复制打印?

  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.   
  8. playboy=> select pg_size_pretty(pg_relation_size('playboy_id_pk'));    //查看索大小  
  9.  pg_size_pretty  
  10. ----------------  
  11.  8192 bytes  
  12. (1 row)  

5,查看表空间,以及大小

查看复制打印?

  1. playboy=> select spcname from pg_tablespace;         //查看所有表空间  
  2.   spcname  
  3. ------------  
  4.  pg_default  
  5.  pg_global  
  6. (2 rows)  
  7.   
  8. playboy=> select pg_size_pretty(pg_tablespace_size('pg_default'));   //查看表空间大小  
  9.  pg_size_pretty  
  10. ----------------  
  11.  14 MB  
  12. (1 row)  

10

转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/pgsql/1525.html

推荐 0
本文由 Yuchi608 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

0 个评论

要回复文章请先登录注册