首页 > 数据库 >Oracle的归档操作

Oracle的归档操作

时间:2024-09-25 16:55:08浏览次数:9  
标签:archived log SQL 2024 oracle archivelog 归档 Oracle 操作

1、查询数据库归档模式

两种方式:查询v$database和命令查看。

NOARCHIVELOG和No Archive Mode都是未开启归档

SQL> select name,log_mode from v$database;

NAME      LOG_MODE
--------- ------------
ORCL      NOARCHIVELOG


SQL> archive log list;

Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /oracle/app/oracle/product/19.3.0/db_1/dbs/arch
Oldest online log sequence     28
Current log sequence           30

2、开启或关闭归档模式

开启和关闭归档模式都需要在mount模式进行,即需要把数据库重启到mount模式下。

SQL> startup mount
ORACLE instance started.

Total System Global Area  830469464 bytes
Fixed Size        8901976 bytes
Variable Size      666894336 bytes
Database Buffers    150994944 bytes
Redo Buffers        3678208 bytes
Database mounted.

SQL> archive log list;
Database log mode         No Archive Mode
Automatic archival         Disabled
Archive destination         /oracle/app/oracle/product/19.3.0/db_1/dbs/arch
Oldest online log sequence     28
Current log sequence         30

– 开启归档模式

SQL> alter database archivelog;
Database altered.
SQL> archive log list;
Database log mode         Archive Mode
Automatic archival         Enabled
Archive destination         /oracle/app/oracle/product/19.3.0/db_1/dbs/arch
Oldest online log sequence     28
Next log sequence to archive   30
Current log sequence         30

– 关闭归档模式

SQL> alter database noarchivelog;
Database altered.
SQL> archive log list;
Database log mode         No Archive Mode
Automatic archival         Disabled
Archive destination         /oracle/app/oracle/product/19.3.0/db_1/dbs/arch
Oldest online log sequence     28
Current log sequence         30

3、修改归档日志文件默认设置

归档日志的默认位置是$ORACLE_HOME/dbs/arch目录,一般需要重新指定位置,例如:/archivelog

SQL> alter system set log_archive_dest_1='location=/archivelog';

System altered.

SQL> archive log list;
Database log mode         Archive Mode
Automatic archival         Enabled
Archive destination         /archivelog
Oldest online log sequence     28
Next log sequence to archive   30
Current log sequence         30

4、修改归档日志文件格式

默认的归档日志文件格式后缀名为dbf,而oracle的表空间数据文件名称后缀也是dbf,为了更好的区分两者,我们自定义下归档的归档日志文件的格式,就以arch为后缀吧。由于log_archive_format参数是静态的,需要重启才能生效。

缺省值:%t_%s_%r.dbf

参数值说明:

%s: 日志序列号
%S: 日志序列号(带有前导)
%t: 重做线程编号.
%T: 重做线程编号(带有前导)
%a: 活动ID号
%d: 数据库ID号
%r: RESETLOGS的ID值.

SQL> show parameter log_archive_format;

NAME             TYPE   VALUE
------------------------------------ ----------- ------------------
log_archive_format         string   %t_%s_%r.dbf

SQL> alter system set log_archive_format='%t_%s_%r.arch' scope=spfile;

System altered.


SQL> show parameter log_archive_format;

NAME             TYPE   VALUE
------------------------------------ ----------- ---------
log_archive_format         string   %t_%s_%r.dbf

– 重启数据库,由于我们一直是在mount状态下操作,
– 所以关闭数据库是提示数据库没有open是正常的。

SQL> shutdown immediate;
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  830469464 bytes
Fixed Size        8901976 bytes
Variable Size      666894336 bytes
Database Buffers    150994944 bytes
Redo Buffers        3678208 bytes
Database mounted.
Database opened.

– 查看归档模式

SQL> archive log list;
Database log mode         Archive Mode
Automatic archival         Enabled
Archive destination         /archivelog
Oldest online log sequence     28
Next log sequence to archive   30
Current log sequence         30

– 查看归档日志文件设置,已经显示为自定义设置的后缀文件名了

SQL> show parameter log_archive_format;

NAME             TYPE   VALUE
------------------------------------ ----------- -----------
log_archive_format         string   %t_%s_%r.arch

5、切换日志查看生成归档信息

数据库中查看

SQL> alter system switch logfile;

System altered.

SQL> select recid, name, first_time from v$archived_log;

使用rman查看

[oracle@dome-[orcl]-/home/oracle]$ rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Sat Jun 4 05:42:25 2024
Version 19.14.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1627730222)
RMAN> crosscheck archivelog all;

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=460 device type=DISK
validation succeeded for archived log
archived log file name=/archivelog/1_30_1099949486.arch RECID=1 STAMP=1106458725
Crosschecked 1 objects
RMAN> crosscheck archivelog all;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=460 device type=DISK
validation succeeded for archived log
archived log file name=/archivelog/1_30_1099949486.arch RECID=1 STAMP=1106458725
validation succeeded for archived log
archived log file name=/archivelog/1_31_1099949486.arch RECID=2 STAMP=1106458993
Crosschecked 2 objects

6、归档日志的删除

crosscheck archivelog all:检查log_archive_dest参数指定位置的文件,如果有系统rm删除的归档日志,会有验证失败提示validation failed for archived log,结合delete noprompt expired archivelog all;语句删除过期归档日志。

RMAN> delete noprompt  archivelog all;

released channel: ORA_DISK_1
released channel: ORA_DISK_2
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=36 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=268 device type=DISK
List of Archived Log Copies for database with db_unique_name CDB1
=====================================================================

Key     Thrd Seq     S Low Time
------- ---- ------- - -------------------
1       1    12      A 2024-08-16 08:32:10
        Name: /u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_21/o1_mf_1_12_mdbz2690_.arc

2       1    13      A 2024-08-21 13:33:58
        Name: /u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_21/o1_mf_1_13_mdc32yw7_.arc

3       1    14      A 2024-08-21 14:42:38
        Name: /u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_23/o1_mf_1_14_mdjdwvp8_.arc

4       1    15      A 2024-08-23 15:00:43
        Name: /u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_23/o1_mf_1_15_mdjkg7dt_.arc

5       1    16      A 2024-08-23 16:18:15
        Name: /u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_26/o1_mf_1_16_mdr6gy8c_.arc

6       1    17      A 2024-08-26 13:59:58
        Name: /u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_09_02/o1_mf_1_17_mfbmx6ng_.arc

deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_21/o1_mf_1_12_mdbz2690_.arc RECID=1 STAMP=1177594439
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_21/o1_mf_1_13_mdc32yw7_.arc RECID=2 STAMP=1177598559
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_23/o1_mf_1_14_mdjdwvp8_.arc RECID=3 STAMP=1177772444
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_23/o1_mf_1_15_mdjkg7dt_.arc RECID=4 STAMP=1177777095
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_08_26/o1_mf_1_16_mdr6gy8c_.arc RECID=5 STAMP=1178027999
Deleted 3 objects

deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/CDB1/archivelog/2024_09_02/o1_mf_1_17_mfbmx6ng_.arc RECID=6 STAMP=1178631593
Deleted 3 objects

具体用法和个别参数说明

force:强制删除日志
noprompt:忽略提示

验证日志

crosscheck archivelog all;

列出过期日志

list expired archivelog all; 

删除所有过期日志

delete noprompt expired archivelog all;

删除所有归档日志

delete noprompt  archivelog all;

按日期区间删除

delete noprompt archivelog until time "to_date('yyyy-mm-dd','YYYY-MM-DD')"; 

按时间区间删除

delete noprompt archivelog until time "to_date('2022-06-03 00:00:00','2022-06-03 03:00:00')";

删除7天前的日志

delete noprompt archivelog all completed before 'sysdate-7';

删除1小时以前的日志

delete noprompt archivelog all completed before 'sysdate-1/24'; 

删除30分钟以前的日志

delete noprompt archivelog all completed before 'sysdate-1/48';

7、脚本和定时任务删除

DG环境下的归档日志删除脚本,主库保留3天,备库保留10个

source /home/oracle/.bash_profile 
export logfile=/home/oracle/rman_del_arch_${ORACLE_SID}.log

delPriArch(){
echo "begin deleting primary archivelog"
rman target / log=${logfile} append <<EOF
delete noprompt archivelog until time 'SYSDATE-3';
exit;
EOF
}

getsql(){
sqlplus -S "/as sysdba" <<EOF
set head off
set feedback off
set time off
set timing off
set echo off
select 'delete noprompt archivelog from sequence 0 until sequence '||max(sequence# - 10)|| ' thread ' || thread# ||';'
  from v\$archived_log where applied='YES' group by thread#;
exit
EOF
}


delStdArch(){
sql=$(getsql)
echo "begin deleting standby archivelog"
rman target / log=${logfile} append <<EOF
$sql
exit;
EOF
}


getrole() {
sqlplus -S "/as sysdba" <<EOF
set head off
set feedback off
set echo off
set time off
set timing off
select database_role from v\$database;
exit
EOF
}

role=$(getrole)
role=`echo ${role} |sed 's/ //g'`
echo $role
if [ "${role}" = "PRIMARY" ];then
delPriArch;
elif [ "${role}" = "PHYSICALSTANDBY" ];then
delStdArch;
else 
echo "error, unable to connect to the database, try again later"
fi

配置系统定时任务

0 0,2,4,6,8,10,12,14,16,18,20,22 * * * sh /home/oracle/rman_del_arch.sh

标签:archived,log,SQL,2024,oracle,archivelog,归档,Oracle,操作
From: https://blog.csdn.net/2301_76664379/article/details/142521744

相关文章

  • Linux 基础入门操作 第十章 多线程实现
    10线程介绍线程是进程的一条执行路径。每个线程共享其所附属的进程的所有的资源,包括打开的文件、页表(因此也就共享整个用户态地址空间)、信号标识及动态分配的内存等等。线程和进程的关系是:线程是属于进程的,线程运行在进程空间内,同一进程所产生的线程共享同一物理内存空间......
  • node/expressjs 连接与操作 MongoDB
    MongoDB 的安装、配置、启动、常见指令等,详见上一节“mongoDB简介” 以下将讲述 node/expressjs 与 mongoDB 的交互——连接与操作数据库 mongoDB注释:以下示例是采用express官网的生成器初始化项目的。数据库 mongoDB的操作运用的是mongoose插件, mong......
  • linux semaphore信号量操作
    信号量(semaphore)是操作系统中最常见的同步原语之一。spinlock是实现忙等待锁,而信号量则允许进程进入睡眠状态。下面将分析信号量的获取是释放操作。1、数据结构数据结构定义和初始化如下:include/linux/semaphore.h/*Pleasedon'taccessanymembersofthisstruc......
  • Oracle 19c OCP 认证考试 082 题库(第26题)- 2024年修正版
    【优技教育】Oracle19cOCP082题库(Q26题)-2024年修正版考试科目:1Z0-082考试题量:90通过分数:60%考试时间:150min本文为(CUUG原创)整理并解析,转发请注明出处,禁止抄袭及未经注明出处的转载。原文地址:http://www.cuug.com/index.php?s=/home/article/detail/id/3412.html第......
  • 微服务2:微服务远程操作Redis
    目录1、本文目标2、Redis简介3、Redis安装及配置4、搭建Redis的客户端微服务5、注册至Eureka服务注册中心6、Redis客户端微服务测试1、本文目标2、Redis简介Redis是一个开源的(BSD许可)、内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件。Redis支......
  • Linux中MySQL配置主主复制操作
    一、GTIDGTID(GlobalTransactionIdentifier)是MySQL的一种用于标识分布式环境中事务的全局唯一标识符。它在MySQL的主从复制场景中尤为重要,尤其是在使用MariaDB或MySQL5.6及更高版本的环境中。GTID由两部分组成:服务器ID(标识执行该事务的服务器)和事务序号(表示在该服务器上执......
  • 统信服务器操作系统a版e版【dde桌面限制登录次数】介绍
    dde桌面登录规则、tty限制登录次数、ssh限制登录次数、ssh限制地点登录、本地限制终端登录、时间限制登录等内容文章目录功能概述功能介绍1.查看dde桌面登录规则2.tty限制登录次数3.ssh限制登录次数4.ssh限制地点登录5.本地限制终端登录6.时间限制登录功能概述......
  • Mybatis基础操作
    一、设置日志mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl在Mybatis当中我们可以借助⽇志,查看到sql语句的执⾏、执⾏传递的参数以及执⾏结果二、XML映射SQL在MyBatis中,你可以选择两种主要方式来编写SQL映射:使用XML映射文件或者......
  • 如何修复英雄联盟常见dll错误,操作系统提示缺少英雄联盟dll文件的有效解决办法
    在众多热门游戏中,《英雄联盟》以其精彩的竞技性和丰富的玩法深受玩家喜爱。然而,当玩家准备在召唤师峡谷大显身手时,却可能遭遇因操作系统中缺少DLL文件而导致的游戏无法启动等问题,这无疑令人十分困扰。别担心,下面就为大家介绍一些有效解决操作系统中缺少英雄联盟DLL文件的办......
  • GZY.Quartz.MUI(基于Quartz的UI可视化操作组件) 2.7.0发布 新增各项优化与BUG修复
    GZY.Quartz.MUI(基于Quartz的UI可视化操作组件)2.7.0发布新增各项优化与BUG修复 前言时隔大半年,终于抽出空来可以更新这个组件了(边缘化了,大概要被裁员了)2.7.0终于发布了~更新内容:1.添加API类任务的超时时间,可以通过全局配置也可以单个任务设置2.设置定时任务日......