一、 查看是否开启归档模式
[oracle@db ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Wed Oct 17 07:24:38 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> archive log list #查看是否开启,下文显示未开启
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 15
Current log sequence 17
SQL>
二、开启归档模式
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>
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 15
Next log sequence to archive 17
Current log sequence 17
SQL>
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 /u01/app/oracle/fast_recovery_area
db_recovery_file_dest_size big integer 2G
默认情况下,归档日志会存放到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 location=/u01/app/oracle/archivelog
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
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_18 string
log_archive_dest_19 string
log_archive_dest_2 string location=/home/oracle/archive_log
# 归档日志格式
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;
SQL> select name from v$archived_log;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/archivelog1_17_989497127.dbf
/home/oracle/archive_log1_17_989497127.dbf
####################################################################################
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
REDO LOG 0
ARCHIVED LOG 0
BACKUP PIECE 0
IMAGE COPY 0
FLASHBACK LOG 0
FOREIGN ARCHIVED LOG 0
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;就行了
本文转自 手把手 :https://www.shoubashou.com/db/oracle/102.html