有客户咨询在19c多租户这样的架构中,除了查询cdb本身外,还想查询具体pdb的负载(DB Time),但是使用之前的脚本发现查询不到,只显示cdb自己的结果,客户写的脚本如下:
因为自己前些年做运维的时候接触客户环境大部分还是使用的11g,没太关注这方面的更新,和同事讨论,第一想法看到 dba_hist_*
这类视图不包含pdb的信息,是否应该有 cdb_hist_*
这类的视图包含呢?
这是一个比较正常的思考方向,但实际验证发现,在这个问题上并不是这样,这两个视图都没有对应的pdb信息。
看起来不是这个问题,那难道说19c多租户架构就查不到pdb层面的dbtime吗?
这也是不太可能的,毕竟AWR都能依据pdb层面做采集和分析呢。。
发现官方文档针对 “DBA_HIST_SYS_TIME_MODEL” 的描述,下面的See Also:
有提到另外一个相关视图 “DBA_HIST_CON_SYS_TIME_MODEL”,这有啥区别?
正在找不同,此时同事 Shine 发我的一段描述恰好说明了二者的区别:
https://docs.oracle.com/en/database/oracle/oracle-database/19/tgdba/gathering-database-statistics.html#GUID-18E1B278-B3C5-4FE1-8E51-BC8878C439F5
DBA_HIST Views
The DBA_HIST views show the AWR data present only on the CDB root.
When the DBA_HIST views are accessed from a CDB root, they show all the AWR data stored on the CDB root.
When the DBA_HIST views are accessed from a PDB, they show the subset of the CDB root AWR data, which is specific to that PDB.
DBA_HIST_CON Views
The DBA_HIST_CON views are similar to the DBA_HIST views, but they provide more fine grained information about each container, and thus, they have more data than the DBA_HIST views.
The DBA_HIST_CON views show the AWR data present only on the CDB root.
When the DBA_HIST_CON views are accessed from a CDB root, they show all the AWR data stored on the CDB root.
When the DBA_HIST_CON views are accessed from a PDB, they show the subset of the CDB root AWR data, which is specific to that PDB.
感谢同事 Shine 的帮忙,更快的找到了这个区别对应的官方解释。
看起来DBA_HIST_CON系列视图会有更完整的每个pdb的信息,跟客户解释,客户说好像之前也尝试过这个视图,但是结果有负数的情况,感觉上不太对。
于是我在自己测试环境测了下,初步改了下几个点,没有细看,但没有负数显示不正确的情况:
主要修改就是替换视图,以及标识不同的con_id,具体修改如下:
我没太细看客户的脚本,在假设原脚本正确的基础上,直接进行的修改,需要客户帮测试下,看是否还有问题,目前尚未有反馈。
大家如果感兴趣也可以测试下哈,若有任何问题都欢迎找我一起探讨。
更新:
客户最终又简化了脚本,测试查询没有问题,脚本如下: