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 - ...
随机推荐
- Docker:Containers
Prerequisites Install Docker version 1.13 or higher. Read the orientation in Part 1. Give your envir ...
- ps/kill/pkill简单应用
ps http://www.cnblogs.com/wangkangluo1/archive/2011/09/23/2185938.html 参数: 1)ps a 显示现行终端机下的所有程序,包括其他 ...
- 【搬运工】——Java中的static关键字解析(转)
原文链接:http://www.cnblogs.com/dolphin0520/p/3799052.html static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大 ...
- SSH KEY 设置 目录在open ~ 根目录下的.ssh 里面
当我们从github或者gitlab上clone项目或者参与项目时,需要证明我们的身份.github.gitlab支持使用SSH协议进行免密登录,而SSH协议采用了RSA算法保证了登录的安全性.我们要 ...
- Redis 个人理解总结
一.什么是Redis ? Redis(remote dictionnary server)是一个key-value存储系统.Redis是一个开源的使用ANSI C语言编写.遵守BSD协议.支持网络.可 ...
- 浅谈Linux文件系统
Linux 与其他类 UNIX 系统一样并不区分文件与目录:目录是记录了其他文件名的文件.使用命令 mkdir 创建目录时,若期望创建的目录的名称与现有的文件名(或目录名)重复,则会创建失败. Lin ...
- mysql基本知识总结
第一天 create database act_web character set utf8; : 创建数据库并设立编码(命令中是不允许使用“-”的) '; :创建用户并设立密码 grant all ...
- .NetCore Session.Redis
首先创建ASP.NET CORE Web项目,然后按如下顺序操作.1.添加nuget程序包: Microsoft.AspNetCore.Session; Microsoft.AspNetCore.Da ...
- [osg]osg窗口显示和单屏幕显示
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osg"); osg::ref_ptr&l ...
- 《剑指offer》第四十三题(从1到n整数中1出现的次数)
// 面试题43:从1到n整数中1出现的次数 // 题目:输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数.例如 // 输入12,从1到12这些整数中包含1 的数字有1,10,11和12 ...