📢📢📢📣📣📣
哈喽!大家好,我是【IT邦德】,江湖人称jeames007,10余年DBA及大数据工作经验
一位上进心十足的【大数据领域博主】!😜😜😜
中国DBA联盟(ACDU)成员,目前服务于工业互联网
擅长主流Oracle、MySQL、PG、高斯及Greenplum运维开发,备份恢复,安装迁移,性能优化、故障应急处理等。
? 如果有对【数据库】感兴趣的【小可爱】,欢迎关注【IT邦德】💞💞💞
??????感谢各位大可爱小可爱!??????
Oracle 归档日志(Archive Log)是一种用于记录数据库事务日志的技术。它可以将数据库中的更改操作(如插入、更新和删除)记录下来,以便在出现故障时恢复数据。归档日志采用增量方式记录,即每次更改操作后,日志文件会逐步变大.
如果归档的空间满了,就会导致
ORA-00257: archiver error. Connect internal only, until freed.
以下脚本为定时删除7天前的归档日志
[root@mesdb1 ~]# su - oracle
[oracle@mesdb1 ~]$ mkdir -p /home/oracle/script
[oracle@mesdb1 ~]$ mkdir -p /home/oracle/arch/log
vi /home/oracle/script/arch_del.sh
export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
export ORACLE_SID=mesdb1
dt=`date '+%Y%m%d_%H%M'`
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
rman target / log /home/oracle/arch/log/log_arch_$dt.log <<EOF
run{
allocate channel ch1 type;
allocate channel ch2 type;
crosscheck archivelog all;
sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';
delete expired archivelog all;
delete archivelog until time 'sysdate-7' ;
release channel ch1;
release channel ch2;
}
EOF
0 1 * * * sh /home/oracle/script/arch_del.sh
在oracle 10g时候,只有文本格式的listener.log; 在11.2版本时,由于ADR特性出现了xml/log两种格式的监听日志,xml格式的日志会达到一定大小后自动分片,形成log_1.xml 这种数字序号的文件;log格式的日志会达到一定大小后自动分片,形成log_1.log 这种数字序号的文件.
Oracle11g的新特性自动诊断库(ADR)默认会启用,
监听日志默认以xml方式存放,如果空间占用太大,你可以关闭
建议调整监听参数文件DIAG_ADR_ENABLED_listener = OFF ,
然后reload监听,监听就不会存放为XML文件格式,而是使用10g老的方式。
同时建议在SQLNET.ORA文件中设置参数 DIAG_ADR_ENABLED = OFF
来屏蔽ADR向ALERT写入错误信息(如ORA-609),操作如下:
在listener.ora里面加入如下行:
DIAG_ADR_ENABLED_ LISTENER = OFF 其中LISTENER为监听名
sqlnet.ora加入如下行:
DIAG_ADR_ENABLED = OFF
重启监听:
lsnrctl reload
监听进程的查询,RAC一般使用ASM的监听
ps -ef |grep tnslsnr
grid 12386 1 0 2023 ? 05:00:31 /u01/app/19.0.0/grid/bin/tnslsnr LISTENER -no_crs_notify -inherit
grid 12460 1 0 2023 ? 00:47:24 /u01/app/19.0.0/grid/bin/tnslsnr ASMNET1LSNR_ASM -no_crs_notify -inherit
oracle 70467 68189 0 08:40 pts/2 00:00:00 grep --color=auto tnslsnr
监听的位置在如下位置
cd $ORACLE_BASE/diag/tnslsnr/{hostname}
asmnet1lsnr_asm
listener
listener_scan1
crontable -l
0 23 * * * /home/oracle/scirpt/listener_clear.sh > /dev/null 2>&1;
#!/bin/sh
#listener
find /u01/app/grid/diag/tnslsnr/rac1/listener/alert -mtime +7 -name “log_.xml" | xargs rm -rf ;
find /u01/app/grid/diag/tnslsnr/rac1/listener/trace -mtime +7 -name "listener_.llog” | xargs rm -rf ;
#asmnet1lsnr_asm
find /u01/app/grid/diag/tnslsnr/rac1/asmnet1lsnr_asm/alert -mtime +7 -name “log_.xml" | xargs rm -rf ;
find /u01/app/grid/diag/tnslsnr/rac1/asmnet1lsnr_asm/trace -mtime +7 -name "asmnet1lsnr_asm_.log” | xargs rm -rf ;
Oracle跟踪文件分为三种类型
1)后台报警日志文件
2)DBWR、LGWR、SMON等后台进程创建的后台跟踪文件
3)连接到Oracle的用户进程(Server Processes)生成的用户跟踪文件
这里涉及两个参数:
LONGP_POLICY:默认保留365天的事件与警告。
SHORTP_POLICY:默认保留30天的trace文件或core dump file
[oracle@rac1 ]$ adrci
adrci> show home
ADR Homes:
diag/kfod/mes-all-db1/kfod
diag/rdbms/mesdb/mesdb1
diag/clients/user_oracle/host_314373652_110
adrci> set home diag/rdbms/mesdb/mesdb1
删除一天前的alert log
adrci> PURGE -age 1440 -type ALERT
删除一天前的trace 文件
adrci> PURGE -age 1440 -type TRACE
adrci> show control ##单位是小时
更改 SHORTP_POLICY即可实现保留的日期
adrci> set control (SHORTP_POLICY=360)
清理trace文件(单位分钟,前一天之前的)
adrci> purge -age 1440 -type TRACE
默认情况下当天的trace文件是不能被清理的!
SYS@mesdb1> SELECT * FROM V$DIAG_INFO WHERE NAME = ‘Diag Trace’;
#!/bin/bash
databaseName='PROD'
baseDir='/usr01/backup/'
backupDate=`date "+%Y-%m-%d"`
if [ `whoami` != 'oracle' ];then
echo 必须使用 oracle 用户进行备份,备份停止
exit
fi
if [ ! -e $baseDir ]
then
echo 备份根 $baseDir 目录不存在,备份停止
exit
fi
backupDir=$baseDir$backupDate
if [ ! -e $backupDir ];then
mkdir -p $backupDir/arc
mkdir -p $backupDir/data
mkdir -p $backupDir/ctl
else
echo 备份目录 $backupDir 已存在,备份停止
exit
fi
logFile=$backupDir/backup_log_$backupDate
echo `date` 备份开始
# 要添加 catalog
rman target / log=${logFile} <<EOF
run {
allocate channel c1 device type disk ;
allocate channel c2 device type disk ;
CONFIGURE BACKUP OPTIMIZATION ON;
backup as compressed backupset
incremental level 0
tag '${databaseName}_{backupDate}'
filesperset 8
format '${backupDir}/data/${databaseName}_data_%U.bak'
database
include current controlfile ;
sql 'alter system archive log current';
backup current controlfile format '${backupDir}/ctl/${databaseName}_ctl_%U.bak';
backup as compressed backupset
skip inaccessible
filesperset 32
format '${backupDir}/arc/${databaseName}_arc_%U.bak'
archivelog all;
delete noprompt archivelog until time = 'sysdate-3';
release channel c1;
release channel c2;
}
EOF
echo `date` 备份完成 >> $logFile
[oracle@mes-all-db1 ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Sat Jan 6 10:11:34 2024
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: MESDB (DBID=3146269603)
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name MESDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/19.0.0/dbhome_1/dbs/snapcf_mesdb1.f'; # default
--备份策略调整,备份保留7天
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;