Oracle 歸檔開啟切換和歸檔日志刪除(單實例和RAC)


Oracle默認安裝后,是沒有開啟歸檔模式的,需要手動開啟。

開啟歸檔
--單實例
如果archive log模式下不能正常startup,則先恢復成noarchive log,startup成功后,再shutdown;
SQL> select group#,thread# from v$log;

GROUP# THREAD#
---------- ----------
1 1
2 1
3 2
4 2
5 1

shutdown immediate;
startup mount;
alter database noarchivelog;
alter database open;
--alter system set log_archive_format='%s_%t_%r.log' scope=spfile;
--alter system set log_archive_dest_1='location=/u01/app/oracle/archive';

再次startup以archive log模式
shutdown immediate;
startup mount;
show parameter log_archive_dest;
alter database archivelog;
archive log list;
alter database open;
SQL> show parameter archive;
alter system archive log current;

--RAC ,把歸檔日志放在asm上
ASMCMD> cd ARCH
ASMCMD> ls
ASMCMD> pwd
+FRA/BOL/ARCH
ASMCMD> lsdg
SQL> select instance_name,host_name,status from gv$instance;

SQL> alter system set log_archive_dest_1='location=+FRA/BOL/ARCH' scope=spfile sid='bol1';
SQL> alter system set log_archive_format='%s_%t_%r.log' scope=spfile sid='bol1';

SQL> alter system set log_archive_dest_1='location=+FRA/BOL/ARCH' scope=spfile sid='bol2';
SQL> alter system set log_archive_format='%s_%t_%r.log' scope=spfile sid='bol2';
srvctl stop database -d bol
srvctl start instance -d bol -i bol1 -o mount

SQL> alter database archivelog;
SQL> alter database open;
SQL> archive log list;
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +FRA/bol/arch
Oldest online log sequence 91
Next log sequence to archive 93
Current log sequence 93

srvctl start instance -d bol -i bol2 -o mount
SQL> alter database open;
SQL> show parameter archive;
SQL> show parameter cluster_da

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean TRUE
cluster_database_instances integer 2
select *from v$archived_log;
1 991992944 +FRA/bol/arch/32_2_990861401.log 1 2 32
2 991993151 +FRA/bol/arch/93_1_990861401.log 1 1 93
--2個實例的歸檔日志
[grid@rac2 ~]$ asmcmd
ASMCMD> cd FRA/BOL/ARCH
ASMCMD> ls
32_2_990861401.log
33_2_990861401.log
93_1_990861401.log
94_1_990861401.log
--2個實例的歸檔文件


刪除歸檔日志
--單實例
手工刪除os的歸檔日志后,在controfile中仍然記錄着這些歸檔日志的信息,這時候需要刪除
1 刪除os文件
[root@localhost archivelog]# pwd
/u01/app/oracle/archivelog
[root@localhost archivelog]# find /u01/app/oracle/archivelog/ -mtime +30 -name '*.arc'
---執行刪除命令
find /u01/app/oracle/archivelog/ -mtime +30 -name '*.arc' -exec rm -f {} \;
[oracle@localhost ~]$ find /u01/app/oracle/archivelog/ -mtime +30 -name '*.arc' -exec rm -f {} \;
2 rman執行刪除
[oracle@localhost ~]$ rman target /
RMAN> crosscheck archivelog all;
RMAN> delete expired archivelog all;
RMAN> report obsolete;
RMAN> delete obsolete;
RMAN> list expired archivelog all;
或者直接執行
RMAN> delete archivelog all completed before 'sysdate -29';
--刪除全部歸檔日志
delete noprompt archivelog all completed before 'sysdate'; --->該命令清除所有的歸檔日志
delete noprompt archivelog all; --->同上一命令
select * from V$FLASH_RECOVERY_AREA_USAGE;
select * from v$archived_log order by first_time desc
--腳本刪除
#!/bin/bash
source /home/oracle/.bash_profile
#LOGFILE=/data/rman/rman_delete.log
#RMAN=$ORACLE_HOME/bin/rman
$ORACLE_HOME/bin/rman log=/home/oracle/del_arch$(date +%Y-%m-%d).log <<EOF
connect target sys/***@sid
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog until time 'sysdate-1';
exit;
EOF
--刪除rac的歸檔日志
[grid@rac2 ~]$ asmcmd
ASMCMD> cd FRA/BOL/ARCH
ASMCMD> ls
32_2_990861401.log
33_2_990861401.log
93_1_990861401.log
94_1_990861401.log
--進行rm刪除文件
ASMCMD> rm 32_2_990861401.log


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM