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

查看数据库

playboy=> \l                       //\加上字母l,相当于mysql的,mysql> show databases;  
        List of databases  
   Name    |  Owner   | Encoding  
-----------+----------+----------  
 playboy   | postgres | UTF8  
 postgres  | postgres | UTF8  
 template0 | postgres | UTF8  
 template1 | postgres | UTF8  

playboy=> select pg_database_size('playboy');    //查看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)  

playboy=> select pg_size_pretty(pg_database_size('playboy'));      //以KB,MB,GB的方式来查看数据库大小  
 pg_size_pretty  
----------------  
 3553 kB  
(1 row)

查看多表


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

查看单表

playboy=> \d test;                 //相当于mysql的,mysql> desc 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)  

playboy=> select pg_size_pretty(pg_relation_size('test'));   //以KB,MB,GB的方式来查看表大小  
 pg_size_pretty  
----------------  
 0 bytes  
(1 row)  

playboy=> select pg_size_pretty(pg_total_relation_size('test'));   //查看表的总大小,包括索引大小  
 pg_size_pretty  
----------------  
 8192 bytes  
(1 row)  

查看索引

playboy=> \di                      //相当于mysql的,mysql> show index from test;  
                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)  

查看表空间,以及大小

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值