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)

原文地址:https://www.cnblogs.com/ilifeilong/p/9190111.html

时间: 2024-10-30 12:49:05

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

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

SQL中查看数据库各表的大小 编写人:CC阿爸 2014-6-17 在日常SQL数据库的操作中,如何快速的查询数据库中各表中数据的大小. 以下有两种方法供参考: 第一种: create table #t(name varchar(255), rows bigint, reserved varchar(20), data varchar(20), index_size varchar(20), unused varchar(20)) exec sp_MSforeachtable "insert i

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

本文转自:https://blog.csdn.net/zgmu/article/details/52882868 当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择.df可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力.du可以查看文件及文件夹的大小.两者配合使用,非常有效.比如用df查看哪个一级目录过大,然后用df查看文件夹或文件的大小,如此便可迅速确定症结. 下面分别简要介绍 df命令可以显示目前所有文件系统的可用空间及使用情形,请看下列这个

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

df -l 查看磁盘空间大小命令 df -hl  查看磁盘剩余空间 df -h  查看每个根路径的分区大小 du -sh  当前文件夹下所有文件大小(包括子文件大小 du -sm  [文件夹] 返回该文件夹总M数 du -h ftp 查看指定文件夹下所有文件大小(包括子文件夹) du -h ./package/compat-libstdc++-33-3.2.3-69.el6.x86_64.rpm 查看指定文件大小

用命令查看Mysql中数据库、表的空间大小

要想知道每个数据库的大小的话,步骤如下: 1.进入information_schema 数据库(存放了其他的数据库的信息) use information_schema; 2.查询所有数据的大小: select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables; 3.查看指定数据库的大小: 比如查看数据库home的大小 select concat(round(sum(data_length/1024/1024

Android 开发之开发插件使用:Eclipse 插件 SQLiteManger eclipse中查看数据内容--翻译

最近研究了一段时间Android开发后发现,google自带的ADT工具,缺失一些开发常用的东西,希望可以构建一个类似使用JAVA EE开发体系一样开发的工具包集合,包括前台开发,调试,到后台数据库的管理,到此,在网上逛了一遍发现这个一些常用的插件功能很强大,所以我决定做一系列翻译这些插件安装使用的教程,希望大家喜欢. 本文受益于这篇文章,所以决定翻译这篇文章中的一部分东西工具.19 个 Android 开发工具投递人 itwriter 发布于 2014-05-08 09:32 本文翻译:Ecl

zbb20170816 oracle Oracle 查看表空间、数据文件的大小及使用情况sql语句

oracle Oracle 查看表空间.数据文件的大小及使用情况sql语句 --表空间 --1G=1024MB --1M=1024KB --1K=1024Bytes --1M=11048576Bytes --1G=1024*11048576Bytes=11313741824Bytes SELECT a.tablespace_name "表空间名", total "表空间大小", free "表空间剩余大小", (total - free) &qu

如何查看Oracle数据库表空间大小(空闲、已使用),是否要增加表空间的数据文件

要查看Oracle数据库表空间大小,是否需要增加表空间的数据文件,在数据库管理中,磁盘空间不足是DBA都会遇到的问题,问题比较常见. --1.查看表空间已经使用的百分比 Sql代码 select   a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024   "used MB",b.bytes/1024/1024 "free MB",round(((a.by

如何查看MySQL中每张表占用的空间大小

如题,找到MySQL中的information_schema表,这张表记录了所有数据库中表的信息,主要字段含义如下: TABLE_SCHEMA : 数据库名 TABLE_NAME:表名 ENGINE:所使用的存储引擎 TABLES_ROWS:记录数 DATA_LENGTH:数据大小 INDEX_LENGTH:索引大小 如果需要查询所有数据库占用空间大小只需要执行SQL命令: mysql> use information_schema Database changed mysql> SELECT

Linux中查看磁盘大小、文件大小、排序方法小结

一,查看磁盘空间大小的命令:dfdf命令用于查看磁盘分区上的磁盘空间,包括使用了多少,还剩多少,默认单位是KB 比如以下命令: df -hl执行结果如下: 执行的结果每列的含义: 第一列Filesystem,磁盘分区 第二列Size,磁盘分区的大小 第三列Used,已使用的空间 第四列Avail,可用的空间 第五列Use%,已使用的百分比 第六列Mounted on,挂载点 解释一下后面的h和l参数,h是把显示的单位改成容易辨认的单位,不再是默认的KB了,而l参数表示只显示本地磁盘分区,不包含的