1. 查看当前数据库大小以及记录行数

select
trim(pgdb.datname) as database, sum(b.mbytes) as mbytes, sum(a.rows) as rows
from
(select db_id, id, name, sum(rows) as rows from stv_tbl_perm a group by db_id, id, name) as a
join pg_class as pgc on pgc.oid = a.id
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (select tbl, count(*) as mbytes from stv_blocklist group by tbl) b on a.id=b.tbl
group by pgdb.datname
order by 1; database | mbytes | rows
-----------+---------+------------
analytics | 1074998 | 5030398009
(1 row)

2. 查看当前数据库各schema大小以及每个schema下的记录行数

select
trim(pgdb.datname) as database, trim(pgn.nspname) as schema,
sum(b.mbytes) as mbytes, sum(a.rows) as rows
from
(select db_id, id, name, sum(rows) as rows from stv_tbl_perm a group by db_id, id, name) as a
join pg_class as pgc on pgc.oid = a.id
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (select tbl, count(*) as mbytes from stv_blocklist group by tbl) b on a.id=b.tbl
group by pgdb.datname, pgn.nspname
order by 1, 2; database | schema | mbytes | rows
-----------+-------------+--------+------------
analytics | datascience | 168 | 196128
analytics | dba | 15852 | 43752350
analytics | dimensions | 28223 | 225275059
analytics | facts | 265457 | 1382762113
analytics | public | 50235 | 104688442
analytics | search_data | 696799 | 3235794562
analytics | staging | 18264 | 37929355
(7 rows)

3. 查看当前数据库下每张表的大小

方法一

SELECT   TRIM(pgdb.datname) AS Database,
TRIM(a.name) AS Table,
((b.mbytes/part.total::decimal)*100)::decimal(5,2) AS pct_of_total,
b.mbytes,
b.unsorted_mbytes
FROM stv_tbl_perm a
JOIN pg_database AS pgdb
ON pgdb.oid = a.db_id
JOIN ( SELECT tbl,
SUM( DECODE(unsorted, 1, 1, 0)) AS unsorted_mbytes,
COUNT(*) AS mbytes
FROM stv_blocklist
GROUP BY tbl ) AS b
ON a.id = b.tbl
JOIN ( SELECT SUM(capacity) AS total
FROM stv_partitions
WHERE part_begin = 0 ) AS part
ON 1 = 1
WHERE a.slice = 0
ORDER BY 4 desc, db_id, name; database | table | pct_of_total | mbytes | unsorted_mbytes
-----------+-----------------------------------------------+--------------+--------+-----------------
analytics | es_entitysvc_response_logshed | 39.42 | 450948 | 449820
analytics | es_entitysvc_logshed | 18.06 | 206630 | 206054
analytics | auto_events | 9.99 | 114379 | 113395
analytics | auto_events_realtime | 4.11 | 47029 | 47020
analytics | auto_events_rt | 2.20 | 25251 | 25242
analytics | entity | 1.87 | 21485 | 16553
analytics | unified_events_dev | 1.27 | 14604 | 14592
analytics | logshedevents_processed | 0.65 | 7504 | 7504
analytics | client_events_stg | 0.60 | 6912 | 6912
analytics | search_autocomplete_response_processed | 0.58 | 6672 | 6660
analytics | entity_gen3 | 0.51 | 5940 | 5796
analytics | staging_auto_events_stg | 0.47 | 5436 | 5436
analytics | es_denaliusage_logshed | 0.45 | 5224 | 5212
analytics | scout4cars_events | 0.38 | 4430 | 4430
analytics | search_autocomplete_request_processed | 0.35 | 4080 | 4068
analytics | osm_metrics | 0.32 | 3718 | 3708
analytics | gm_auto_events | 0.32 | 3715 | 1970
analytics | client_events_raj | 0.32 | 3707 | 1584
analytics | scout_events_tmp | 0.29 | 3384 | 1716
analytics | client_events_sessionmap_stg_loadtest | 0.28 | 3288 | 3288
analytics | unified_events_for_scout_dev | 0.27 | 3192 | 3180
analytics | client_events_vlad | 0.27 | 3144 | 1572
analytics | client_events_backup_till_1010 | 0.27 | 3120 | 1584
(25 rows)

方法二

select
trim(pgdb.datname) as database, trim(pgn.nspname) as schema,
trim(a.name) as Table, b.mbytes, a.rows
from
(select db_id, id, name, sum(rows) as rows from stv_tbl_perm a group by db_id, id, name) as a
join pg_class as pgc on pgc.oid = a.id
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (select tbl, count(*) as mbytes from stv_blocklist group by tbl) b on a.id=b.tbl
order by 1, 2, 4 desc; database | schema | table | mbytes | rows
-----------+-------------+-----------------------------------------------+--------+------------
analytics | datascience | clusterwithstartstop | 168 | 196128
analytics | dba | staging_auto_events_stg | 5436 | 42524253
analytics | dba | client_events | 1680 | 8623
analytics | dba | client_events_hive | 1680 | 2742
analytics | dba | client_events_stg | 1656 | 3690
analytics | dba | client_events_stg_hive | 1548 | 2537
analytics | dba | facts_auto_events | 1452 | 1053537
analytics | dba | auto_events | 1200 | 79584
analytics | dba | facts_auto_events_hive | 1200 | 77384
analytics | dimensions | entity | 21485 | 178665073
analytics | dimensions | entity_gen3 | 5940 | 46499810
analytics | dimensions | date | 216 | 39444
analytics | dimensions | location | 192 | 65921
analytics | dimensions | product | 132 | 2292
analytics | dimensions | carrier | 96 | 1128
analytics | dimensions | application_info | 90 | 1248
analytics | dimensions | event_type_classification | 72 | 143
analytics | facts | auto_events | 114379 | 893071197
analytics | facts | auto_events_realtime | 47029 | 78054568
(21 rows)

方法三

select
cast(use2.usename as varchar(50)) as owner,
pgc.oid,
trim(pgdb.datname) as Database,
trim(pgn.nspname) as Schema,
trim(a.name) as Table,
b.mbytes,
a.rows
from
(select db_id, id, name, sum(rows) as rows
from stv_tbl_perm a
group by db_id, id, name
) as a
join pg_class as pgc on pgc.oid = a.id
left join pg_user use2 on (pgc.relowner = use2.usesysid)
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
and pgn.nspowner > 1
join pg_database as pgdb on pgdb.oid = a.db_id
join
(select tbl, count(*) as mbytes
from stv_blocklist
group by tbl
) b on a.id = b.tbl
order by mbytes desc, a.db_id, a.name; owner | oid | database | schema | table | mbytes | rows
------------------------+---------+-----------+-------------+-----------------------------------------------+--------+------------
search_data_writer | 780702 | analytics | search_data | es_entitysvc_response_logshed | 450948 | 1983660186
search_data_writer | 780704 | analytics | search_data | es_entitysvc_logshed | 206630 | 870298752
tnadmin | 868711 | analytics | facts | auto_events | 114379 | 893071197
client_events_etl_user | 680119 | analytics | facts | auto_events_realtime | 47029 | 78054568
tnadmin | 868715 | analytics | facts | auto_events_rt | 25251 | 184784513
sheena | 119412 | analytics | dimensions | entity | 21485 | 178665073
client_events_etl_user | 1080972 | analytics | facts | unified_events_dev | 14604 | 104578129
search_data_writer | 225115 | analytics | search_data | logshedevents_processed | 7504 | 112599927
tnadmin | 148013 | analytics | staging | client_events_stg | 6912 | 9145782
search_data_writer | 218921 | analytics | search_data | search_autocomplete_response_processed | 6672 | 116412380
tnadmin | 950671 | analytics | dimensions | entity_gen3 | 5940 | 46499810
tnadmin | 252547 | analytics | dba | staging_auto_events_stg | 5436 | 42524253
search_data_writer | 958865 | analytics | search_data | es_denaliusage_logshed | 5224 | 11127230
tnadmin | 754088 | analytics | facts | scout4cars_events | 4430 | 17981548
search_data_writer | 218919 | analytics | search_data | search_autocomplete_request_processed | 4080 | 42130637
matthieu | 157597 | analytics | facts | osm_metrics | 3718 | 33749875
tnadmin | 689962 | analytics | facts | gm_auto_events | 3715 | 12066340
tnadmin | 158221 | analytics | facts | client_events_raj | 3707 | 1362676
krishna | 138765 | analytics | staging | client_events_sessionmap_stg_loadtest | 3288 | 18799978
client_events_etl_user | 1070400 | analytics | facts | unified_events_for_scout_dev | 3192 | 2961636
tnadmin | 128436 | analytics | facts | client_events_backup_till_1010 | 3120 | 7046
tnadmin | 147602 | analytics | facts | client_events_logshed_temp | 3120 | 44265
(24 rows)

Redshift中查看database、schema、table数据大小的更多相关文章

  1. PostgreSQL中,database,schema,table之间关系

    从逻辑上看,schema,table,都是位于database之下. 首先,在postgres数据库下建立表(相当于建立在public schema下): [pgsql@localhost bin]$ ...

  2. SQL中查看数据库各表的大小

    SQL中查看数据库各表的大小 编写人:CC阿爸 2014-6-17 在日常SQL数据库的操作中,如何快速的查询数据库中各表中数据的大小. 以下有两种方法供参考: 第一种: create table # ...

  3. [转]Centos系统中查看文件和文件夹大小

    本文转自:https://blog.csdn.net/zgmu/article/details/52882868 当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择.df可以 ...

  4. Linux中查看文件或者文件夹大小

    df -l 查看磁盘空间大小命令 df -hl  查看磁盘剩余空间 df -h  查看每个根路径的分区大小 du -sh  当前文件夹下所有文件大小(包括子文件大小 du -sm  [文件夹] 返回该 ...

  5. cmd中查看MySQL数据库表数据及结构

    0. 1 .cmd进入mysql安装的bin目录(C:\Program Files\XXXXXX\MySQL Server 5.6\bin) mysql -hlocalhost -uroot -p 回 ...

  6. Linux中查看文件夹占用磁盘大小

    一.命令 ./ du -h ./ 查看当前目录占用空间 二.样例

  7. Instruments-查看收集到的数据

    由于Xcode调试工具Instruments指南篇幅太长,所以本篇blog继续上篇,介绍对Instruments收集到的数据去分析. 关于数据分析 Instruments不解决你代码中的任何问题,它帮 ...

  8. SQL Server中模式(schema)、数据库(database)、表(table)、用户(user)之间的关系

    数据库的初学者往往会对关系型数据库模式(schema).数据库(database).表(table).用户(user)之间感到迷惘,总感觉他们的关系千丝万缕,但又不知道他们的联系和区别在哪里,对一些问 ...

  9. mysql管理 ------查看 MySQL 数据库中每个表占用的空间大小

    如果想知道MySQL数据库中每个表占用的空间.表记录的行数的话,可以打开MySQL的 information_schema 数据库.在该库中有一个 TABLES 表,这个表主要字段分别是: TABLE ...

随机推荐

  1. mysql表分区存储过程

    本文为博主原创,未经允许不得转载: 由于数据库一张表数据量有几千万条,而且在不断增长,看见公司前辈写了一个创建表分区的存储过程,感觉 甚是牛逼,在此供自己保留学习. /*PROCEDURE creat ...

  2. HDU 4496 D-City(逆向并查集)

    http://acm.hdu.edu.cn/showproblem.php?pid=4496 题意: 给出n个顶点m条边的图,每次选择一条边删去,求每次删边后的连通块个数. 思路: 离线处理删边,从后 ...

  3. IIS7.5 错误代码0x8007007e HTTP 错误 500.19 - Internal Server Error

    今天在win2008+IIS7.5的环境中部署WCF服务后,一直出现无法打开的页面.具体错误信息如下: HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面 ...

  4. React Native组件之BackAndroid !安卓手机的物理返回键的使用

    ok!在安卓手机上,当我们用物理返回键的时候,会以一次性的将程序退出来,这样是很不好的体验,所以就需要使用RN的物理返回键组件:BackAndroid,其原理也就是 分析路由,然后pop()这样! o ...

  5. Git 基础 - 打标签

    列出现有标签(或者使用git tag -l) $ git tag v0. v1. 如果只对 1.4.2 系列的版本感兴趣 $ git tag -l 'v1.4.2.*' v1. v1. v1. v1. ...

  6. 力扣(LeetCode)976. 三角形的最大周长

    给定由一些正数(代表长度)组成的数组 A,返回由其中三个长度组成的.面积不为零的三角形的最大周长. 如果不能形成任何面积不为零的三角形,返回 0. 示例 1: 输入:[2,1,2] 输出:5 示例 2 ...

  7. [C#][Windows]]基于ArcFace2.0+红外双目摄像头的活体检测

    废话不多说 直接上图 这个是demo中用到的双目摄像头,一个是红外的,一个是正常的rgb摄像头两个usb接口,在电脑上呈现两路摄像头通道程序检测RGB输出图像,当检测到有人脸时,用RGB人脸的位置到红 ...

  8. MarkerOpter marker操作类

    构造函数:MarkerOpter=function(p_params): p_params={} 参数描述: p_params.layer; // markerlayer p_params.imgUr ...

  9. 虚拟机镜像压缩(qcow2,raw)

    ●qcow2 格式的压缩首先,需要对虚拟机系统的剩余空间写零操作: $ dd if=/dev/zero of=/zero.dat 删除 zero.dat$ rm /zero.dat关闭虚拟机,进入虚拟 ...

  10. 雷林鹏分享:XML DOM

    XML DOM DOM(Document Object Model 文档对象模型)定义了访问和操作文档的标准方法. XML DOM XML DOM(XML Document Object Model) ...