如何查询 dashDB 上已用/可用的磁盘

how to query disk used / available on dashDB

我想以编程方式查询磁盘 space 已用和剩余​​ space。我如何在 dashDB 中执行此操作?

在 oracle 中,我可以执行这样的操作:

column dummy noprint
column  pct_used format 999.9               heading "%|Used"
column  name    format a16                  heading "Tablespace Name"
column  bytes   format 9,999,999,999,999    heading "Total Bytes"
column  used    format 99,999,999,999       heading "Used"
column  free    format 999,999,999,999      heading "Free"
break   on report
compute sum of bytes on report
compute sum of free on report
compute sum of used on report

set linesize 132
set termout off
select a.tablespace_name                                              name,
       b.tablespace_name                                              dummy,
       sum(b.bytes)/count( distinct a.file_id||'.'||a.block_id )      bytes,
       sum(b.bytes)/count( distinct a.file_id||'.'||a.block_id ) -
       sum(a.bytes)/count( distinct b.file_id )                       used,
       sum(a.bytes)/count( distinct b.file_id )                       free,
       100 * ( (sum(b.bytes)/count( distinct a.file_id||'.'||a.block_id )) -
               (sum(a.bytes)/count( distinct b.file_id ) )) /
       (sum(b.bytes)/count( distinct a.file_id||'.'||a.block_id ))    pct_used
from sys.dba_free_space a, sys.dba_data_files b
where a.tablespace_name = b.tablespace_name
group by a.tablespace_name, b.tablespace_name;

我如何使用 dashDB 做类似的事情?

目前没有 API 呼吁这样做。 (在此处查找可用的 API 调用:https://developer.ibm.com/clouddataservices/docs/dashdb/rest-api/)目前,判断您正在使用或剩余多少 space 的唯一方法是通过 dashDB UI。我知道,dashDB 团队正在探索更多的可能性。如果我了解更多,我会post再次来到这里

一个简单快速的方法是查看目录,它最终是最新的(当目录表用最新统计信息更新时,内部会以特定的时间间隔收集统计信息):

select substr(a.tabname,1,30), (a.fpages*PAGESIZE/1024) as size_k, a.card from syscat.tables a, syscat.tablespaces b where a.TBSPACEID=b.TBSPACEID ;

更准确但成本更高的方法是:

SELECT TABSCHEMA, TABNAME, SUM(DATA_OBJECT_P_SIZE) + SUM(INDEX_OBJECT_P_SIZE)+ SUM(LONG_OBJECT_P_SIZE) + SUM(LOB_OBJECT_P_SIZE)+ SUM(XML_OBJECT_P_SIZE) FROM SYSIBMADM.ADMINTABINFO where tabschema='' and tabname='' group by tabschema,tabname;