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

来源:互联网 发布:上海圣剑网络怎么样 编辑:程序博客网 时间:2024/05/16 08:52

客户要求用pgsql,所在服务器装了一下pgsql,我出了一个pgsql的分类,看这篇文章前,把这个分类下的文章都可以看一下,这是我熟悉pgsql的一套流程。以前搞过一次pgsql,很早了。

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)  
0 0
原创粉丝点击