postgresql 查看數據庫,表,索引,表空間以及大小
1,查看數據庫html
查看複製打印?mysql
- 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)
2,查看多表sql
查看複製打印?數據庫
- playboy=> \dt //至關於mysql的,mysql> show tables;
- List of relations
- Schema | Name | Type | Owner
- --------+------+-------+---------
- public | test | table | playboy
- (1 row)
3,查看單表post
查看複製打印?spa
- 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)
4,查看索引htm
查看複製打印?blog
- 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)
5,查看錶空間,以及大小索引
查看複製打印?ip
- 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)
23
歡迎關注本站公眾號,獲取更多信息