quark如何查看表占用空间的大小

  其他常见问题
内容纲要

原理描述


经常会遇到客户需要获取一张表占用空间的大小,或者需要清理空间排查哪些表占用空间过大的诉求,这时候可以用到inceptor中的数据字典表system.table_stats_v,该视图是通过table_size函数对system.tables_v视图的database_name,table_name,table_location,input_format列来计算表的大小的。

> DESCRIBE FUNCTION EXTENDED table_size;
 - table_size(database_name, table_name, table_location, input_format) 
 - returns the size of database.table, eg: '101.9 M'
> SELECT
>   table_size('default',
>              'people_orc',
>              'hdfs://nameservice1/inceptor1/user/hive/warehouse/default.db/lkw/people_orc',
>              'orc')
> FROM system.dual;
 - 414 M

需要注意的是,像ES、hyperdrive、hyperbase这些外部存储的表是不支持查看table_size的,所以这些table_format类型的表,在该视图中的table_size为NULL,本文会通过其他方式来获取这些表的空间大小。

详细说明


1. orc表、text表、csv表

--查看指定表占用空间的大小
> SELECT * FROM system.table_stats_v t WHERE t.database_name='default' AND t.table_name='people_orc';

file

-- 该参数避免decimal类型小数点后面的0显示不了造成的排序混乱
SET inceptor.decimal.display.padding.zero=true;
-- 对table_size倒序排列,检查哪些表占用空间过大,注意避开table_size为null的表
SELECT
    t.database_name,
    t.table_name,
    t.table_format,
    t.table_size,
    decimal(CASE 
        WHEN t.table_size LIKE '%B' 
            THEN regex_substr(t.table_size,'[^ ]+',1)/1024/1024/1024
        WHEN t.table_size LIKE '%K' 
            THEN regex_substr(t.table_size,'[^ ]+',1)/1024/1024
        WHEN t.table_size LIKE '%M' 
            THEN regex_substr(t.table_size,'[^ ]+',1)/1024
        WHEN t.table_size LIKE '%G' 
            THEN regex_substr(t.table_size,'[^ ]+',1)/1
        END
        )||'G' AS size
FROM system.table_stats_v t
    WHERE t.table_size IS NOT NULL
    ORDER BY size DESC ;

file

2. search表

方法一:head页面
通过search head 索引页面下的size查看大小

方法二:curl命令
curl -X GET "172.22.23.1:9200/_cat/indices?pretty"

3. hyperbase表、hyperdrive表

统计hdfs中{hbase.rootdir}/datanase/table_name的大小

注意! 并不是show create table {hbase_table} 中LOCATION的路径下文件的大小哦 !

# 一般在TDH中hbase.rootdir配置为hdfs://nameservice1/hyperbase1
$ hadoop fs -du -s -h /hyperbase1/data/datanase/table_name

以default库的people_hyperbase_1000w表为例

file

4. holodesk表

方法一:dbaservice_db_stats.holo_table_stats表

该表是dbaservice9.2以上版本才提供的功能,可以通过库表的形式存储holodesk表的统计信息。

需要注意的是,这个表的数据并不是实时准确的,DBAService会在每天23:00更新所有库表的信息,如果想获取实时数据,需要在dbaservice进行一次Update data。

SELECT databasename||'.'||tablename as 表, tablebytes as 字节数 FROM dbaservice_db_stats.holo_table_stats;

file

方法二:DBAservice页面

file

同时我们支持Download下载功能,可以将表的相关信息整合到一个excel文件种,e.g :

file

方法三:Restful API

如果是shiva1 (需要用namespace):
curl -X GET "172.22.23.95:4567/table/description?pretty&namespace=default&table_name=default.global_people_holodesk_2ba7ce71-fcad-4324-aa66-ad3692fad5c4" | grep table_size_bytes

如果是shiva2 (需要用database):
curl -X GET "172.22.23.95:4567/table/description?pretty&database=default&table_name=default.global_people_holodesk_2ba7ce71-fcad-4324-aa66-ad3692fad5c4" | grep table_size_bytes

file

注:这里的 750263814 单位为bytes

这篇文章对您有帮助吗?

平均评分 5 / 5. 次数: 1

尚无评价,您可以第一个评哦!

非常抱歉,这篇文章对您没有帮助.

烦请您告诉我们您的建议与意见,以便我们改进,谢谢您。