微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

1,查看数据库
  1. playboy=>\l//\加上字母l,相当于MysqL的,MysqL>showdatabases;
  2. listofdatabases
  3. Name|Owner|Encoding
  4. -----------+----------+----------
  5. playboy|postgres|UTF8
  6. postgres|postgres|UTF8
  7. template0|postgres|UTF8
  8. template1|postgres|UTF8
  9. playboy=>selectpg_database_size('playboy');//查看playboy数据库的大小
  10. pg_database_size
  11. ------------------
  12. 3637896
  13. (1row)
  14. playboy=>selectpg_database.datname,pg_database_size(pg_database.datname)ASsizefrompg_database;//查看所有数据库的大小
  15. datname|size
  16. -----------+---------
  17. postgres|3621512
  18. playboy|3637896
  19. template1|3563524
  20. template0|3563524
  21. (4rows)
  22. playboy=>selectpg_size_pretty(pg_database_size('playboy'));//以KB,MB,GB的方式来查看数据库大小
  23. pg_size_pretty
  24. ----------------
  25. 3553kB
  26. (1row)

2,查看多表

  1. playboy=>\dt//相当于MysqL的,MysqL>showtables;
  2. listofrelations
  3. Schema|Name|Type|Owner
  4. --------+------+-------+---------
  5. public|test|table|playboy
  6. (1row)

3,查看单表

  1. playboy=>\dtest;//相当于MysqL的,MysqL>desctest;
  2. Table"public.test"
  3. Column|Type|Modifiers
  4. --------+-----------------------+-----------
  5. id|integer|notnull
  6. name|charactervarying(32)|
  7. Indexes:"playboy_id_pk"PRIMARYKEY,btree(id)
  8. playboy=>selectpg_relation_size('test');//查看表大小
  9. pg_relation_size
  10. ------------------
  11. 0
  12. (1row)
  13. playboy=>selectpg_size_pretty(pg_relation_size('test'));//以KB,MB,GB的方式来查看表大小
  14. pg_size_pretty
  15. ----------------
  16. 0bytes
  17. (1row)
  18. playboy=>selectpg_size_pretty(pg_total_relation_size('test'));//查看表的总大小,包括索引大小
  19. pg_size_pretty
  20. ----------------
  21. 8192bytes
  22. (1row)

4,查看索引

  1. playboy=>\di//相当于MysqL的,MysqL>showindexfromtest;
  2. listofrelations
  3. Schema|Name|Type|Owner|Table
  4. --------+---------------+-------+---------+-------
  5. public|playboy_id_pk|index|playboy|test
  6. (1row)
  7. playboy=>selectpg_size_pretty(pg_relation_size('playboy_id_pk'));//查看索大小
  8. pg_size_pretty
  9. ----------------
  10. 8192bytes
  11. (1row)

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐