Redshift中查看database、schema、table数据大小
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数据大小的更多相关文章
- PostgreSQL中,database,schema,table之间关系
从逻辑上看,schema,table,都是位于database之下. 首先,在postgres数据库下建立表(相当于建立在public schema下): [pgsql@localhost bin]$ ...
- SQL中查看数据库各表的大小
SQL中查看数据库各表的大小 编写人:CC阿爸 2014-6-17 在日常SQL数据库的操作中,如何快速的查询数据库中各表中数据的大小. 以下有两种方法供参考: 第一种: create table # ...
- [转]Centos系统中查看文件和文件夹大小
本文转自:https://blog.csdn.net/zgmu/article/details/52882868 当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择.df可以 ...
- Linux中查看文件或者文件夹大小
df -l 查看磁盘空间大小命令 df -hl 查看磁盘剩余空间 df -h 查看每个根路径的分区大小 du -sh 当前文件夹下所有文件大小(包括子文件大小 du -sm [文件夹] 返回该 ...
- cmd中查看MySQL数据库表数据及结构
0. 1 .cmd进入mysql安装的bin目录(C:\Program Files\XXXXXX\MySQL Server 5.6\bin) mysql -hlocalhost -uroot -p 回 ...
- Linux中查看文件夹占用磁盘大小
一.命令 ./ du -h ./ 查看当前目录占用空间 二.样例
- Instruments-查看收集到的数据
由于Xcode调试工具Instruments指南篇幅太长,所以本篇blog继续上篇,介绍对Instruments收集到的数据去分析. 关于数据分析 Instruments不解决你代码中的任何问题,它帮 ...
- SQL Server中模式(schema)、数据库(database)、表(table)、用户(user)之间的关系
数据库的初学者往往会对关系型数据库模式(schema).数据库(database).表(table).用户(user)之间感到迷惘,总感觉他们的关系千丝万缕,但又不知道他们的联系和区别在哪里,对一些问 ...
- mysql管理 ------查看 MySQL 数据库中每个表占用的空间大小
如果想知道MySQL数据库中每个表占用的空间.表记录的行数的话,可以打开MySQL的 information_schema 数据库.在该库中有一个 TABLES 表,这个表主要字段分别是: TABLE ...
随机推荐
- python爬虫训练——爬poj题目
首先要解决的就是不同的题目在不同的页上,也就是要实现翻页功能,自动获取所要爬取的地址,通过分析可以得出不同的页面也就是volume=后面的数字不同 所以我们可以用re模块来替换即可: new_url ...
- jenkins 异常
八月 03, 2017 7:23:54 下午 org.eclipse.jetty.util.log.JavaUtilLog warn 警告: FAILED ServerConnector@29e6eb ...
- jquery 封装页面之间获取值
最近在项目中发页面传值比较繁琐.View → Control → View,或是Session.Cookie 的 感觉不是很好,于是封装了一个页面间的js方法,上码 $.extend({ reque ...
- Money 20/20 | 未来金融数字化转型:数字化半径与全栈式战略观
小蚂蚁说: 近年来,国际和国内的领先银行纷纷全力投入数字化转型.IDC去年报告说,全球1000大企业里面,67%已经把数字化转型定为企业级战略,而决定数字化转型成功与否的是人的思想改变.我们用数字化半 ...
- BZOJ 2754 【SCOI2012】 喵星球上的点名
题目链接:喵星球上的点名 首先可以发现姓和名两个串就是逗你玩的.在两个串中间插入一个\(10001\),当成一个串做就可以了. 于是我们的问题转化为了: 有\(n\)个串\(A_1,A_2,\dots ...
- AFM(3)---Maude使用说明
load file-name 1可用绝对路径 2.可进入maude文件所在目录下load 3.默认工作空间是什么?
- 学习笔记13—python DataFrame获取行数、列数、索引及第几行第几列的值
1. df=DataFrame([{‘A’:’11’,’B’:’12’},{‘A’:’111’,’B’:’121’},{‘A’:’1111’,’B’:’1211’}]) print df.column ...
- ubuntu16.04 安装docker-ce,docker-compose
2018.11.14更新 参考https://blog.csdn.net/qq_38199832/article/details/77803645 sudo curl -sSL https://dow ...
- Spring AOP 理论
一.AOP AOP 产生的背景 “存在即合理”,任何一种理论或技术的产生,必然有它的原因.了解它产生的背景.为了解决的问题有助于我们更好地把握AOP的概念. 软件开发一直在寻求一种高效开发.护展.维护 ...
- 2019/01/17 基于windows使用fabric将gitlab的文件远程同步到服务器(git)
觉得django项目把本地更新push到gitlab,再执行fabric脚本从gitlab更新服务器项目挺方便的,当然从本地直接到服务器就比较灵活. 2019/01/17 基于windows使用fab ...