
点击上方「蓝字」关注我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源创计划”,欢迎正在阅读的你也加入,一块儿分享。