Oracle AWR 資料匯入/匯出的步驟

mahanso發表於2017-12-26
LINUX狀態下,連線oracle使用者:su - oracle 
1.上傳採集快照.dmp檔案至伺服器  (dbid:4292035712)  919219826
2.在伺服器端建立目錄 (即資料夾awrtest)
$> mkdir /home/oracle/awrtest 

3.把第一步中上傳的.dmp檔案,移動到第二步中建立的資料夾中:

$> cp /var/ftp/AWR_10107.dmp(如果原檔案字尾名是.DMP一定要改成小寫.dmp) /home/oracle/awrtest 

4.切換至sqlplus狀態,並且啟動資料庫:

$> sqlplus / as sysdba 
SQL>startup;

5. 建立資料庫目錄便於資料庫查詢

SQL> create directory AWRTEST as '/home/oracle/awrtest'

6.載入資料檔案:

SQL> @?/rdbms/admin/awrload.sql
SQL>Enter value for directory_name: AWRTEST ////注意:輸入directory name 時,字母需要大寫 
Enter value for file_name: AWR_10107 ///注意:此處不要加檔案字尾名
Enter value for schema_name: AWR_STAGE //(一般預設就行)
Enter value for default_tablespace: USERS 
Enter value for temporary_tablespace: //(回車預設)

  出現一下文字,就說明匯入成功了!

... Creating AWR_STAGE user | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Loading the AWR data from the following | directory/file: | /home/oracle/awr | AWRDAT_9239_9394.dmp | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | *** AWR Load Started ... | | This operation will take a few moments. The | progress of the AWR load operation can be | monitored in the following directory/file: | /home/oracle/awr | AWRDAT_9239_9394.log | ... Dropping AWR_STAGE user End of AWR Load ----------------------------------------------------------------------------------

報錯症狀:注意資料夾復權的問題!)

[root@localhost ~]# cd /home/oracle/ [root@localhost oracle]# ls -lt
total 660 drwxr-xr-x 2 root   root 4096 Aug 6 02:07 awr
drwxr-xr-x 2 root   root 4096 Aug 6 02:04 awrtest2 -rw-r--r-- 1 oracle oinstall 326088 Jul  8 22:13 zhongxing.html -rw-r--r-- 1 oracle oinstall 311525 Jul  1 12:48 HUAYOUSHIJI.html drwxr-xr-x 3 oracle oinstall 4096 Jul 1 11:32 awrtest1
drwxr-xr-x 2 oracle oinstall 4096 Jul 1 01:10 awrtest
drwxr-xr-x 2 oracle oinstall 4096 Jun 30 12:47 jishubu
drwxr-xr-x 3 oracle oinstall 4096 Jun 22 14:58 Desktop [root@localhost oracle]# chmod -R 777 awr [root@localhost oracle]# ls -lt
total 660 drwxrwxrwx 2 root   root 4096 Aug 6 02:07 awr
drwxr-xr-x 2 root   root 4096 Aug 6 02:04 awrtest2 -rw-r--r-- 1 oracle oinstall 326088 Jul  8 22:13 zhongxing.html -rw-r--r-- 1 oracle oinstall 311525 Jul  1 12:48 HUAYOUSHIJI.html drwxr-xr-x 3 oracle oinstall 4096 Jul 1 11:32 awrtest1
drwxr-xr-x 2 oracle oinstall 4096 Jul 1 01:10 awrtest
drwxr-xr-x 2 oracle oinstall 4096 Jun 30 12:47 jishubu
drwxr-xr-x 3 oracle oinstall 4096 Jun 22 14:58 Desktop [root@localhost oracle]#

其他報錯問題 解決參考地址:

http://space.itpub.net/12129601/viewspace-735524 http://www.xifenfei.com/3966.html   惜分飛  http://blog.163.com/jet_it_life/blog/static/205097083201262431444951/directory  建立不正確導致的ORA-39070 http://www.douban.com/note/37656300/oracle impdp/expdp 的許可權問題
http://space.itpub.net/519536/viewspace-664406 侯聖文老師
AWR資料遷移參考地址:
春風:  http://www.dbdream.org/?p=223 
eygle: AWR 與 Statspack 資料的匯出與遷移  http://www.eygle.com/archives/2010/08/awr_statspack_extract.html 
7.執行相關指令碼:(如邏輯讀指令碼、db-time指令碼等)
   檢視dbid:
SQL> select dbid from v$database; 223805804 SQL> setpagesize 500 # su - oracle 
$  cd awrtest/ #根據自己的安裝目錄確認
$  ls (檢視當前目錄下檔案,確認相關檔名)

生成邏輯讀-語句: 

SELECT case when to_number(to_char(c.end_interval_time, 'mi'))<15 or to_number(to_char(c.end_interval_time, 'mi'))>=45             
                then to_char(round(c.end_interval_time, 'hh24'),'yyyy-mm-dd hh24:mi')                                              
else to_char(c.end_interval_time, 'yyyy-mm-dd hh24')||':30'                                                                        
      end end_time,                                                                                                                
      case when max(decode(a.instance_number, 1, a.value - b.value, null))<0 then null                                             
           else max(decode(a.instance_number, 1, a.value - b.value, null))                                                         
      end INST1,                                                                                                                   
      case when max(decode(a.instance_number, 2, a.value - b.value, null))<0 then null                                             
           else max(decode(a.instance_number, 2, a.value - b.value, null))                                                         
      end INST2,                                                                                                                   
      case when max(decode(a.instance_number, 3, a.value - b.value, null))<0 then null                                             
           else max(decode(a.instance_number, 3, a.value - b.value, null))                                                         
      end INST3,                                                                                                                   
      case when max(decode(a.instance_number, 4, a.value - b.value, null))<0 then null                                             
           else max(decode(a.instance_number, 4, a.value - b.value, null))                                                         
      end INST4                                                                                                                    
FROM sys.wrh$_sysstat a, sys.wrh$_sysstat b, sys.wrm$_snapshot c                                                                   
WHERE a.stat_id =3143187968                                                                                                        
  AND b.stat_id = a.stat_id                                                                                                        
  AND a.snap_id = b.snap_id + 1                                                                                                    
  AND a.snap_id = c.snap_id                                                                                                        
  and a.dbid =&dbid                                                                                                                
  and b.dbid = a.dbid                                                                                                              
  and c.dbid = a.dbid                                                                                                              
  and a.instance_number = b.instance_number                                                                                        
  and a.instance_number = c.instance_number                                                                                        
group by a.snap_id, case when to_number(to_char(c.end_interval_time, 'mi'))<15 or to_number(to_char(c.end_interval_time, 'mi'))>=45
                then to_char(round(c.end_interval_time, 'hh24'),'yyyy-mm-dd hh24:mi')                                              
else to_char(c.end_interval_time, 'yyyy-mm-dd hh24')||':30'                                                                        
      end                                                                                                                          
ORDER BY a.snap_id; 

注意:結尾的分號不能少。
 
生成db-time資料語句: 
SELECT TO_CHAR(b.end_interval_time, 'yyyy-mm-dd hh24:mi:ss') snap_time,
  --'DB Time(s)',
  CASE
    WHEN (ROUND((a.VALUE - lag(a.VALUE, 1) OVER(ORDER BY a.snap_id)) / 1000000))<0
    THEN 0
    ELSE ROUND((a.VALUE - lag(a.VALUE, 1) OVER(ORDER BY a.snap_id)) / 1000000)
  END AS "db time(s)"
FROM
  (SELECT snap_id,
    VALUE
  FROM dba_hist_sys_time_model
  WHERE stat_name     = 'DB time'
  and dbid=&db_id
  AND INSTANCE_NUMBER = &instance_id) a,
  dba_hist_snapshot b
WHERE b.dbid=&db_id
AND a.snap_id       = b.snap_id
AND b.INSTANCE_NUMBER = &instance_id
--AND b.end_interval_time > sysdate-30
ORDER BY 1;
 
Enter value for db_id: 4292035712
Enter value for instance_id: 1  ///(單例項輸入1,RAC 的根據實際情況輸入相應的值)
Enter value for db_id: 4292035712
Enter value for instance_id: 1     

8.匯入excel表 ,生成趨勢圖
   excel裡邊選擇資料 -匯入-自文字
   選擇匯入的資料-生成曲線圖-雙擊橫座標選擇文字格式
 
9. 觀察趨勢圖高峰值,匯出AWR報告,Oracle使用者下執行如下命令:
@?/rdbms/admin/awrrpti
匯出的AWR報告有兩種型別格式: .txt 和 .html
系統預設匯出是.html      一般輸入時間間隔天數:7 
按照步驟,連續操作就行。
Enter value for dbid: 4292035712 Using 4292035712 for database Id
Enter value for inst_num: 1(輸入例項個數)
Using 1 for instance number

例如:匯出時間點為:7月1日 11點 12點 負載高峰時段的AWR資料。

注意:在匯出報告時,檔案起名時要手動新增字尾名.html
    

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12272958/viewspace-2149318/,如需轉載,請註明出處,否則將追究法律責任。

相關文章