您好,登錄后才能下訂單哦!
[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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。