重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 157|回复: 0
打印 上一主题 下一主题

[Oracle] 切换Oracle归档路径后,如何正常删除原归档路径上的归档文件

[复制链接]
跳转到指定楼层
楼主
发表于 6 天前 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.检查当前Oracle数据库是否开启归档
SQL> select open_mode from v$database;                 ---检查当前数据库是否打开
OPEN_MODE
--------------------
READ WRITE

SQL> archive log list
Database log mode              No Archive Mode         ---Oracle为非归档模式
Automatic archival             Disabled
Archive destination            /u01/app/oracle/oradata
Oldest online log sequence     110
Current log sequence           115
2.启用数据库归档
切换归档模式,需要数据库打开到mount状态,前面查到数据库是READ WRITE,所以需要关闭数据库,启动到mount状态

SQL> shutdown immediate                       ---正常关闭数据库
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

SQL> startup mount                           ---启动数据库到mount状态
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size                  2260088 bytes
Variable Size             910164872 bytes
Database Buffers          150994944 bytes
Redo Buffers                5517312 bytes
Database mounted.

SQL> alter database archivelog;             ---切换数据库为归档模式
Database altered.

SQL> alter database open;                   ---mount状态下打开数据库
Database altered.

[oracle@lsq ~]$ cd /u01/app/oracle/oradata/ --查看归档文件的情况
[oracle@lsq oradata]$ ll
total 85476
-rw-r----- 1 oracle oinstall 87523840 Feb 24  2023 1_102_1124643686.dbf
drwxr-x--- 2 oracle oinstall      275 Dec 28  2022 lsq
3.切换归档路径
由于归档路径标识不够明确或没有标识,不够规范,存在归档被误删的风险,因此需要在/u01/app/oracle/oradata/下创建archivelog目录用于存放归档。

[oracle@lsq oradata]$ mkdir archivelog
[oracle@lsq oradata]$
[oracle@lsq oradata]$ ll
total 85476
-rw-r----- 1 oracle oinstall 87523840 Feb 24  2023 1_102_1124643686.dbf
drwxr-xr-x 2 oracle oinstall        6 Mar 19 14:12 archivelog
drwxr-x--- 2 oracle oinstall      275 Dec 28  2022 lsq
[oracle@lsq oradata]$ cd archivelog/
[oracle@lsq archivelog]$ ll
total 0
[oracle@lsq archivelog]$ pwd
/u01/app/oracle/oradata/archivelog
在数据库中修改归档路径

SQL> show  parameter dest

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest                      string      /u01/app/oracle/admin/lsq/adump
background_dump_dest                 string      /u01/app/oracle/diag/rdbms/lsq/lsq/trace
core_dump_dest                       string      /u01/app/oracle/diag/rdbms/lsq/lsq/cdump
cursor_bind_capture_destination      string      memory+disk
db_create_file_dest                  string
db_create_online_log_dest_1          string
db_create_online_log_dest_2          string
db_create_online_log_dest_3          string
db_create_online_log_dest_4          string
db_create_online_log_dest_5          string
db_recovery_file_dest                string      /u01/app/oracle/fast_recovery_area
db_recovery_file_dest_size           big integer 100G
diagnostic_dest                      string      /u01/app/oracle
log_archive_dest                     string
log_archive_dest_1                   string      location=/u01/app/oracle/oradata        ---注意这条

SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/oradata/archivelog';  ---修改归档路径
System altered.

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/oradata/archivelog                       ---归档路径已经变化     
Oldest online log sequence     110
Next log sequence to archive   115
Current log sequence           115

SQL> alter system switch logfile;                                                       ---手工切换归档日志
System altered.
检查文件系统下的归档日志,发现在/u01/app/oracle/oradata/archivelog目录下已经生成归档日志

[oracle@lsq archivelog]$ ll
total 43652
-rw-r----- 1 oracle oinstall 44699136 Mar 19 14:13 1_115_1124643686.dbf
截止目前的情况是在/u01/app/oracle/oradata目录下有一个1_102_1124643686.dbf,在/u01/app/oracle/oradata/archivelog目录下有1_115_1124643686.dbf。

4.模拟删除日志
[oracle@lsq archivelog]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Mar 19 14:13:53 2025
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: LSQ (DBID=3389915302)

RMAN> delete archivelog all;                                                       ---删除所有的日志
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1154 device type=DISK
List of Archived Log Copies for database with db_unique_name LSQ
=====================================================================
Key     Thrd Seq     S Low Time
------- ---- ------- - ---------
1       1    115     A 14-JUN-23
        Name: /u01/app/oracle/oradata/archivelog/1_115_1124643686.dbf
Do you really want to delete the above objects (enter YES or NO)? yes               ---确认是要删除的日志,输入yes
deleted archived log
archived log file name=/u01/app/oracle/oradata/archivelog/1_115_1124643686.dbf RECID=1 STAMP=1196172826
Deleted 1 objects
发现没有删除/u01/app/oracle/oradata目录下有一个1_102_1124643686.dbf,在生产环境可能造成空间的浪费。

5.规范删除旧归档日志
RMAN> catalog start with '/u01/app/oracle/oradata';                 ---使用rman的catalog找到目录下的文件

searching for all files that match the pattern /u01/app/oracle/oradata
List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/oradata/1_102_1124643686.dbf
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/oradata/1_102_1124643686.dbf

RMAN> delete archivelog all;                                        ---然后就可以删除文件了
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1154 device type=DISK
List of Archived Log Copies for database with db_unique_name LSQ
=====================================================================
Key     Thrd Seq     S Low Time
------- ---- ------- - ---------
2       1    102     A 14-FEB-23
        Name: /u01/app/oracle/oradata/1_102_1124643686.dbf

Do you really want to delete the above objects (enter YES or NO)? yes
deleted archived log
archived log file name=/u01/app/oracle/oradata/1_102_1124643686.dbf RECID=2 STAMP=1196172872
Deleted 1 objects


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2025-3-29 19:15 , Processed in 0.097613 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表