當Oracle中的歸檔日志空間滿時,則需要把它清空,否則將會影響數據庫正常運行,
將無法正常登入ORACLE,需要刪除一部分歸檔日志才能正常登入ORACLE。
一、首先刪除歸檔日志物理文件,歸檔日志一般都是位於archive目錄下,在Oracle 10g中AIX系統下文件格式為“1_17884_XXX.dbf”,建議操作前先對數據庫進行備份,刪除時至少保留最近幾天的日志用於數據庫恢復。
二、把歸檔日志的物理文件刪除后,我們就可以正常登入ORACLE了,但是還沒完全把歸檔日志刪除干凈,ORACLE的controlfile中仍然記錄着這些archivelog的信息,在oracle的OEM管理器中有可視化的日志展現出,當我們手工清除archive目錄下的文件后,這些記錄並沒有被我們從controlfile中清除掉,接下去我們要做的就是這個工作。
1.指定數據庫實例
登錄數據庫
2.連接數據庫
>RMAN TARGET / --由於沒有使用catalog 只能nocatalog方式登錄
3.查看歸檔日志的狀態
RMAN> list archivelog all;--顯示全部的歸檔日志信息
4.手工刪除歸檔日志文件
RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';
說明:
SYSDATA-7,表明當前的系統時間7天前,before關鍵字表示在7天前的歸檔日志,如果使用了閃回功能,也會刪除閃回的數據。
同樣道理,也可以刪除從7天前到現在的全部日志,不過這個命令要考慮清楚,做完這個刪除,最好馬上進行全備份數據庫
DELETE ARCHIVELOG from TIME 'SYSDATE-7'; 刪除從7天前到現在的全部日志,慎用
UNIX/LINUX下也可以通過FIND找到7天前的歸檔數據,使用EXEC子操作刪除
find /oraarchive -xdev -mtime +7 -name "*.dbf" -exec rm -f {} ;
這樣做仍然會在RMAN里留下未管理的歸檔文件
仍需要在RMAN里執行下面2條命令
rman target /
crosscheck archivelog all;
delete expired archivelog all;
YES
----------------------------------
手動刪除實際操作步驟:
用oracle用戶登陸rman並連接數據庫
rman target /
校驗日志的可用性
crosscheck archivelog all;
顯示全部的歸檔日志信息
list archivelog all;
列出所有失效的歸檔日志
list expired archivelog all;
刪除列出所有失效的歸檔日志
delete expired archivelog all;
YES
如果日志爆了,用以上命令可能不起作用,可以使用下面的命令強行刪除所有日志
delete noprompt force expired archivelog all;
list expired archivelog all;
list archivelog all;
----------------------------------
5、再次進行手工全庫備份
backup database
同時備份控制文件、參數文件、歸檔日志
6、在使用report obsolete命令報告過期備份
7、再使用delete obsolete命令刪除過期備份,若不能刪除,可以再加一個參數 force強制刪除
簡要介紹一下report obsolete命令
使用report obsolete命令報告過期備份
RMAN> report obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 125 01-NOV-04
Backup Piece 125 01-NOV-04 /data1/oracle/orabak/full_1_541045804
Backup Set 131 04-NOV-04
Backup Piece 131 04-NOV-04 /data1/oracle/orabak/full_AVATAR2_20041104_131
....
Backup Set 173 06-DEC-04
Backup Piece 173 06-DEC-04 /data1/oracle/orabak/full_AVATAR2_20041206_173
Backup Set 179 11-DEC-04
Backup Piece 179 11-DEC-04 /data1/oracle/orabak/arch544588206.arc
.....
Backup Piece 189 17-DEC-04 /data1/oracle/orabak/arch545106606.arc
Backup Set 190 17-DEC-04
Backup Piece 190 17-DEC-04 /data1/oracle/orabak/arch545106665.arc
Backup Set 191 20-DEC-04
Backup Piece 191 20-DEC-04 /data1/oracle/orabak/arch_AVATAR2_20041220_194
Archive Log 2973 20-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2985.dbf
Archive Log 2971 20-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2984.dbf
.....
Archive Log 2705 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2717.dbf
Archive Log 2704 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2716.dbf
Archive Log 2703 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2715.dbf
Archive Log 2702 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2714.dbf
4.使用delete obsolete命令刪除過期備份:
RMAN> delete obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 125 01-NOV-04
Backup Piece 125 01-NOV-04 /data1/oracle/orabak/full_1_541045804
....
Archive Log 2704 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2716.dbf
Archive Log 2703 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2715.dbf
Archive Log 2702 17-DEC-04 /opt/oracle/oradata/avatar2/archive/1_2714.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/data1/oracle/orabak/full_AVATAR2_20041206_173 recid=173 stamp=544156241
.....
deleted archive log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2715.dbf recid=2703 stamp=545108268
deleted archive log
archive log filename=/opt/oracle/oradata/avatar2/archive/1_2714.dbf recid=2702 stamp=545107659
Deleted 286 objects
RMAN> crosscheck archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=19 devtype=DISK
specification does not match any archive log in the recovery catalog
5 在rman中用crosscheck檢查歸檔日志,2個歸檔日志都是失敗的:
RMAN> crosscheck archivelog all;
釋放的通道: ORA_DISK_1
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=14 devtype=DISK
對歸檔日志的驗證失敗
存檔日志文件名 =D:ORACLEORADATATESTARCHIVE1_47.DBF 記錄 ID=1 時間戳 =572866
683
對歸檔日志的驗證失敗
存檔日志文件名 =D:ORACLEORADATATESTARCHIVE11_48.DBF 記錄 ID=2 時間戳 =57286
6931
已交叉檢驗的 2 對象
6 試着同步一下,看行不行,結果不行,crosscheck還是失敗:
RMAN> resync catalog;
正在啟動全部恢復目錄的 resync
完成全部 resync
RMAN> crosscheck archivelog all;
釋放的通道: ORA_DISK_1
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=14 devtype=DISK
對歸檔日志的驗證失敗
存檔日志文件名 =D:ORACLEORADATATESTARCHIVE1_47.DBF 記錄 ID=1 時間戳 =572866
683
對歸檔日志的驗證失敗
存檔日志文件名 =D:ORACLEORADATATESTARCHIVE11_48.DBF 記錄 ID=2 時間戳 =57286
6931
已交叉檢驗的 2 對象
7 用list expired看看是否有失效的archive log,證明沒有失效的archive log:
RMAN> list expired archivelog all;
說明與恢復目錄中的任何存檔日志均不匹配
8 更改語言環境試試,結果再次crosscheck,2個archive log 都成功了:
RMAN> exit
恢復管理器完成。
C:>set nls_lang=american_america.zhs16gbk
C:>rman catalogrman/rman@safetarget /
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: TEST (DBID=1870953724)
connected to recovery catalog database
RMAN> crosscheck archivelog all;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=9 devtype=DISK
validation succeeded for archived log
archive log filename=D:ORACLEORADATATESTARCHIVE1_47.DBF recid=1 stamp=57286
6683
validation succeeded for archived log
archive log filename=D:ORACLEORADATATESTARCHIVE11_48.DBF recid=2 stamp=5728
66931
Crosschecked 2 objects
2、使用rman清理歸檔日志
RMAN清除方式會自動清除磁盤上的歸檔日志文件,同時會釋放控制文件中對應的歸檔日志的歸檔信息。
可以基於不同的條件來清除歸檔日志,如基於SCN,基於SEQUENCE,基於TIME等方式。
對於上述的三種方式又可以配合from, until, between .. and .. 等等子句來限定范圍,方式靈活多變。
下面的命令用於校驗歸檔日志的有效性,列出無效的歸檔日志,以及以何種方式清除歸檔日志,列出幾種常用的:
delete noprompt archivelog until time "to_date('XXXX-XX-XX','YYYY-MM-DD')"; ---> 清理到某天日期之前的歸檔 delete noprompt archivelog until time "to_date('2016-09-14 18:00:00','YYYY-MM-DD hh24:mi:ss')"; ---> 清理到具體時分秒之前的歸檔日志 cross check archivelog all; --->校驗日志的可用性 list expired archivelog all; --->列出所有失效的歸檔日志 delete archivelog until sequence 16; --->刪除log sequence為16及16之前的所有歸檔日志 delete archivelog all completed before 'sysdate-7'; --->刪除系統時間7天以前的歸檔日志,不會刪除閃回區有效的歸檔日志 delete archivelog all completed before 'sysdate - 1'; --->同上,1天以前的 delete archivelog from time 'sysdate-1'; --->注意這個命令,刪除系統時間1天以內到現在的歸檔日志 delete noprompt archivelog all completed before 'sysdate'; --->該命令清除當前所有的歸檔日志 delete noprompt archivelog all completed before 'sysdate-0'; --->該命令清除當前所有的歸檔日志 delete noprompt archivelog all; --->同上一命令
自動化腳本實現清理
#對於RAC環境或者ASM需要清除archive,使用shell腳本調用RMAN是比較妥當的方式
#其次,如果你的archive位於閃回區,制定合理的保留策略,也可以讓Oracle自動老化無用的歸檔日志
robin@SZDB:~/dba_scripts/custom/bin> cat clean_arch.sh
#!/bin/bash
#cd /u01/app/ora/data/zst/archive/
#find . -mtime +14 |xargs rm -rf
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
#if [ -z "${1}" ];then
# echo "Usage: "
# echo " `basename $0` ORACLE_SID"
# exit 1
#fi
#ORACLE_SID=$1; export ORACLE_SID
rman log=~/rman.log <<EOF
connect target /
run{
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate - 14';
}
exit;
EOF
echo "done"
4、小結
a、歸檔日志清除的方法最好是在RMAN方式下完成,這樣子是最徹底的清除方式
b、對於生產環境應考慮在RMAN備份的時候清除歸檔日志,如backup archivelog all時使用delete input與delete all input清除歸檔日志
c、如果備份期間不清除歸檔日志則arch會很大,造成歸檔磁盤滿而導致歸檔失敗。建議還是刪除或考慮存放到閃回區
d、如果清除大部分又想保留最近的,則使用delete noprompt archivelog all completed before 'sysdate - n'方式
e、詳細的清除歸檔日志語法: http://docs.oracle.com/cd/B19306_01/backup.102/b14194/rcmsynta008.htm#RCMRF106
————————————————
[root@hch_test_121_90 ~]# more archivelog_clear.sh
#!/bin/sh
BACK_DIR=/oracle/clear_archlog/data
export DATE=`date +%F`
echo " " >> $BACK_DIR/$DATE/rman_backup.log
echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/$DATE/rman_backup.log
su - oracle -c "
mkdir -p $BACK_DIR/$DATE
rman log=$BACK_DIR/$DATE/rman_backup.log target / <<EOF
# delete force archivelog all completed before 'sysdate-1/24'; # 這里執行清除歸檔日志,如果不想手動輸入YES,則可以添加noprompt參數
delete force noprompt archivelog all completed before 'sysdate-1/24';
exit;
EOF
"
echo " " >> $BACK_DIR/$DATE/rman_backup.log
crontab定時任務
[root@hch_test_121_90 ~]# crontab -l 10 */1 * * * sh /home/oracle/archivelog_clear.sh
------------------------------------------
Oracle RMAN 清除歸檔日志
原創Leshami 最后發布於2013-07-12 11:03:36 閱讀數 44565 收藏
展開
在開發環境及UAT環境經常碰到需要清除歸檔日志的情形,對於這個問題方法有很多。可以直接使用rm方式清除歸檔日志,也可以使用find命令來查找符合條件的記錄來清除歸檔日志,或者直接寫個shell腳本來搞定。這樣在DEV或者UAT還可以,但是在Prod環境還是建議使用RMAN提供的命令來搞定比較妥當。因為rm,find方式刪除了實際的歸檔日志也釋放了空間,但對應的存儲在控制文件中的歸檔信息並沒有徹底清除。依舊占用着一些空間未能及時清除而需要控制文件通過age out方式來釋放空間。本文描述了使用RMAN方式來清除歸檔日志,同時也可以將其部署到shell腳本中使用。
有關閱讀本文需要的相關參考
Oracle 歸檔日志
Oracle 控制文件(CONTROLFILE)
Oracle 聯機重做日志文件(ONLINE LOG FILE)
delete archivelog all 無法徹底刪除歸檔日志?
Linux/Unix shell 腳本中調用SQL,RMAN腳本
Linux/Unix shell 腳本清除歸檔日志文件
1、清除歸檔日志的方式
a、手動刪除
使用rm 或者find方式來刪除,通過該方式刪除之后,在RMAN下可以通過 crosscheck archivelog all 校驗歸檔是否失效,如下面的操作:
rm -rf arch_816906485_1_10.arc
find /u02/database/GOBO1/archive/ -ctime +0 -delete
RMAN> crosscheck archivelog all
b、使用RMAN方式清除
RMAN清除方式會自動清除磁盤上的歸檔日志文件,同時會釋放控制文件中對應的歸檔日志的歸檔信息。
可以基於不同的條件來清除歸檔日志,如基於SCN,基於SEQUENCE,基於TIME等方式。
對於上述的三種方式又可以配合from, until, between .. and .. 等等子句來限定范圍,方式靈活多變。
下面的命令用於校驗歸檔日志的有效性,列出無效的歸檔日志,以及以何種方式清除歸檔日志,列出幾種常用的:
crosscheck archivelog all; --->校驗日志的可用性
list expired archivelog all; --->列出所有失效的歸檔日志
delete archivelog until sequence 16; --->刪除log sequence為16及16之前的所有歸檔日志
delete archivelog all completed before 'sysdate-7'; --->刪除系統時間7天以前的歸檔日志,不會刪除閃回區有效的歸檔日志
delete archivelog all completed before 'sysdate - 1'; --->同上,1天以前的
delete archivelog from time 'sysdate-1'; --->注意這個命令,刪除系統時間1天以內到現在的歸檔日志
delete noprompt archivelog all completed before 'sysdate'; --->該命令清除所有的歸檔日志
delete noprompt archivelog all; --->同上一命令
2、演練使用RMAN清除歸檔日志
robin@SZDB:~> export ORACLE_SID=GOBO1
robin@SZDB:~> rman target /
Recovery Manager: Release 10.2.0.3.0 - Production on Thu Jul 11 17:07:00 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GOBO1 (DBID=733951103)
RMAN> host;
robin@SZDB:~> cd /u02/database/GOBO1/archive/
robin@SZDB:/u02/database/GOBO1/archive> ls
arch_816906485_1_10.arc arch_816906485_1_12.arc
arch_816906485_1_11.arc arch_816906485_1_13.arc
............
robin@SZDB:/u02/database/GOBO1/archive> rm -rf arch_816906485_1_10.arc arch_816906485_1_11.arc arch_816906485_1_12.arc
robin@SZDB:/u02/database/GOBO1/archive> exit;
exit
host command complete
RMAN> crosscheck archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_9.arc recid=2085 stamp=817211151
validation failed for archived log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_10.arc recid=2086 stamp=817250793
..............
validation succeeded for archived log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_90.arc recid=2166 stamp=820458049
Crosschecked 83 objects
RMAN> list expired archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2086 1 10 X 20130604 11:05:51 /u02/database/GOBO1/archive/arch_816906485_1_10.arc
2087 1 11 X 20130604 22:06:17 /u02/database/GOBO1/archive/arch_816906485_1_11.arc
2088 1 12 X 20130605 19:30:53 /u02/database/GOBO1/archive/arch_816906485_1_12.arc
RMAN> delete archivelog until sequence 16;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2084 1 8 A 20130604 09:53:17 /u02/database/GOBO1/archive/arch_816906485_1_8.arc
.................
2092 1 16 A 20130607 22:03:23 /u02/database/GOBO1/archive/arch_816906485_1_16.arc
Do you really want to delete the above objects (enter YES or NO)? yes
...............
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_16.arc recid=2092 stamp=817516861
Deleted 9 objects
RMAN> delete archivelog all completed before 'sysdate-7';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2093 1 17 A 20130608 00:01:00 /u02/database/GOBO1/archive/arch_816906485_1_17.arc
2094 1 18 A 20130608 18:00:17 /u02/database/GOBO1/archive/arch_816906485_1_18.arc
...........
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_72.arc recid=2148 stamp=819847035
Deleted 56 objects
RMAN> list copy of database archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2149 1 73 A 20130703 23:17:13 /u02/database/GOBO1/archive/arch_816906485_1_73.arc
2150 1 74 A 20130704 22:00:19 /u02/database/GOBO1/archive/arch_816906485_1_74.arc
2151 1 75 A 20130704 22:04:40 /u02/database/GOBO1/archive/arch_816906485_1_75.arc
...............
2164 1 88 A 20130709 23:19:34 /u02/database/GOBO1/archive/arch_816906485_1_88.arc
2165 1 89 A 20130710 13:00:34 /u02/database/GOBO1/archive/arch_816906485_1_89.arc
2166 1 90 A 20130710 22:02:44 /u02/database/GOBO1/archive/arch_816906485_1_90.arc
RMAN> delete archivelog from time 'sysdate-1';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2165 1 89 A 20130710 13:00:34 /u02/database/GOBO1/archive/arch_816906485_1_89.arc
2166 1 90 A 20130710 22:02:44 /u02/database/GOBO1/archive/arch_816906485_1_90.arc
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_89.arc recid=2165 stamp=820447373
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_90.arc recid=2166 stamp=820458049
Deleted 2 objects
RMAN> delete archivelog all completed before 'sysdate - 1';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2149 1 73 A 20130703 23:17:13 /u02/database/GOBO1/archive/arch_816906485_1_73.arc
.......................
2164 1 88 A 20130709 23:19:34 /u02/database/GOBO1/archive/arch_816906485_1_88.arc
Do you really want to delete the above objects (enter YES or NO)? yes
................
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_88.arc recid=2164 stamp=820414835
Deleted 16 objects
RMAN> sql " alter system archive log current";
sql statement: alter system archive log current
RMAN> list copy of archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2167 1 91 A 20130711 01:00:48 /u02/database/GOBO1/archive/arch_816906485_1_91.arc
RMAN> delete noprompt archivelog all completed before 'sysdate';
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1075 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ----------------- ----
2167 1 91 A 20130711 01:00:48 /u02/database/GOBO1/archive/arch_816906485_1_91.arc
deleted archive log
archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_91.arc recid=2167 stamp=820517964
Deleted 1 objects
3、清除歸檔日志簡單的shell腳本
#對於RAC環境或者ASM需要清除archive,使用shell腳本調用RMAN是比較妥當的方式
#其次,如果你的archive位於閃回區,制定合理的保留策略,也可以讓Oracle自動老化無用的歸檔日志
robin@SZDB:~/dba_scripts/custom/bin> more clean_arch.sh
# +-------------------------------------------------------+
# + Clean archived log as specified time |
# + Author : Robinson |
# + Blog : http://blog.csdn.net/robinson_0612 |
# + Usage : |
# + clean_arch.sh $ORACLE_SID |
# +-------------------------------------------------------+
#
#!/bin/bash
# --------------------
# Define variable
# --------------------
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
if [ -z "${1}" ];then
echo "Usage: "
echo " `basename $0` ORACLE_SID"
exit 1
fi
ORACLE_SID=$1; export ORACLE_SID
$ORACLE_HOME/bin/rman log=/users/robin/log/rman.log <<EOF
connect target /
run{
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate - 1';
}
exit;
EOF
exit
4、小結
a、歸檔日志清除的方法最好是在RMAN方式下完成,這樣子是最徹底的清除方式
b、對於生產環境應考慮在RMAN備份的時候清除歸檔日志,如backup archivelog all時使用delete input與delete all input清除歸檔日志
c、如果備份期間不清除歸檔日志則arch會很大,造成歸檔磁盤滿而導致歸檔失敗。建議還是刪除或考慮存放到閃回區
d、如果清除大部分又想保留最近的,則使用delete noprompt archivelog all completed before 'sysdate - n'方式
e、詳細的清除歸檔日志語法: http://docs.oracle.com/cd/B19306_01/backup.102/b14194/rcmsynta008.htm#RCMRF106
相關參考
Oracle 冷備份
Oracle 熱備份
Oracle 備份恢復概念
Oracle 實例恢復
Oracle 基於用戶管理恢復的處理
SYSTEM 表空間管理及備份恢復
SYSAUX表空間管理及恢復
Oracle 基於備份控制文件的恢復(unsing backup controlfile)
RMAN 概述及其體系結構
RMAN 配置、監控與管理
RMAN 備份詳解
RMAN 還原與恢復
RMAN catalog 的創建和使用
基於catalog 創建RMAN存儲腳本
基於catalog 的RMAN 備份與恢復
RMAN 備份路徑困惑
自定義 RMAN 顯示的日期時間格式
只讀表空間的備份與恢復
Oracle 基於用戶管理的不完全恢復
理解 using backup controlfile
使用RMAN實現異機備份恢復(WIN平台)
使用RMAN遷移文件系統數據庫到ASM
基於Linux下 Oracle 備份策略(RMAN)
Linux 下RMAN備份shell腳本
使用RMAN遷移數據庫到異機
RMAN 提示符下執行SQL語句
Oracle 基於 RMAN 的不完全恢復(incomplete recovery by RMAN)
————————————————
版權聲明:本文為CSDN博主「Leshami」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/robinson_0612/java/article/details/9308287
業務增長發展迅猛,歸檔日志增長太快,磁盤承受不了,所以准備做個定時清理歸檔日志的定時任務
ORACLE 定時清理歸檔日志詳細過程
1、RM方式清理歸檔日志
清理歸檔日志,可以人為的刪除已經歸檔好的日志文件,然后再調用rman里面RMAN> crosscheck archivelog all;來去數據庫里面刪除歸檔記錄;也可以通過ram調用delete命令來刪除歸檔日志。
2、使用rman清理歸檔日志
RMAN清除方式會自動清除磁盤上的歸檔日志文件,同時會釋放控制文件中對應的歸檔日志的歸檔信息。
可以基於不同的條件來清除歸檔日志,如基於SCN,基於SEQUENCE,基於TIME等方式。
對於上述的三種方式又可以配合from, until, between .. and .. 等等子句來限定范圍,方式靈活多變。
下面的命令用於校驗歸檔日志的有效性,列出無效的歸檔日志,以及以何種方式清除歸檔日志,列出幾種常用的:
delete noprompt archivelog until time "to_date('XXXX-XX-XX','YYYY-MM-DD')"; ---> 清理到某天日期之前的歸檔 delete noprompt archivelog until time "to_date('2016-09-14 18:00:00','YYYY-MM-DD hh24:mi:ss')"; ---> 清理到具體時分秒之前的歸檔日志 cross check archivelog all; --->校驗日志的可用性 list expired archivelog all; --->列出所有失效的歸檔日志 delete archivelog until sequence 16; --->刪除log sequence為16及16之前的所有歸檔日志 delete archivelog all completed before 'sysdate-7'; --->刪除系統時間7天以前的歸檔日志,不會刪除閃回區有效的歸檔日志 delete archivelog all completed before 'sysdate - 1'; --->同上,1天以前的 delete archivelog from time 'sysdate-1'; --->注意這個命令,刪除系統時間1天以內到現在的歸檔日志 delete noprompt archivelog all completed before 'sysdate'; --->該命令清除當前所有的歸檔日志 delete noprompt archivelog all completed before 'sysdate-0'; --->該命令清除當前所有的歸檔日志 delete noprompt archivelog all; --->同上一命令
3、實現清理一個小時前的歸檔日志
執行命令:delete force archivelog all completed before 'sysdate-1/24';
(1)查看當前時間 [oracle@hch_test_121_90 ~]$ date Tue Oct 11 11:20:20 CST 2016 [oracle@hch_test_121_90 ~]$ (2)查看當前一個小時之前的歸檔日志,看到有一個o1_mf_1_2822_czrm1dj8_.arc,如下所示: [oracle@hch_test_121_90 ~]$ ll /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/ |more total 3181880 -rw-r----- 1 oracle oinstall 41340416 Oct 11 10:19 o1_mf_1_2822_czrm1dj8_.arc -rw-r----- 1 oracle oinstall 40434176 Oct 11 10:20 o1_mf_1_2823_czrm49l9_.arc -rw-r----- 1 oracle oinstall 41180160 Oct 11 10:22 o1_mf_1_2824_czrm76nd_.arc -rw-r----- 1 oracle oinstall 40340480 Oct 11 10:23 o1_mf_1_2825_czrm9xos_.arc (3)開始執行刪除命令,按計划刪除這一條歸檔日志 RMAN> delete force archivelog all completed before 'sysdate-1/24'; using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=11 device type=DISK List of Archived Log Copies for database with db_unique_name POWERDES ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 1396 1 2822 A 11-OCT-16 Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2822_czrm1dj8_.arc Do you really want to delete the above objects (enter YES or NO)? YES # 輸入刪除命令 deleted archived log archived log file name=/oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2822_czrm1dj8_.arc RECID=1396 STAMP=924949164 Deleted 1 objects RMAN>
4、自動化腳本定時任務實現清理一個小時前的歸檔日志
(1)自動化腳本
[root@hch_test_121_90 ~]# more archivelog_clear.sh
#!/bin/sh
BACK_DIR=/oracle/clear_archlog/data
export DATE=`date +%F`
echo " " >> $BACK_DIR/$DATE/rman_backup.log
echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/$DATE/rman_backup.log
su - oracle -c "
mkdir -p $BACK_DIR/$DATE
rman log=$BACK_DIR/$DATE/rman_backup.log target / <<EOF
# delete force archivelog all completed before 'sysdate-1/24'; # 這里執行清除歸檔日志,如果不想手動輸入YES,則可以添加noprompt參數
delete force noprompt archivelog all completed before 'sysdate-1/24';
exit;
EOF
"
echo " " >> $BACK_DIR/$DATE/rman_backup.log
(2)crontab定時任務
[root@hch_test_121_90 ~]# crontab -l 10 */1 * * * sh /home/oracle/archivelog_clear.sh
(3)查看執行后的日志
[root@hch_test_121_90 ~]# more /oracle/clear_archlog/data/2016-10-11/rman_backup.log Recovery Manager: Release 11.2.0.1.0 - Production on Tue Oct 11 11:28:04 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: POWERDES (DBID=3458668465) RMAN> using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=137 device type=DISK List of Archived Log Copies for database with db_unique_name POWERDES ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 1397 1 2823 A 11-OCT-16 Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2823_czrm49l9_.arc 1398 1 2824 A 11-OCT-16 Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2824_czrm76nd_.arc 1399 1 2825 A 11-OCT-16 Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2825_czrm9xos_.arc 1400 1 2826 A 11-OCT-16 Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2826_czrmdqqy_.arc 1401 1 2827 A 11-OCT-16 Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2827_czrmhksn_.arc Do you really want to delete the above objects (enter YES or NO)? "exit;" is an invalid response - please re-enter. Do you really want to delete the above objects (enter YES or NO)? Error occurred getting response - assuming NO response RMAN> Recovery Manager complete.
作者:泡菜愛上WaSabi
鏈接:https://www.jianshu.com/p/a8031357c65d
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。