為Active DataGuard的備庫生成statspack報告並實現定時傳送
因為備庫的資料與主庫完全一樣且只讀,所以備庫無法收集AWR報告,在備庫上收集到的AWR其實是主庫的資料資訊。針對需要監控備庫的效能這種情況,11g提供了一種辦法,可以收集備庫的statspack。
本文說明如何配置statspack並實現定時透過郵件傳送報表到指定人員,下面為詳細步驟:
注意,下面所有操作都是在主庫上執行:
一、安裝配置statspack
1、建立單獨的表空間
$ sqlplus / as sysdba
SQL> create tablespace statspack '/oracle/data/statspack01.dbf' size 500m autoextend on maxsize unlimited;
2、安裝statspack使用者和物件
$ sqlplus / as sysdba
SQL> @?/rdbms/admin/spcreate.sql
輸入PERFSTAT使用者的密碼,這裡為aaa
預設表空間為sysaux,可以指定為statspack表空間
指定臨時表空間為temp
SQL> @?/rdbms/admin/sbcreate.sql
輸入PERFSTAT使用者的密碼,這裡為aaa
預設表空間為sysaux,可以指定為statspack表空間
指定臨時表空間為temp
SQL> @?/rdbms/admin/sbcreate.sql
輸入STDBYPERF使用者的密碼,這裡為bbb
預設表空間為sysaux,可以指定為statspack表空間
指定臨時表空間為temp
3、新增備庫例項
在執行sbcreate.sql指令碼時,建立完物件時會自動呼叫/rdbms/admin/sbaddins指令碼來新增備庫例項:
THE INSTANCE YOU ARE GOING TO ADD MUST BE ACCESSIBLE AND OPEN READ ONLY
Do you want to continue (y/n) ?
Enter value for key: y
You entered: y
Do you want to continue (y/n) ?
Enter value for key: y
You entered: y
需要輸入standby資料庫在主庫中的tns的名稱:
Enter the TNS ALIAS that connects to the standby database instance
-----------------------------------------------------------------
Make sure the alias connects to only one instance (without load balancing).
Enter value for tns_alias: orclb
需要輸入standby資料庫中perfstat使用者的密碼:
Enter the PERFSTAT user's password of the standby database
---------------------------------------------------------
Performance data will be fetched from the standby database via
database link. We will connect to user PERFSTAT.
Enter value for perfstat_password: aaa
Enter the TNS ALIAS that connects to the standby database instance
-----------------------------------------------------------------
Make sure the alias connects to only one instance (without load balancing).
Enter value for tns_alias: orclb
需要輸入standby資料庫中perfstat使用者的密碼:
Enter the PERFSTAT user's password of the standby database
---------------------------------------------------------
Performance data will be fetched from the standby database via
database link. We will connect to user PERFSTAT.
Enter value for perfstat_password: aaa
4、收集快照:
$ sqlplus stdbyperf/bbb;
SQL> exec statspack_orclb_orcl.snap;
SQL> exec statspack_orclb_orcl.snap;
格式為statspack_(db_unique_name)_(instance_name).snap
5、生成報表:
SQL> @?/rdbms/admin/sbreport.sql
Instances in this Statspack schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Unique Name Instance Name
------------------------------ ----------------
orclb orcl
Enter the DATABASE UNIQUE NAME of the standby database to report
Enter value for db_unique_name: orclb
You entered: orclb
Enter the INSTANCE NAME of the standby database instance to report
Enter value for inst_name: orcl
You entered: orcl
Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing <return> without
specifying a number lists all completed snapshots.
Listing all Completed Snapshots
Snap
Instance Snap Id Snap Started Level Comment
------------ --------- ----------------- ----- --------------------
orcl 1 27 Oct 2015 18:38 5
2 27 Oct 2015 18:46 5
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 1
Begin Snapshot Id specified: 1
Enter value for end_snap: 2
End Snapshot Id specified: 2
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is sb_orclb_orcl_1_2. To use this name,
press <return> to continue, otherwise enter an alternative.
Instances in this Statspack schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Unique Name Instance Name
------------------------------ ----------------
orclb orcl
Enter the DATABASE UNIQUE NAME of the standby database to report
Enter value for db_unique_name: orclb
You entered: orclb
Enter the INSTANCE NAME of the standby database instance to report
Enter value for inst_name: orcl
You entered: orcl
Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing <return> without
specifying a number lists all completed snapshots.
Listing all Completed Snapshots
Snap
Instance Snap Id Snap Started Level Comment
------------ --------- ----------------- ----- --------------------
orcl 1 27 Oct 2015 18:38 5
2 27 Oct 2015 18:46 5
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 1
Begin Snapshot Id specified: 1
Enter value for end_snap: 2
End Snapshot Id specified: 2
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is sb_orclb_orcl_1_2. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: /tmp/sb_orclb_orcl_1_2
所有收集到的資料會儲存在stdbyperf使用者下面。
二、配置statspack定時收集snapshot
1、以使STATSPACK每小時收集一次備庫的snapshot為例說明
在/tmp目錄下建立sbauto.sql指令碼,內容如下(從$ORACLE_HOME/rdbms/admin/spauto.sql指令碼改編而來):
spool sbauto.lis
variable jobno number;
variable instno number;
begin
select 1 into :instno from dual;
dbms_job.submit(:jobno, 'statspack_orclb_orcl.snap;', trunc(sysdate+1/24,'HH'), 'trunc(SYSDATE+1/24,''HH'')', TRUE, :instno);
commit;
end;
/
variable instno number;
begin
select 1 into :instno from dual;
dbms_job.submit(:jobno, 'statspack_orclb_orcl.snap;', trunc(sysdate+1/24,'HH'), 'trunc(SYSDATE+1/24,''HH'')', TRUE, :instno);
commit;
end;
/
prompt the job:
print jobno
print jobno
prompt The next scheduled run for this job is:
select job, next_date, next_sec
from user_jobs
where job = :jobno;
select job, next_date, next_sec
from user_jobs
where job = :jobno;
spool off;
2、執行指令碼:
在主庫上使用stdbyperf使用者登入
$ sqlplus stdbyperf/bbb;
SQL> @/tmp/sbauto.sql
3、查詢任務是否建立成功
$ sqlplus stdbyperf/bbb;
SQL> select job,log_user,priv_user,schema_user,next_date,next_sec from user_jobs;
三、設定定時產生報表併傳送:
1、建立生成報表併傳送的指令碼:
改指令碼範例為當天12點到14點的statspack報告。
$ vi /home/oracle/scripts/get_statspack.sh
內容如下:
. /home/oracle/.bash_profile
LOGDIR=/u02/monitor/log
date=`date '+%Y%m%d'`
date=`date '+%Y%m%d'`
filename=statspack_$date.txt
db_unique_name=orclb
inst_name=orcl
minid=`sqlplus -s / as sysdba <<EOF
set pagesize 0 feedback off verify off heading off echo off
select min(snap_id) from stdbyperf.stats\\$snapshot where snap_time between trunc(Sysdate)+12/24 And trunc(Sysdate)+14/24;
exit;
EOF`
maxid=`sqlplus -s / as sysdba <<EOF
set pagesize 0 feedback off verify off heading off echo off
select max(snap_id) from stdbyperf.stats\\$snapshot where snap_time between trunc(Sysdate)+12/24 And trunc(Sysdate)+14/24;
exit;
EOF`
sqlplus -S stdbyperf/bbb <<EOF
@$ORACLE_HOME/rdbms/admin/sbreport.sql
$db_unique_name
$inst_name
$minid
$maxid
inst_name=orcl
minid=`sqlplus -s / as sysdba <<EOF
set pagesize 0 feedback off verify off heading off echo off
select min(snap_id) from stdbyperf.stats\\$snapshot where snap_time between trunc(Sysdate)+12/24 And trunc(Sysdate)+14/24;
exit;
EOF`
maxid=`sqlplus -s / as sysdba <<EOF
set pagesize 0 feedback off verify off heading off echo off
select max(snap_id) from stdbyperf.stats\\$snapshot where snap_time between trunc(Sysdate)+12/24 And trunc(Sysdate)+14/24;
exit;
EOF`
sqlplus -S stdbyperf/bbb <<EOF
@$ORACLE_HOME/rdbms/admin/sbreport.sql
$db_unique_name
$inst_name
$minid
$maxid
$LOGDIR/statspack_$date.txt
exit;
EOF
EOF
mutt -s "statspack daily report" xxx@163.com -a $LOGDIR/$filename
加上執行許可權:
chmod u+x /home/oracle/scripts/get_statspack.sh
2、建立定時任務:
$ crontab -e
30 15 * * * sh /home/oracle/scripts/get_statspack.sh >> /home/oracle/log/get_statspack.log
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26194851/viewspace-1817451/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 監控備庫效能,為Active DataGuard的備庫生成statspack報告並實現定時傳送
- 【效能優化】Oracle 部署 Statspack並生成報告優化Oracle
- 自動生成addm報告並以郵件傳送
- 自動生成AWR報告並以郵件附件傳送
- 【效能最佳化】Oracle 部署 Statspack並生成報告Oracle
- Statspack之六-生成分析報告
- 定時自動生成awr報告
- 指令碼:定時生成awr報告指令碼
- BMMySQL定時備份資料庫(全庫備份)的實現meuMySql資料庫
- statspack 報告分析
- 基於AWR實現STATSPACK報告(4-等待事件)事件
- 基於AWR實現STATSPACK報告(5-TOPSQL)SQL
- 基於AWR實現STATSPACK報告(7-TOPSEGMENT)
- 收到263定時傳送郵件的傳送提醒
- 定時傳送郵件
- 定時備份 MySQL 並上傳到七牛MySql
- Linux實現定時備份MySQL資料庫並刪除30天前的備份檔案LinuxMySql資料庫
- 基於AWR實現STATSPACK報告(2-系統效率)
- 基於AWR實現STATSPACK報告(3-RAC統計)
- 基於AWR實現STATSPACK報告(6-例項元件)元件
- vbs指令碼和windows定時任務實現qq訊息表情包定時傳送指令碼Windows
- 使用RMAN DUPLICATE...FROM ACTIVE DATABASE命令來建立DataGuard物理備庫Database
- 詳解statspack 報告
- dataguard 主備庫出現gap
- node 定時傳送郵件
- MySQL資料庫定時備份的幾種實現方法MySql資料庫
- DataGuard切換(主庫為Rac+備庫為Rac)
- 備庫的切換狀態為SWITCHOVER PENDING時進行dataguard主備庫角色切換
- 一個備份集同時恢出dataguard的主庫&備庫
- 基於AWR實現STATSPACK報告(1-系統負載)負載
- 基於AWR實現STATSPACK報告(8-例項元件二)元件
- node.js爬取資料並定時傳送HTML郵件Node.jsHTML
- 達夢資料庫如何來配置並生成AWR報告資料庫
- dataguard備庫出現GAP修復
- statspack報告分析摘錄
- Statspack分析報告說明
- Statspack分析報告詳解
- statspack中報告中的等待事件事件