SELECT
table_name,
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size
FROM (
SELECT
table_name,
pg_table_size(table_name) AS table_size,
pg_indexes_size(table_name) AS indexes_size,
pg_total_relation_size(table_name) AS total_size
FROM (
SELECT ('"' || table_schema || '"."' || table_name || '"') AS table_name
FROM information_schema.tables
) AS all_tables
ORDER BY total_size DESC
) AS pretty_sizes; table_name | table_size | indexes_size | total_size
-------------------------------------------------------------------------------+------------+--------------+------------
"emg_search_cn_20170614"."place_address" | 13 GB | 10 GB | 23 GB
"emg_search_cn_20170614"."place_attributes" | 6228 MB | 17 GB | 23 GB
"emg_search_cn_20170614"."place_name" | 5545 MB | 2614 MB | 8158 MB
"emg_search_cn_20170614"."place_raw_category" | 2132 MB | 4582 MB | 6715 MB
"emg_search_cn_20170614"."place_main" | 2668 MB | 1226 MB | 3895 MB
"emg_search_jjj_20161128"."place_attributes" | 422 MB | 3081 MB | 3503 MB
"emg_search_jjj_20161128"."place_address" | 869 MB | 1785 MB | 2654 MB
"emg_search_cn_20170614"."place_category" | 1010 MB | 1226 MB | 2237 MB
"emg_search_cn_20170614"."place_chain" | 656 MB | 945 MB | 1602 MB
"emg_search_jjj_20161129"."place_address" | 869 MB | 283 MB | 1152 MB
"emg_search_jjj_20161125"."place_address" | 787 MB | 256 MB | 1044 MB
"emg_search_jjj_20161128"."place_raw_category" | 145 MB | 810 MB | 955 MB
"emg_search_jjj_20161129"."place_attributes" | 422 MB | 521 MB | 943 MB
"emg_search_jjj_20161128"."place_name" | 405 MB | 473 MB | 878 MB
"emg_search_jjj_20161125"."place_attributes" | 385 MB | 475 MB | 861 MB
"emg_search_jjj_20161129"."place_name" | 405 MB | 76 MB | 480 MB
"emg_search_jjj_20161125"."place_name" | 369 MB | 69 MB | 439 MB
"emg_search_jjj_20161128"."place_main" | 186 MB | 223 MB | 409 MB
"emg_search_jjj_20161128"."place_category" | 70 MB | 223 MB | 293 MB
"emg_cn_170515"."emg_guangdongsheng_guangzhoushi_poi" | 267 MB | 14 MB | 281 MB
"emg_cn_170515"."emg_shanghaishi_poi1_poi" | 261 MB | 14 MB | 276 MB SELECT
table_name,
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size
FROM (
SELECT
table_name,
pg_table_size(table_name) AS table_size,
pg_indexes_size(table_name) AS indexes_size,
pg_total_relation_size(table_name) AS total_size
FROM (
-- tables from 'public'
SELECT table_name
FROM information_schema.tables
where table_schema = 'public' and table_type = 'BASE TABLE'
union
-- materialized views
SELECT oid::regclass::text as table_name
FROM pg_class
WHERE relkind = 'm'
order by table_name
) AS all_tables
-- ORDER BY total_size DESC
order by table_name
) AS pretty_sizes table_name | table_size | indexes_size | total_size
------------------------------------------------------+------------+--------------+------------
emg_search_cn_20170602.all_place_attributes_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_address_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_attributes_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_category_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_chain_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_embeded_ids | 0 bytes | 8192 bytes | 8192 bytes
emg_search_cn_20170602.place_full_view_static | 8192 bytes | 24 kB | 32 kB
emg_search_cn_20170602.place_name_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_phoneme_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_raw_category_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_relationship_child_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.place_relationship_parent_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170602.rich_attributes_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170614.all_place_attributes_mv | 3805 MB | 509 MB | 4314 MB
emg_search_cn_20170614.place_address_mv | 7960 MB | 509 MB | 8469 MB
emg_search_cn_20170614.place_attributes_mv | 1854 MB | 509 MB | 2363 MB
emg_search_cn_20170614.place_category_mv | 1005 MB | 509 MB | 1514 MB
emg_search_cn_20170614.place_chain_mv | 1253 MB | 276 MB | 1530 MB
emg_search_cn_20170614.place_embeded_ids | 827 MB | 0 bytes | 827 MB
emg_search_cn_20170614.place_full_view_static | 19 GB | 1537 MB | 21 GB
emg_search_cn_20170614.place_name_mv | 4179 MB | 509 MB | 4688 MB
emg_search_cn_20170614.place_phoneme_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_cn_20170614.place_raw_category_mv | 1494 MB | 509 MB | 2003 MB
emg_search_cn_20170614.place_relationship_child_mv | 30 MB | 6944 kB | 37 MB
emg_search_cn_20170614.place_relationship_parent_mv | 73 MB | 31 MB | 104 MB
emg_search_cn_20170614.rich_attributes_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_jjj_20161125.all_place_attributes_mv | 240 MB | 32 MB | 272 MB
emg_search_jjj_20161125.place_address_mv | 468 MB | 32 MB | 500 MB
emg_search_jjj_20161125.place_attributes_mv | 115 MB | 32 MB | 147 MB
emg_search_jjj_20161125.place_category_mv | 64 MB | 32 MB | 97 MB
emg_search_jjj_20161125.place_chain_mv | 8192 bytes | 8192 bytes | 16 kB
emg_search_jjj_20161125.place_embeded_ids | 52 MB | 32 MB | 85 MB
emg_search_jjj_20161125.place_full_view_static | 1145 MB | 97 MB | 1243 MB SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
, pg_total_relation_size(reltoastrelid) AS toast_bytes
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE relkind = 'r'
) a
) a; oid | table_schema | table_name | row_estimate | total_bytes | index_bytes | toast_bytes | table_bytes | total | index | toast | table
-------+-------------------------+-------------------------------------------------------------+--------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
2619 | pg_catalog | pg_statistic | 1444 | 25845760 | 532480 | 8650752 | 16662528 | 25 MB | 520 kB | 8448 kB | 16 MB
1247 | pg_catalog | pg_type | 2363 | 802816 | 286720 | | 516096 | 784 kB | 280 kB | | 504 kB
1260 | pg_catalog | pg_authid | 1 | 73728 | 32768 | | 40960 | 72 kB | 32 kB | | 40 kB
1249 | pg_catalog | pg_attribute | 37008 | 8650752 | 2490368 | | 6160384 | 8448 kB | 2432 kB | | 6016 kB
1255 | pg_catalog | pg_proc | 3327 | 1286144 | 393216 | 24576 | 868352 | 1256 kB | 384 kB | 24 kB | 848 kB
1418 | pg_catalog | pg_user_mapping | 0 | 16384 | 16384 | | 0 | 16 kB | 16 kB | | 0 bytes
2604 | pg_catalog | pg_attrdef | 478 | 425984 | 65536 | 8192 | 352256 | 416 kB | 64 kB | 8192 bytes | 344 kB
2606 | pg_catalog | pg_constraint | 352 | 270336 | 163840 | 8192 | 98304 | 264 kB | 160 kB | 8192 bytes | 96 kB
2610 | pg_catalog | pg_index | 1096 | 393216 | 114688 | | 278528 | 384 kB | 112 kB | | 272 kB
2617 | pg_catalog | pg_operator | 765 | 245760 | 81920 | | 163840 | 240 kB | 80 kB | | 160 kB
2753 | pg_catalog | pg_opfamily | 86 | 81920 | 32768 | | 49152 | 80 kB | 32 kB | | 48 kB
2616 | pg_catalog | pg_opclass | 128 | 90112 | 32768 | | 57344 | 88 kB | 32 kB | | 56 kB
2601 | pg_catalog | pg_am | 5 | 73728 | 32768 | | 40960 | 72 kB | 32 kB | | 40 kB
2602 | pg_catalog | pg_amop | 436 | 163840 | 98304 | | 65536 | 160 kB | 96 kB | | 64 kB
2603 | pg_catalog | pg_amproc | 344 | 106496 | 49152 | | 57344 | 104 kB | 48 kB | | 56 kB
2612 | pg_catalog | pg_language | 4 | 73728 | 32768 | | 40960 | 72 kB | 32 kB | | 40 kB
1262 | pg_catalog | pg_database | 2 | 40960 | 32768 | | 8192 | 40 kB | 32 kB | | 8192 bytes
2600 | pg_catalog | pg_aggregate | 133 | 65536 | 16384 | | 49152 | 64 kB | 16 kB | | 48 kB
2618 | pg_catalog | pg_rewrite | 142 | 925696 | 32768 | 671744 | 221184 | 904 kB | 32 kB | 656 kB | 216 kB
2620 | pg_catalog | pg_trigger | 0 | 32768 | 24576 | 8192 | 0 | 32 kB | 24 kB | 8192 bytes | 0 bytes
3466 | pg_catalog | pg_event_trigger | 0 | 16384 | 16384 | | 0 | 16 kB | 16 kB | | 0 bytes
2609 | pg_catalog | pg_description | 3686 | 442368 | 139264 | 8192 | 294912 | 432 kB | 136 kB | 8192 bytes | 288 kB
2605 | pg_catalog | pg_cast | 198 | 81920 | 32768 | | 49152 | 80 kB | 32 kB | | 48 kB
3501 | pg_catalog | pg_enum | 0 | 24576 | 24576 | | 0 | 24 kB | 24 kB | | 0 bytes
2615 | pg_catalog | pg_namespace | 6 | 73728 | 32768 | | 40960 | 72 kB | 32 kB | | 40 kB
2607 | pg_catalog | pg_conversion | 132 | 106496 | 49152 | | 57344 | 104 kB | 48 kB | | 56 kB
2608 | pg_catalog | pg_depend | 15060 | 2998272 | 1933312 | | 1064960 | 2928 kB | 1888 kB | | 1040 kB
2964 | pg_catalog | pg_db_role_setting | 0 | 32768 | 16384 | 8192 | 8192 | 32 kB | 16 kB | 8192 bytes | 8192 bytes
1213 | pg_catalog | pg_tablespace | 2 | 73728 | 32768 | | 40960 | 72 kB | 32 kB | | 40 kB
1136 | pg_catalog | pg_pltemplate | 8 | 57344 | 16384 | | 40960 | 56 kB | 16 kB | | 40 kB
1261 | pg_catalog | pg_auth_members | 0 | 16384 | 16384 | | 0 | 16 kB | 16 kB | | 0 bytes
1214 | pg_catalog | pg_shdepend | 784 | 204800 | 98304 | | 106496 | 200 kB | 96 kB | | 104 kB
2396 | pg_catalog | pg_shdescription | 1 | 65536 | 16384 | 8192 | 40960 | 64 kB | 16 kB | 8192 bytes | 40 kB
3602 | pg_catalog | pg_ts_config | 16 | 73728 | 32768 | | 40960 | 72 kB | 32 kB | | 40 kB
3603 | pg_catalog | pg_ts_config_map | 304 | 81920 | 32768 | | 49152 | 80 kB | 32 kB | | 48 kB SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 20; relation | total_size
------------------------------------------------+------------
emg_search_cn_20170614.place_address | 23 GB
emg_search_cn_20170614.place_attributes | 23 GB
emg_search_cn_20170614.place_full_view_static | 21 GB
emg_search_cn_20170614.place_address_mv | 8469 MB
emg_search_cn_20170614.place_name | 8158 MB
emg_search_cn_20170614.place_raw_category | 6715 MB
emg_search_cn_20170614.place_name_mv | 4688 MB
emg_search_cn_20170614.all_place_attributes_mv | 4314 MB
emg_search_cn_20170614.place_main | 3895 MB
emg_search_jjj_20161128.place_attributes | 3503 MB
emg_search_jjj_20161128.place_address | 2654 MB
emg_search_cn_20170614.place_attributes_mv | 2363 MB
emg_search_cn_20170614.place_category | 2237 MB
emg_search_cn_20170614.place_raw_category_mv | 2003 MB
emg_search_cn_20170614.place_chain | 1602 MB
emg_search_jjj_20161128.place_full_view_static | 1600 MB
emg_search_cn_20170614.place_chain_mv | 1530 MB
emg_search_cn_20170614.place_category_mv | 1514 MB
emg_search_jjj_20161129.place_full_view_static | 1369 MB
emg_search_jjj_20161125.place_full_view_static | 1243 MB
(20 rows) SELECT
table_schema || '.' || table_name AS TableName,
pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS TableSize
FROM information_schema.tables
ORDER BY
pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC; tablename | tablesize
---------------------------------------------------------------------------+------------
emg_search_cn_20170614.place_address | 23 GB
emg_search_cn_20170614.place_attributes | 23 GB
emg_search_cn_20170614.place_name | 8158 MB
emg_search_cn_20170614.place_raw_category | 6715 MB
emg_search_cn_20170614.place_main | 3895 MB
emg_search_jjj_20161128.place_attributes | 3503 MB
emg_search_jjj_20161128.place_address | 2654 MB
emg_search_cn_20170614.place_category | 2237 MB
emg_search_cn_20170614.place_chain | 1602 MB
emg_search_jjj_20161129.place_address | 1152 MB
emg_search_jjj_20161125.place_address | 1044 MB
emg_search_jjj_20161128.place_raw_category | 955 MB
emg_search_jjj_20161129.place_attributes | 943 MB
emg_search_jjj_20161128.place_name | 878 MB
emg_search_jjj_20161125.place_attributes | 861 MB
emg_search_jjj_20161129.place_name | 480 MB
emg_search_jjj_20161125.place_name | 439 MB
emg_search_jjj_20161128.place_main | 409 MB
emg_search_jjj_20161128.place_category | 293 MB
emg_cn_170515.emg_guangdongsheng_guangzhoushi_poi | 281 MB
emg_cn_170515.emg_shanghaishi_poi1_poi | 276 MB
emg_search_jjj_20161129.place_raw_category | 275 MB
emg_cn_170515.emg_guangdongsheng_shenzhenshi_poi | 249 MB

查看当前库表和物化视图总大小

SELECT
inet_server_addr() AS instance_address,
table_catalog AS database_name,
table_schema AS schema_name,
table_name,
pg_table_size(table_full_name) AS table_size,
pg_indexes_size(table_full_name) AS index_size,
pg_total_relation_size(table_full_name) AS total_size,
table_type
FROM ( SELECT
('"' || table_schema || '"."' || table_name || '"') AS table_full_name,
table_catalog,
table_schema,
table_name,
table_type
FROM information_schema.tables
WHERE table_schema NOT IN ('pg_catalog','information_schema','topology','tiger','tiger_data') and table_type='BASE TABLE'
UNION ALL
SELECT
('"' || schemaname || '"."' || matviewname || '"') AS table_full_name,
current_database() AS table_catalog,
schemaname AS table_schema,
matviewname AS table_name,
'MATERIALIZED VIEW' as table_type
FROM pg_matviews
) AS all_tables
ORDER BY total_size DESC;

PostgreSQL查看表大小的命令的更多相关文章

  1. mysql查看表大小

    mysql查看表大小 一:命令 show table status like 'table_name'\G; mysql> show table status like 'x'\G; . row ...

  2. Linux查看空间大小的命令

    在linux中,常用查看空间大小的命令有df.du,下面依次介绍一下. df 命令是linux系统上以磁盘分区为单位来查看文件系统的命令,后面可以加上不同的参数来查看磁盘的剩余空间信息.Linux d ...

  3. MySQL 查看表结构简单命令

    一.简单描述表结构,字段类型 desc tabl_name; 显示表结构,字段类型,主键,是否为空等属性,但不显示外键. 例如:desc table_name 二.查询表中列的注释信息 select ...

  4. MySQL 查看表结构简单命令。

    一.简单描述表结构,字段类型 desc tabl_name; 显示表结构,字段类型,主键,是否为空等属性,但不显示外键. 二.查询表中列的注释信息 select * from information_ ...

  5. 161215、MySQL 查看表结构简单命令

    一.简单描述表结构,字段类型desc tabl_name;显示表结构,字段类型,主键,是否为空等属性,但不显示外键.二.查询表中列的注释信息select * from information_sche ...

  6. SQL Server 2008系统信息查询常用命令 查看表大小、记录数等

    1.返回所有数据库信息(数据库名,创建日期,存储路径等).   use master; GO select * from dbo.sysdatabases 2.返回当前数据库所有对象(可根据type字 ...

  7. sql server查看表大小

    查看SqlServer 数据库中各个表多少行 : SELECT A.NAME ,B.ROWS FROM sysobjects A JOIN sysindexes B ON A.id = B.id WH ...

  8. PostgreSQL查看表、表索引、视图、表结构

    -- 表索引select * from pg_indexes where tablename='person_wechat_label';select * from pg_statio_all_ind ...

  9. Mysql 查看表结构的命令

    创建数据库create database abc; 显示数据库 show databases; 使用数据库 use 数据库名; 直接打开数据库 mysql -h localhost -u root - ...

随机推荐

  1. jquery及jquery常用选择器使用

    本文为博主原创,未经允许不得转载: 1.jquery强大之处:   容易上手,强大的选择器,解决浏览器的兼容   完善的时间机制,出色的ajax封装,丰富的ui    2.jquery是一个javas ...

  2. Tomcat下webapps夹中root文件夹作用及如何发布项目至root文件夹中

    转载请注明出处: tomcat的root文件夹下面默认是tomcat的管理程序,但是如果你把自己的web项目发布到root下面的话,你可以不通过项目名直接访问你的项目,比如,你见了一个名为Test的项 ...

  3. Bootstrap 3 媒体查询

    可以参考 Bootstrap  的媒体查询,写网站. html: <div class="bootstrap-3-media"> <p>Mobile-Fir ...

  4. 用maven和spring搭建ActiveMQ环境

    前面搭建过了简单的环境,这次用稍微实际一点的maven+spring+activemq来进行搭建 准备:win7,eclipse,jdk1.8,tomcat8,maven3.5.2,activemq5 ...

  5. 【AT1219】历史研究

    Problem Description \(IOI\)国历史研究的第一人--\(JOI\)教授,最近获得了一份被认为是古代\(IOI\)国的住民写下的日记.\(JOI\)教授为了通过这份日记来研究古代 ...

  6. 后台返回数据判断是http还是后台本地图片 indexOf

    今天的笔记呢,记录一下 其实这个应该后台去判断的,但是因为某种原因,今天我们前台做一下判断 事情是这样的,后台返回我一个url  这个url有的http开头的 也有他后台本地的例如:/img/1.pn ...

  7. 【UOJ】#273. 【清华集训2016】你的生命已如风中残烛

    题目链接:http://uoj.ac/problem/273 $${Ans=\frac{\prod _{i=1}^{m}i}{w-n+1}}$$ #include<iostream> #i ...

  8. 封装微信小程序支付

    <?php /** * User: Eden * Date: 2019/3/21 * 共有内容 */ namespace Common\Service; use Think\Exception; ...

  9. typeScript入门基础 (2): 数据 类型, 函数定义

    1.   number , boolean, string, null, undefind  枚举, any, array数组, 元祖, 2...枚举,需要的注意点,  下一个图,就是为什么yello ...

  10. Android drag drop

    最近偶尔知道了锤子的one step,所以在网上看相关的东西,有人说android原生drag drop就能实现,我就去学习一下这个drag drop,下面把学习到的东西总结一下: drag drop ...