一、 查看是否开启归档模式
SQL> archive log list #查看是否开启,下文显示未开启 Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 8 Current log sequence 10
二、开启归档模式
SQL> shutdown immediate #关闭实例 Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount #启动到mount ORACLE instance started. Total System Global Area 1286066176 bytes Fixed Size 2228024 bytes Variable Size 352321736 bytes Database Buffers 922746880 bytes Redo Buffers 8769536 bytes Database mounted. SQL> alter database archivelog; #开启归档模式 Database altered. SQL> archive log list; #再次查看是否开启归档,下文显示已归档 Database log mode Archive Mode Automatic archival Enabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 8 Next log sequence to archive 10 Current log sequence 10 SQL> alter database open; #打开数据库 Database altered. SQL> show parameter db_recovery # 查看参数db_recovery_file_dest归档日志目录(默认闪回恢复区)、db_recovery_file_dest_size大小 NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_recovery_file_dest string /data/oracle/app/oracle/fast_recovery_area db_recovery_file_dest_size big integer 4182M
默认情况下,归档日志会存放到USE_DB_RECOVERY_FILE_DEST(闪回恢复区flash_recovery_area)内,如果闪回恢复区已满,归档日志就有可能无法继续归档,通常的解决方法是增大闪回恢复区,可以用以下SQL实现:
SQL> alter system set db_recovery_file_dest_size=3G;
Oracle里面有个叫做spfile的东西,就是动态参数文件,里面设置了Oracle的各种参数。所谓的动态,就是说你可以在不关闭数据库的情况下,更改数据库参数,记录在spfile里面。
语法:alter system set 参数=值 scope=spfile;
注意:ALTER SYSTEM 中 SCOPE=SPFILE/MEMORY/BOTH 的区别:
SCOPE = SPFILE : 此更改写入初始化参数文件,更改将在下次启动时生效。
SCOPE = MEMORY : 只在内存上修改,立即生效,但重启后将不再生效,因为并没有写入到初始化参数文件。只适用于动态参数,静态参数则不允许。
SCOPE = BOTH : 默认选项,既写入到初始化参数文件,也在内存上修改,立即生效。同样也只适用于动态参数,静态参数则不允许
闪回恢复区ORACLE会自动管理,如果空间不足就会清理掉没用的数据。另外,还可以修改归档日志的路径,将归档日志放到其他不受限制的路径下来解决这个问题,即通过下面的SQL来修改归档日志的存放路径:
SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog'; SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/archivelog Oldest online log sequence 15 Next log sequence to archive 17 Current log sequence 17
从10g开始,可以设置多个归档路径,生成多份一样的日志:
SQL> alter system set log_archive_dest_2 = 'location=/home/oracle/archive_log'; SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /home/oracle/archive_log Oldest online log sequence 15 Next log sequence to archive 17 Current log sequence 17
# 查看归档日志位置
SQL> show parameter log_archive_dest; # 查看归档日志位置 NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_dest string log_archive_dest_1 string log_archive_dest_10 string log_archive_dest_11 string log_archive_dest_12 string log_archive_dest_13 string log_archive_dest_14 string log_archive_dest_15 string log_archive_dest_16 string log_archive_dest_17 string log_archive_dest_18 string NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_dest_19 string log_archive_dest_2 string log_archive_dest_20 string log_archive_dest_21 string log_archive_dest_22 string log_archive_dest_23 string log_archive_dest_24 string log_archive_dest_25 string log_archive_dest_26 string log_archive_dest_27 string log_archive_dest_28 string NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_dest_29 string log_archive_dest_3 string log_archive_dest_30 string log_archive_dest_31 string log_archive_dest_4 string log_archive_dest_5 string log_archive_dest_6 string log_archive_dest_7 string log_archive_dest_8 string log_archive_dest_9 string log_archive_dest_state_1 string enable NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_dest_state_10 string enable log_archive_dest_state_11 string enable log_archive_dest_state_12 string enable log_archive_dest_state_13 string enable log_archive_dest_state_14 string enable log_archive_dest_state_15 string enable log_archive_dest_state_16 string enable log_archive_dest_state_17 string enable log_archive_dest_state_18 string enable log_archive_dest_state_19 string enable log_archive_dest_state_2 string enable NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_dest_state_20 string enable log_archive_dest_state_21 string enable log_archive_dest_state_22 string enable log_archive_dest_state_23 string enable log_archive_dest_state_24 string enable log_archive_dest_state_25 string enable log_archive_dest_state_26 string enable log_archive_dest_state_27 string enable log_archive_dest_state_28 string enable log_archive_dest_state_29 string enable log_archive_dest_state_3 string enable NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_dest_state_30 string enable log_archive_dest_state_31 string enable log_archive_dest_state_4 string enable log_archive_dest_state_5 string enable log_archive_dest_state_6 string enable log_archive_dest_state_7 string enable log_archive_dest_state_8 string enable log_archive_dest_state_9 string enable
# 归档日志格式
SQL> show parameter log_archive_format NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_format string %t_%s_%r.dbf
SQL> alter system set log_archive_format ="archive_%t_%s_%r.log" scope=spfile; System altered.
# 归档日志进程数
SQL> show parameter log_archive_max_process NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_max_processes integer 4 SQL> alter system set log_archive_max_processes = 5; System altered. SQL> show parameter log_archive_max_process NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_max_processes integer 5
# 归档当前重做日志
SQL> alter system archive log current; System altered. SQL> select name from v$archived_log; NAME -------------------------------------------------------------------------------- /data/oracle/app/oracle/fast_recovery_area/ORCL/archivelog/2019_04_04/o1_mf_1_10 _gbc8v3d9_.arc
alter system switch logfile 是强制日志切换,不一定就归档当前的重做日志文件(若自动归档打开,就归档前的重做日志,若自动归档没有打开,就不归档当前重做日志。)
alter system archive log current 是归档当前的重做日志文件,不管自动归档有没有打都归档。
主要的区别在于:
alter system switch logfile 对单实例数据库或RAC中的当前实例执行日志切换;
alter system archive log current 会对数据库中的所有实例执行日志切换。
# 查看闪回恢复区空间使用情况
SQL> set linesize 300 SQL> select * from v$flash_recovery_area_usage; FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE -------------------- ------------------ ------------------------- NUMBER_OF_FILES --------------- CONTROL FILE 0 0 0 REDO LOG 0 0 0 ARCHIVED LOG 1.15 0 1 FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE -------------------- ------------------ ------------------------- NUMBER_OF_FILES --------------- BACKUP PIECE 0 0 0 IMAGE COPY 0 0 0 FLASHBACK LOG 0 0 0 FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE -------------------- ------------------ ------------------------- NUMBER_OF_FILES --------------- FOREIGN ARCHIVED LOG 0 0 0 7 rows selected.
SQL> col name for a50 SQL> select * from v$recovery_file_dest; NAME SPACE_LIMIT SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES -------------------------------------------------- ----------- ---------- ----------------- --------------- /u01/app/oracle/fast_recovery_area 4322230272 0 0
三、修改为非归档模式
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 1286066176 bytes Fixed Size 2228024 bytes Variable Size 352321736 bytes Database Buffers 922746880 bytes Redo Buffers 8769536 bytes Database mounted. SQL> alter database noarchivelog; SQL> alter database open; SQL> archive log list; Database log mode No Archive Mode Automatic archival Disabled Archive destination /home/oracle/archive_log Oldest online log sequence 16 Current log sequence 18
四、归档空间满的处理方法
这里列出两个手动删除归档日志的方法:
4.1、先手动删除物理的归档日志,然后执行下列命令
RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';
说明:SYSDATA-7,表明当前的系统时间7天前,before关键字表示在7天前的归档日志,如果使用了闪回功能,也会删除闪回的数据。同样道理,也可以删除从7天前到现在的全部日志,不过这个命令要考虑清楚,做完这个删除,最好马上进行全备份数据库。DELETE ARCHIVELOG from TIME ‘SYSDATE-7’; 删除从7天前到现在的全部日志,慎用
4.2、UNIX/LINUX下也可以通过FIND找到7天前的归档数据,使用EXEC子操作删除
find /oracle/oraarchive -xdev -mtime +7 -name "*.dbf" -exec rm -f {} ; 或 find /mnt/oradb/archivelog -type f -mtime +1 -exec rm {} ;
然后会在RMAN里留下未管理的归档文件,要在RMAN里执行下面2条命令:
crosscheck archivelog all; delete expired archivelog all;
最后再输入一次crosscheck archivelog all;就行了
crosscheck archivelog all;
您暂时无权查看此隐藏内容!
评论前必须登录!
注册