PostgreSQL查看表大小的命令
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查看表大小的命令的更多相关文章
- mysql查看表大小
mysql查看表大小 一:命令 show table status like 'table_name'\G; mysql> show table status like 'x'\G; . row ...
- Linux查看空间大小的命令
在linux中,常用查看空间大小的命令有df.du,下面依次介绍一下. df 命令是linux系统上以磁盘分区为单位来查看文件系统的命令,后面可以加上不同的参数来查看磁盘的剩余空间信息.Linux d ...
- MySQL 查看表结构简单命令
一.简单描述表结构,字段类型 desc tabl_name; 显示表结构,字段类型,主键,是否为空等属性,但不显示外键. 例如:desc table_name 二.查询表中列的注释信息 select ...
- MySQL 查看表结构简单命令。
一.简单描述表结构,字段类型 desc tabl_name; 显示表结构,字段类型,主键,是否为空等属性,但不显示外键. 二.查询表中列的注释信息 select * from information_ ...
- 161215、MySQL 查看表结构简单命令
一.简单描述表结构,字段类型desc tabl_name;显示表结构,字段类型,主键,是否为空等属性,但不显示外键.二.查询表中列的注释信息select * from information_sche ...
- SQL Server 2008系统信息查询常用命令 查看表大小、记录数等
1.返回所有数据库信息(数据库名,创建日期,存储路径等). use master; GO select * from dbo.sysdatabases 2.返回当前数据库所有对象(可根据type字 ...
- sql server查看表大小
查看SqlServer 数据库中各个表多少行 : SELECT A.NAME ,B.ROWS FROM sysobjects A JOIN sysindexes B ON A.id = B.id WH ...
- PostgreSQL查看表、表索引、视图、表结构
-- 表索引select * from pg_indexes where tablename='person_wechat_label';select * from pg_statio_all_ind ...
- Mysql 查看表结构的命令
创建数据库create database abc; 显示数据库 show databases; 使用数据库 use 数据库名; 直接打开数据库 mysql -h localhost -u root - ...
随机推荐
- 洛谷P1244 青蛙过河 DP/思路
又是一道奇奇怪怪的DP(其实是思路题). 原文戳>>https://www.luogu.org/problem/show?pid=1244<< 这题的意思给的挺模糊,需要一定的 ...
- ps/kill/pkill简单应用
ps http://www.cnblogs.com/wangkangluo1/archive/2011/09/23/2185938.html 参数: 1)ps a 显示现行终端机下的所有程序,包括其他 ...
- 【Mac】Finder显示或隐藏文件
第一步:打开「终端」应用程序. 第二步:输入如下命令: defaults write com.apple.finder AppleShowAllFiles -boolean true ; killal ...
- hdu 2034 改革春风吹满地 多边形面积
改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
- poj 1744 tree 树分治
Tree Time Limit: 1000MS Memory Limit: 30000K Description Give a tree with n vertices,each ed ...
- android:ems="10"是什么意思
android:ems = " 设置TextView或者Edittext的宽度为10个字符的宽度.当设置该属性后,控件显示的长度就为10个字符的长度,超出的部分将不显示. xml中 andr ...
- Django 国际化和本地化
所谓的国际化,是指使用不同语言的用户在访问同一个网站页面时能够看到符合其自身语言的文本页面. 国际化的基本原理是: 浏览器通过LANGUAGE_CODE在HTTP请求头中告诉网站后台服务器用户所需要的 ...
- Python 传递任意数量的实参
在定义函数的时候如果你不知道该函数在使用的时候要接收多少的实参怎么办? 好在python提供了可以接收任意数量的实参的操作. # def sandwitch(*ingredents): # print ...
- arcface和Dlib人脸识别算法对比
我司最近要做和人脸识别相关的产品,原来使用的是其他的在线平台,识别率和识别速度很满意,但是随着量起来的话,成本也是越来越不能接受(目前该功能我们是免费给用户使用的),而且一旦我们的设备掉线了就无法使用 ...
- python - selenium 2 升级到最新版本
python - selenium 2 升级到最新版本 之前一直用的是selenium 2.48 .firefox36 而实际用户的浏览器可能都有自动更新功能,所以版本基本上是最新的.所以这次专门做了 ...