點擊上方「藍字」關注我css
運維之美linux
導讀:oracle的運維人員相信都據說過歸檔日誌,oracle能夠將聯機文件保存在數據庫服務器的不一樣位置,將聯機日誌轉換爲歸檔日誌的過程就是歸檔,當數據庫發生故障時,咱們能夠根據物理備份和歸檔日誌恢復數據庫。若是業務中若是用到ogg,也是必須開啓歸檔的,ogg鏈路將的數據同步就是經過抽取源庫的歸檔日誌,經過進程將的trail隊列文件傳送目標庫轉換爲sql實現數據同步。
sql
01typescript
—shell
開啓oracle歸檔數據庫
查看數據庫歸檔模式bash
[oracle@localhost ~]$ export ORACLE_SID=oracle123[oracle@localhost ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on Fri May 22 20:31:18 2020
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> archive log listDatabase log mode No Archive ModeAutomatic archival DisabledArchive destination USE_DB_RECOVERY_FILE_DESTOldest online log sequence 994Current log sequence
須要關閉數據庫,修改成歸檔模式服務器
SQL> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.
startup mount; #鏈接控制文件微信
SQL> startup mount;ORACLE instance started.
Total System Global Area 1603411968 bytesFixed Size 2213776 bytesVariable Size 1040189552 bytesDatabase Buffers 553648128 bytesRedo Buffers 7360512 bytesDatabase mounted.
設置實例爲歸檔模式
oracle
alter database archivelog;Database altered.
打開數據庫
SQL> alter database open;
Database altered.
再次檢查歸檔模式
SQL> alter database open;
Database altered.
SQL> archive log list;Database log mode Archive ModeAutomatic archival EnabledArchive destination USE_DB_RECOVERY_FILE_DESTOldest online log sequence 994Next log sequence to archive 996Current log sequence 996
02
—
定時清理歸檔
優化一:增長歸檔空間大小
SQL> show parameter db_recovery;
NAME TYPE VALUE------------------------------------ ----------- ------------------------------db_recovery_file_dest string /u01/app/oracle/flash_recovery _areadb_recovery_file_dest_size big integer 3882M
SQL> alter system set db_recovery_file_dest_size=5G;
System altered.
SQL> show parameter db_recovery;
NAME TYPE VALUE------------------------------------ ----------- ------------------------------db_recovery_file_dest string /u01/app/oracle/flash_recovery _areadb_recovery_file_dest_size big integer 5G
優化二:清理歸檔空間
方法一:手動清理
按照以下步驟清理
export ORACLE_SID=oracle123而後進入rmanoracle@linux:rman target/ 下面檢查全部的歸檔日誌RMN>crosscheck archivelog all;刪除7天以前的歸檔日誌RMN>DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';刪除從7天前到如今的所有日誌RMN>DELETE ARCHIVELOG FROM TIME 'SYSDATE-5';
方法二:crontab定時任務清理
操做步驟:
vi delete_archivelog.sh
-
2.腳本內容能夠參照以下編寫
腳本1:適合服務器上安裝多實例數據庫,能夠循環刪除
#!/bin/bashfor I in {testcs1,testcs4,testkf01}
do export ORACLE_SID=$Irman target/ <<EOF delete archivelog until time 'sysdate-4';yesEOFdone
#!/bin/bashDATE=`date +%Y%m%d%H`export ORACLE_SID=testsource /home/oracle/.bash_profile$ORACLE_HOME/bin/rman log=/u01/log/rman_${DATE}.log <<EOFconnect target/run{crosscheck archivelog all;delete noprompt expired archivelog all;delete noprompt archivelog all completed before 'sysdate-1'; }exit;EOFexit
[oracle@localhost ORACLE]$ chmod +x delete_archivelog.sh
在oracle用戶下(root下需添加su - oracle -c),添加crontab
下面示例爲天天凌晨1點開始執行定時清理腳本
[oracle@localhost oracle]$ crontab -e00 1 * * * sh /u01/app/oracle/delete_archivelog.sh>/dev/null 2>&1
[oracle@localhost oracle]$ crontab -l00 1 * * * sh /u01/app/oracle/delete_archivelog.sh >/dev/null 2>&1
end
本文分享自微信公衆號 - 運維之美(ywzm8976)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。