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. ElasticSearch——日志工具

    Elasticsearch: 权威指南 官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.ht ...

  2. 常用模块(json/pickle/shelve/XML)

    一.json模块(重点) 一种跨平台的数据格式 也属于序列化的一种方式 介绍模块之前,三个问题: 序列化是什么? 我们把对象(变量)从内存中变成可存储或传输的过程称之为序列化. 反序列化又是什么? 将 ...

  3. _lottery

    通过积分购买彩票,奖励以积分形式发放 当aaa_chance,max_chance,min_chance均为0时,自动计算系统最小积分开销进行开奖

  4. JAVA中使用浮点数类型计算时,计算精度的问题

    标题     在Java中实现浮点数的精确计算    AYellow(原作) 修改    关键字     Java 浮点数 精确计算   问题的提出:如果我们编译运行下面这个程序会看到什么?publi ...

  5. django 应用中获取访问者ip地址

    通常访问者的IP就在其中,所以我们可以用下列方法获取用户的真实IP: #X-Forwarded-For:简称XFF头,它代表客户端,也就是HTTP的请求端真实的IP,只有在通过了HTTP 代理或者负载 ...

  6. Centos7:查看某个端口被哪个进程占用

    查看端口被哪个进程使用的命令 netstat -lnp | grep 参考: https://blog.csdn.net/u010886217/article/details/83626236 htt ...

  7. 使用pymongo连接mongodb时报错:pymongo.errors.OperationFailure: not authorized

    连接本机或局域网部署的mongodb时可以用以下方法: from urllib import parse from pymongo import MongoClient host = '*.*.*.* ...

  8. C++.可变参数_ZC测试

    ZC:环境: Win7 x64(旗舰版),Microsoft Visual Studio 2010(版本 10.0.30319.1 RTMRel, Microsoft .NET Framework(版 ...

  9. 学习笔记44—Linux下安装freesurfer

    第一步:安装ubuntu (略过) 第二步:下载freesurfer:从freesurfer的官方网站上下载:http://surfer.nmr.mgh.harvard.edu/fswiki/Down ...

  10. cocos2dx spine之二 :spine变色

    cocos2dx版本为3.10 1.具体原理和代码可以参考博文<利用shader改变图片色相Hue>,下面的代码根据该博文进行整理优化. 基本原理就是将RGB值转换为HSL值后加上输入的H ...