您的位置 首页 golang

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

概述

今天主要分享一下 postgresql 怎么去查看数据库,表, 索引 表空间 以及大小,适合平时PG运维的朋友。


1、查看数据库

postgres=# \l --查看所有数据库
postgres=# select pg_database_size('hwb'); --查看单个数据库的大小
postgres=# select pg_database.datname, pg_database_size(pg_database.datname) AS size from pg_database; --查看所有数据库的大小
postgres=# select pg_size_pretty(pg_database_size('hwb')); --以KB,MB,GB的方式来查看数据库大小
 


2、查看表

postgres=# \d --查看当前数据库下所有表
postgres=# \d test --查看test表定义
postgres=# select pg_relation_size('test'); --查看test表大小
postgres=# select pg_size_pretty(pg_relation_size('test')); --以KB,MB,GB的方式来查看表大小
postgres=# select pg_size_pretty(pg_total_relation_size('test')); --查看表的总大小,包括索引大小
 


3、查看索引

postgres=# \di --查看当前数据库所有索引
postgres=# select pg_size_pretty(pg_relation_size('parent_pkey')); --查看单个索引大小
 

4、查看表空间,以及大小

postgres=# select spcname from pg_tablespace; --查看所有表空间
postgres=# select pg_size_pretty(pg_tablespace_size('pg_default')); --查看表空间大小
 


后面会分享更多devops和 DBA 方面的内容,感兴趣的朋友可以关注一下~

文章来源:智云一二三科技

文章标题:如何用postgresql查看数据库,表,索引,表空间以及大小

文章地址:https://www.zhihuclub.com/98787.shtml

关于作者: 智云科技

热门文章

评论已关闭

5条评论

  1. Hey there would you mind letting me know which hosting company
    you’re utilizing? I’ve loaded your blog in 3 completely different
    internet browsers and I must say this blog loads
    a lot faster then most. Can you suggest a good web hosting provider at a fair price?

    Thank you, I appreciate it!

    Here is my homepage –

  2. Thanks for sharing your thoughts about 세종porn섹스가능한1인샵.
    Regards

  3. It’s an amazing paragraph in support of all the web visitors;
    they will get advantage from it I am sure.

  4. I am sure this paragraph has touched all the internet visitors, its really really nice paragraph on building up new blog.

  5. That means you’ll see some new features and from access to additional channels where you can win visibility, without having to modify mother wit of some ornate, guide migration process.

网站地图