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

,查看数据库

  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)  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值