如何通过dba_hist_active_sess_history分析数据库历史性能问题

摘自:

https://blogs.oracle.com/Database4CN/entry/%E5%A6%82%E4%BD%95%E9%80%9A%E8%BF%87dba_hist_active_sess_history%E5%88%86%E6%9E%90%E5%8E%86%E5%8F%B2%E6%95%B0%E6%8D%AE%E5%BA%93%E6%80%A7%E8%83%BD%E9%97%AE%E9%A2%98

从Oracle 10G开始,引入了AWR和ASH采样机制,视图gv$active_session_history每秒钟将数据库所有节点的Active Session采样一次,而dba_hist_active_sess_history则会将gv$active_session_history里的数据每10秒采样一次并持久化保存。基于这个特征,可以通过分析dba_hist_active_sess_history的Session采样情况,来定位问题发生的准确时间范围,并且可以观察每个采样点的top event和top holder。

1. Dump出问题期间的ASH数据
为了不影响生产系统,我们可以将问题大概期间的ASH数据export出来在测试机上分析。
基于dba_hist_active_sess_history创建一个新表m_ash,然后将其通过exp/imp导入到测试机。在发生问题的数据库上执行exp:

SQL> conn user/passwd
SQL> create table m_ash as select * from dba_hist_active_sess_history where SAMPLE_TIME between TO_TIMESTAMP ('<time_begin>', 'YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP ('<time_end>', 'YYYY-MM-DD HH24:MI:SS');

$ exp user/passwd file=m_ash.dmp tables=(m_ash) log=m_ash.exp.log

然后导入到测试机:
$ imp user/passwd file=m_ash.dmp log=m_ash.imp.log