如果第一次安装Oracle 数据库,如果没有修改,默认是 NoArchivelog模式。如果数据库处于 NoArchivelog 模式,则 Oracle 不会归档联机重做日志文件。因此,在线重做日志文件已满时会被覆盖。
如果 Oracle 数据库突然重启或崩溃,那么如果没有旧的重做日志记录,它就无法持续启动。
另一方面,oracle 数据库必须处于 Archivelog 模式,以便我们可以在在线模式下进行完整备份。如果 Oracle 数据库处于 NoArchivelog 模式,则 RMAN 无法接收在线备份。
生产环境中的数据库必须是Archivelog模式,一般都是Archivelog模式。您可以根据一下查询确认是否是Archivelog模式。
[oracle@MehmetSalih ~]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Tue Mar 19 17:19:13 2019 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> select log_mode from v$database; LOG_MODE ------------ NOARCHIVELOG SQL>
不处于 Archivelog 模式的数据库通过以下步骤进入 Archivelog 模式。
1.数据库始终处于关闭状态。
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL>
2.数据库持续关闭后,数据库以挂载模式打开。
SQL> startup mount ORACLE instance started. Total System Global Area 534462464 bytes Fixed Size 2230072 bytes Variable Size 339740872 bytes Database Buffers 184549376 bytes Redo Buffers 7942144 bytes Database mounted. SQL>
3.Mount模式下的数据库如下进入归档模式。
SQL> alter database archivelog; Database altered.
4.数据库处于归档模式后,打开数据库如下。
SQL> alter database open; Database altered.
5.如果我们不指定档案的位置,它首先存储db_recovery_file_dest 的默认位置。数据库归档存储的第一个位置是 log_archive_dest_1 参数的位置。我们可以如下调整这个值。
SQL> alter system set log_archive_dest_1='location=/oracle/oradata/ARCH'; System altered.
您可以按照每小时和每天查询并列出日志开关(Archivelog)频率图,如下所示。
select to_char(first_time,'YYYY-MON-DD') day, to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'9999') "00", to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'9999') "01", to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'9999') "02", to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'9999') "03", to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'9999') "04", to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'9999') "05", to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'9999') "06", to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'9999') "07", to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'9999') "08", to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'9999') "09", to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'9999') "10", to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'9999') "11", to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'9999') "12", to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'9999') "13", to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'9999') "14", to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'9999') "15", to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'9999') "16", to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'9999') "17", to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'9999') "18", to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'9999') "19", to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'9999') "20", to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'9999') "21", to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'9999') "22", to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'9999') "23" from v$log_history group by to_char(first_time,'YYYY-MON-DD');
查询结果:
可以使用以下命令查询所有存档日志。
[MSD1]/home/oracle $ rman target / Recovery Manager: Release 18.0.0.0.0 - Production on Mon Mar 9 14:41:02 2020 Version 18.7.0.0.0 Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved. connected to target database: MSD (DBID=2054866743) RMAN> list archivelog all; using target database control file instead of recovery catalog List of Archived Log Copies for database with db_unique_name MSD ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - ------------------- 3643932 1 456786 A 09-03-2020 10:52:05 Name: /zfssa/MSDDB/ARCH2/arch_D-MSD_id-2054866743_S-456786_T-1_A-2054879031_dguqleac 3643134 1 456786 A 09-03-2020 10:52:05 Name: +RECO/MSD/ARCHIVELOG/2020_03_09/thread_1_seq_456786.10371.1034592773 3645414 8 262083 A 09-03-2020 14:37:15 Name: +RECO/MSD/ARCHIVELOG/2020_03_09/thread_8_seq_262083.28235.1034606329 3645424 8 262084 A 09-03-2020 14:38:48 Name: +RECO/MSD/ARCHIVELOG/2020_03_09/thread_8_seq_262084.56375.1034606419 RMAN>
在Oracle数据库中删除归档日志到指定时间
Delete Archivelog until time
如果数据库处于归档日志模式,则 Oracle 数据库正在归档重做日志组文件。
当重做日志文件被归档时,重做日志文件会被新的重做数据覆盖。但是,如果您不安排任何删除作业,则不会删除或自动删除存档日志
您需要定期删除归档日志,否则您将收到归档程序错误。
Delete Archivelog via RMAN
您可以使用以下查询删除所有存档日志。
RMAN> delete archivelog all;
Delete Archivelog Until Time Oracle
您可以像以下查询一样删除存档日志直到特定时间(直到时间 1 天前)。
RMAN> delete archivelog until time 'sysdate -1';
您可以在没有提示(是或否问题)和强制选项的情况下删除所有存档日志。
RMAN> delete noprompt force archivelog all;
您可以删除已备份 1 次到磁带的归档日志。您可以使用 2 或 3 更改 1 次。
RMAN> delete archivelog all backed up 1 times to SBT_TAPE;
您可以删除已备份 1 次到磁盘的归档日志。
RMAN> delete archivelog all backed up 1 times to DISK;
您可以删除归档日志直到特定序列选项。
RMAN> delete archivelog until sequence 9310 thread 1;