1、概念
归档是将联机重做日志以文件的形式保存到硬盘,联机日志归档的前提条件是数据库要处于归档模式。当数据库处于 archivelog 模式并进行日志切换时,后台进程 arch 会将联机重做日志的内容保存到归档日志中,当数据库出现介质故障时,使用数据文件备份、归档日志和联机重做日志可以完全恢复数据库到正常状态。
oracle 数据库设置为归档模式之后,如果归档空间写满,数据库的 redo 文件不能归档,会出现数据库挂起的问题,导致 数据库无法使用。
2、查看数据库是否为归档模式
sql> archive log list;database log mode archive modeautomatic archival enabledarchive destination /app/archiveoldest online log sequence 30next log sequence to archive 34current log sequence 34sql> select log_mode from v$database;log_mode------------------------------------archivelog
3、打开或关闭归档模式
如果需要打开或关闭归档模式,在数据库处于 mount 状态时使用如下命令:
3.1 打开归档模式
alter database archivelog;
3.2 关闭归档模式
alter database noarchivelog;
4、配置归档的位置
当数据库处于归档模式时,进行日志切换时后台进程将自动生成归档日志。
4.1 查看归档进程数
初始化参数 log_archive_max_processes 用于指定最大归档进程个数。通过改变该初始化参数的取值,可以动态地增加或减少归档进程的个数。
sql> show parameter log_archive_max_processes; name type value ------------------------------------ ----------- ------------------------------ log_archive_max_processes integer 4
4.2 配置归档的位置
可以使用 log_archive_dest_n 配置多个归档位置:该参数最多可以指定 10 个归档位置。格式如下:
alter system set log_archive_dest_1 = 'location = 路径1'; alter system set log_archive_dest_2 = 'location = 路径2'; .....
4.2.1 查看归档文件
sql> select sequence#, name from v$archived_log; sequence# name ---------- -------------------------------------------------------------------------------- 34 /app/archive/orcl_62725153_0000000034_1_1125947150.dbf
可知归档的文件位置 /app/archive/
4.2.2 修改归档日志的位置为:/home/oracle/archivelog
sql> alter system set log_archive_dest_1 = 'location=/app/archive' scope = both sid='*'; sql> archive log list; sql> alter system switch logfile; sql> select sequence#, name from v$archived_log; sql> select sequence#, name from v$archived_log; sequence# name ---------- -------------------------------------------------------------------------------- 34 /app/archive/orcl_62725153_0000000034_1_1125947150.dbf 35 /app/archive/orcl_62725153_0000000035_1_1125947150.dbf
5、配置归档日志文件的名称格式
初始化参数 log_archive_format 用于指定归档日志文件的名称格式。设置该初始化参数时,可以指定以下匹配符:
(1)%s:日志序列号;
(2)%s:日志序列号(带有前导 0);
(3)%t:线程编号;
(4)%t:线程编号(带有前导 0);
(5)%a:活动 id 号;
(6)%d:数据库 id 号;
(7)%r:resetlogs的id值。
归档日志的文件名称格式设置如下:
sql> alter system set log_archive_format = 'orcl_%d_%s_%t_%r.dbf' scope = spfile sid='*';
重启数据库使设置生效
sql> shutdown immediate sql> startup
查看参数 log_archive_format 的值:
sql> show parameter log_archive_format name type value ------------------------------------ ----------- ------------------------------ log_archive_format string orcl_%d_%s_%t_%r.dbf
查看归档日志:
sql> select sequence#, name from v$archived_log;
6、删除归档日志
6.1 手工删除归档日志文件
[oracle@node1 archive]$ cd /app/archive/ [oracle@node1 archive]$ ll -r 总用量 4516 -rw-r----- 1 oracle oinstall 10752 2月 2 10:54 orcl_62725153_0000000036_1_1125947150.dbf -rw-r----- 1 oracle oinstall 54784 2月 2 10:51 orcl_62725153_0000000035_1_1125947150.dbf -rw-r----- 1 oracle oinstall 4551680 2月 2 10:46 orcl_62725153_0000000034_1_1125947150.dbf [oracle@node1 archive]$ rm -rf orcl_62725153_0000000034_1_1125947150.dbf [oracle@node1 archive]$ ll 总用量 68 -rw-r----- 1 oracle oinstall 54784 2月 2 10:51 orcl_62725153_0000000035_1_1125947150.dbf -rw-r----- 1 oracle oinstall 10752 2月 2 10:54 orcl_62725153_0000000036_1_1125947150.dbf
查看归档日志:
sql> select sequence#, name from v$archived_log; sequence# name ---------- -------------------------------------------------------------------------------- 34 /app/archive/orcl_62725153_0000000034_1_1125947150.dbf 35 /app/archive/orcl_62725153_0000000035_1_1125947150.dbf 36 /app/archive/orcl_62725153_0000000036_1_1125947150.dbf
虽然物理文件已经删除,但是归档日志文件的信息还在。
6.2 用 rman 删除数据库记录的归档列表信息
[oracle@node1 ~]$ rman target / rman> list archivelog all; list of archived log copies for database with db_unique_name orcl ===================================================================== key thrd seq s low time ------- ---- ------- - --------- 36 1 34 x 02-feb-23 name: /app/archive/orcl_62725153_0000000034_1_1125947150.dbf 37 1 35 a 02-feb-23 name: /app/archive/orcl_62725153_0000000035_1_1125947150.dbf 38 1 36 a 02-feb-23 name: /app/archive/orcl_62725153_0000000036_1_1125947150.dbf rman> crosscheck archivelog all; released channel: ora_disk_1 allocated channel: ora_disk_1 channel ora_disk_1: sid=1996 device type=disk validation failed for archived log archived log file name=/app/archive/orcl_62725153_0000000034_1_1125947150.dbf recid=36 stamp=1127731566 validation succeeded for archived log archived log file name=/app/archive/orcl_62725153_0000000035_1_1125947150.dbf recid=37 stamp=1127731881 validation succeeded for archived log archived log file name=/app/archive/orcl_62725153_0000000036_1_1125947150.dbf recid=38 stamp=1127732067 crosschecked 3 objects rman> delete expired archivelog all; released channel: ora_disk_1 allocated channel: ora_disk_1 channel ora_disk_1: sid=1996 device type=disk list of archived log copies for database with db_unique_name orcl ===================================================================== key thrd seq s low time ------- ---- ------- - --------- 36 1 34 x 02-feb-23 name: /app/archive/orcl_62725153_0000000034_1_1125947150.dbf do you really want to delete the above objects (enter yes or no)? yes deleted archived log archived log file name=/app/archive/orcl_62725153_0000000034_1_1125947150.dbf recid=36 stamp=1127731566 deleted 1 expired objects rman> select sequence#, name from v$archived_log;select sequence#, name from v$archived_log; sequence# name ---------- -------------------------------------------------------------------------------- 34 35 /app/archive/orcl_62725153_0000000035_1_1125947150.dbf 36 /app/archive/orcl_62725153_0000000036_1_1125947150.dbf
6.3 清除 v$archived_log 视图中的过期信息
使用 rman 命令删除归档后,v$archived_log 视图中的 name 列为空,但其他列的信息仍然存在。出现这种现象的原因是因为使用 rman 命令在删除归档日志的时候不能够清除控制文件中的内容。
6.3.1 清除控制文件中关于 v$archived_log 的信息
sql> execute sys.dbms_backup_restore.resetcfilesection(11); pl/sql procedure successfully completed.
6.3.2 查询发现 v$archived_log 视图中的信息全部被清除了
sql> select sequence#, name from v$archived_log; sequence# name ---------- --------------------------------------------------------------------------------
6.3.3 将未过期的归档文件信息重新注册到控制文件中
rman> catalog start with '/app/archive/'; using target database control file instead of recovery catalog searching for all files that match the pattern /app/archive/ list of files unknown to the database ===================================== file name: /app/archive/orcl_62725153_0000000035_1_1125947150.dbf file name: /app/archive/orcl_62725153_0000000036_1_1125947150.dbf do you really want to catalog the above files (enter yes or no)? yes cataloging files... cataloging done list of cataloged files ======================= file name: /app/archive/orcl_62725153_0000000035_1_1125947150.dbf file name: /app/archive/orcl_62725153_0000000036_1_1125947150.dbf rman> select sequence#, name from v$archived_log; sequence# name ---------- -------------------------------------------------------------------------------- 35 /app/archive/orcl_62725153_0000000035_1_1125947150.dbf 36 /app/archive/orcl_62725153_0000000036_1_1125947150.dbf
到此这篇关于oracle归档日志文件(查看、配置、删除)的文章就介绍到这了,更多相关oracle归档日志文件内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论