Oracle修改日志归档模式、归档路径以及空间大小的相关测试
ORACLE 创建数据库的时候要不要开启日志归档?
oracle数据库可以运行在2种模式下:归档模式(archivelog)和非归档模式(noarchivelog) 。
归档模式可以提高Oracle数据库的可恢复性。
生产数据库都应该运行在此模式下,归档模式应该和相应的备份策略相结合,只有归档模式没有相应的备份策略只会带来麻烦。
在默认情况下,oracle数据库是在非归日志档模式中创建的,
在非归档日志模式中,进行日志切换时会直接重写redo log,如果此时数据文件因为介质失败被损坏,则数据库恢复时会丢失掉被重写的数据;
在归档日志模式下,数据库可以应用最近一次数据库备份开始生成的所有归档日志文件,保证数据无丢失;大部分的生产数据库以archivelog模式运行。
oracle数据库在开启归档日志模式后,会自动启动新的进程:归档器ARCn。默认情况下是开启4个进程,在实际应用中最多可以启动30个归档器进程。
[oracle@dbserver1 archivelog]$ ps -ef | grep -i ora_
oracle 26567 1 0 08:48 ? 00:00:00 ora_arc0_orcl
oracle 26573 1 0 08:48 ? 00:00:00 ora_arc1_orcl
oracle 26575 1 0 08:48 ? 00:00:00 ora_arc2_orcl
oracle 26577 1 0 08:48 ? 00:00:00 ora_arc3_orcl
归档日志(Archive Log)是非活动的重做日志备份.通过使用归档日志,可以保留所有重做历史记录,当数据库处于ARCHIVELOG模式并进行日志切换式,
后台进程ARCH会将重做日志的内容保存到归档日志中.当数据库出现介质失败时,使用数据文件备份,归档日志和重做日志可以完全恢复数据库.
#########################
非归档模式 切换 归档模式
修改之前:
确认环境。查看数据库,是否开启归档: ---如下显示的信息,前提是安装数据库的时候,没有选择开启闪回,也没有选择开启归档
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 4
Current log sequence 6 SQL> select name,log_mode from v$database;
NAME LOG_MODE
--------- ------------
ORCL NOARCHIVELOG SQL> show parameter db_recovery
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string
db_recovery_file_dest_size big integer 0
######### 如下 测试没有开启闪回的情况下 数据库从非归档模式切换到归档模式的操作 ############
SQL> shutdown immediate
Database closed. SQL> startup mount
ORACLE instance started. SQL> alter database archivelog;
Database altered. SQL> alter database open;
Database altered. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6 SQL> select name from v$archived_log;
no rows selected SQL> alter system archive log current;
System altered. SQL> select name from v$archived_log;
NAME
--------------------------------------------------------------------------------
/home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_947091054.dbf SQL> show parameter recover;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string
db_recovery_file_dest_size big integer 0
db_unrecoverable_scn_tracking boolean TRUE
recovery_parallelism integer 0 SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;
no rows selected
将log_archive_log设置为默认值时,归档目录将会变为?/dbs/arch。
SQL> alter system set log_archive_dest_1='';
System altered. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination ?/dbs/arch
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7 SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down. SQL> startup mount
ORACLE instance started.
重启数据库到mount后,归档目录变回为原先默认的目录。
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7
---设置归档最大开启进程个数 SQL> alter system set log_archive_max_processes = 5;
System altered.
---修改日志存放格式 SQL> alter system set log_archive_format = "archive_%t_%s_%r.log" scope=spfile;
System altered.
SQL> shutdown immediate
Database dismounted.
ORACLE instance shut down SQL> startup
ORACLE instance started. Total System Global Area 939495424 bytes
Fixed Size 2258840 bytes
Variable Size 637536360 bytes
Database Buffers 293601280 bytes
Redo Buffers 6098944 bytes
Database mounted.
Database opened. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7 SQL> show parameter db_recovery
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string
db_recovery_file_dest_size big integer 0 SQL> select name from v$archived_log;
NAME
--------------------------------------------------------------------------------
/home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_947091054.dbf SQL> alter system switch logfile;
System altered. SQL> select recid, name, first_time from v$archived_log; NAME
--------------------------------------------------------------------------------
/home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_947091054.dbf
/home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/archarchive_1_7_94709105
4.log SQL> select NAME,SPACE_LIMIT/1024/1024/1024,SPACE_USED/1024/1024/1024,NUMBER_OF_FILES from V$RECOVERY_FILE_DEST; no rows selected SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
#############################
开启数据库闪回 设置闪回恢复区路径 以及大小 测试 先关闭归档模式 然后再开启归档后的 默认路径 为数据库的闪回路径
查看数据库,是否开启闪回
注意:开启闪回功能的话,需要在归档模式下,要不闪回没有意义!!!!
但是,开启归档的话,不一定需要开启闪回功能!!!
如果开启了闪回,再开启归档模式,归档日志没有指定新路径的话,那么归档日志是默认保存在闪回区的 数据库中显示为:USE_DB_RECOVERY_FILE_DEST,实际对应闪回的路径。
另外闪回区和归档路径的 位置和大小都是可以手动设置的。
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> shutdown immediate
SQL> startup mount SQL> alter database flashback on; 安装数据库的时候 没有选择开启闪回,出现了如下错误
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38709: Recovery Area is not enabled.
设置闪回恢复区:
设置闪回区大小: oracle默认flash_recovery_area 为2G
SQL> alter system set db_recovery_file_dest_size=5g scope=spfile;
查看闪回区指定路径的空间大小:
SQL> show parameter db_recovery_file_dest_size NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest_size big integer 30G
设置闪回区位置:
SQL> alter system set db_recovery_file_dest='/home/oracle/u01/app/oracle/account_flashback_area' scope=spfile;
设置闪回目标为5天,以分钟为单位,oracle默认1440分钟,即一天)
SQL> alter system set db_flashback_retention_target=7200 scope=spfile;
操作系统层面创建闪回相关目录:
[oracle@dbserver oracle]$ mkdir -p /home/oracle/u01/app/oracle/account_flashback_area SQL> alter database flashback on;
Database altered.
SQL> alter database open;
Database altered. SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
结论:如果开启了闪回,再开启归档模式,归档日志没有指定新路径的话,那么归档日志是默认保存在闪回区的 数据库中显示为:USE_DB_RECOVERY_FILE_DEST,实际对应闪回的路径。
目前我们再测试关闭闪回 重启数据库 查看归档日志路径
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE SQL> shutdown immediate
Database closed. SQL> startup mount
ORACLE instance started.
关闭归档模式 ----提示我们数据库运行在归档模式 闪回开启的情况下,是不能直接关闭归档的
SQL> alter database noarchivelog;
alter database noarchivelog
*
ERROR at line 1:
ORA-38774: cannot disable media recovery - flashback database is enabled
那么我们就先关闭闪回
SQL> alter database flashback off;
Database altered. SQL> alter database noarchivelog;
Database altered. SQL> alter database open;
Database altered. SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Current log sequence 8 SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
重新启动,开启归档 查看归档路径
SQL> shutdown immediate
Database closed.
SQL> startup mount
ORACLE instance started.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8 SQL> select flashback_on,open_mode from v$database;
FLASHBACK_ON OPEN_MODE
------------------ --------------------
NO READ WRITE
结论:开启归档的话,不一定需要开启闪回功能,可以不开启闪回!!!
测试3:修改归档默认路径
SQL> shutdown immediate
SQL> startup mount
ORACLE instance started. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8 SQL> alter system set log_archive_dest_1='location=/home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch';
System altered. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8 SQL> select flashback_on,open_mode from v$database; FLASHBACK_ON OPEN_MODE
------------------ --------------------
NO MOUNTED
测试4: 我们关闭归档 先开启闪回 再开启归档 启动数据库 查看归档路径 是否会见自定义的路径 修改为默认的闪回路径
SQL> alter database noarchivelog;
Database altered. SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 6
Current log sequence 8 SQL> alter database flashback on; ----非归档模式下 无法开启闪回
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38707: Media recovery is not enabled.
结论: 非归档模式下 无法开启闪回
################################################
SQL> alter database archivelog;
Database altered. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
SQL>
SQL> alter database flashback on;
Database altered. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
结论: 如果归档日志指定了存储路径 那么开启闪回的话 归档日志的存放路径还是保持用户原先指定的路径
#############################
继续:
修改归档日志为数据库默认的存放路径 重复上述操作 确认归档日志的路径 是否为闪回区的路径
SQL> shutdown immediate
Database closed.
SQL> startup mount
ORACLE instance started. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8 SQL> alter system set log_archive_dest_1=''; ---修改归档日志为数据库默认的存放路径
System altered. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination ?/dbs/arch
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8 SQL> alter database open;
Database altered. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination ?/dbs/arch
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8 SQL> select flashback_on,open_mode from v$database;
FLASHBACK_ON OPEN_MODE
------------------ --------------------
YES READ WRITE SQL> shutdown immediate
Database closed. SQL> startup
ORACLE instance started. SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
结论:归档日志为数据库默认的存放路径,在闪回功能开启的情况下,切换为归档模式,归档日志的路径默认为闪回区的路径。
其他参考:
http://xmdiao.blog.51cto.com/6331248/1392207/
http://blog.csdn.net/weixin_36707770/article/details/53885423
http://blog.csdn.net/panfelix/article/details/43452121
http://blog.sina.com.cn/s/blog_54eeb5d90100kqf4.html
https://zhidao.baidu.com/question/2054618093433889467.html
http://blog.chinaunix.net/uid-28255964-id-4344766.html
http://jingyan.baidu.com/article/d3b74d64abfa6b1f77e60982.html
http://www.2cto.com/database/201109/102332.html
http://database.51cto.com/art/201108/287998.htm
http://blog.chinaunix.net/uid-26446098-id-4979004.html
Oracle修改日志归档模式、归档路径以及空间大小的相关测试的更多相关文章
- Oracle的日志记录模式
本篇摘自 http://www.cnblogs.com/cnjava/archive/2012/04/09/2439497.html --=============================== ...
- ORACLE 修改日志大小及增加日志成员
日志文件能不能resize,直接扩大日志文件的大小?10g是不能的. 网上的一般方法就是新建两个临时日志组(oracle至少要求两个日志组),切换到这两个临时日志组后,删掉重建扩大或缩小,再添加日志组 ...
- oracle 修改用户下部分表现有表空间
工作日记之<修改用户表现有表空间> //user_tables可查询出当前登录用户的所有表,以及部分表信息,可以灵活运用于其他用途 //假设现有表空间TS1.TS2,需要迁移所有表空间TS ...
- 【Oracle】Oracle改变日志归档模式
一.确认工作模式: 1.查询V$DATABASE SQL>select log_mode from v$database; 归档日志:ARCHIVELOG 2.执 ...
- Oracle数据库LOGGING&NOLOGGING模式概述
1.日志记录模式(LOGGING .FORCE LOGGING .NOLOGGING) 1.1三者的含义 LOGGING:当创建一个数据库对象时将记录日志信息到联机重做日志文件.LOGGING实际上是 ...
- Spring Boot动态修改日志级别
1. pom中引入 org.springframework.boot spring-boot-starter-actuator 2. 发送POST请求: 地址: http://[服务地址] ...
- log4j2和logback动态修改日志级别工具类
工作中,在排查线上问题时,有以下场景在不重新部署或重启服务的情况下,需要动态调整线上日志级别 1.线上有些日志打印过多干扰有用的日志,需要动态修改线上日志记录器的打印日志级别,调高一些日志级别,打印出 ...
- oracle修改归档日志路径与格式
一.查询数据库是否开启归档模式: SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled ...
- 修改oracle数据库为归档模式
参考博客:http://blog.csdn.net/codesaint/article/details/1901030 Oracle分为非归档模式(NOARCHIVELOG) 和归档模式(ARCHI ...
随机推荐
- B-论文一些好的句子
Due to high design and test costs for real many-core chips, simulators which allow exploring the bes ...
- myeclipse cannot connect to vm
启动tomcat时,tomcat可以直接运行,而debug时弹出 解决方法:打开360安全卫士的功能大全找到修复网络(LSP)点击立即修复就可以使用debug
- Apache hadoop安装配置
1.网络中继更改问题 命令: vi /etc/sysconfig/network-scripts/ifcfg-eth0 需要修改的代码 DEVICE=eth0 HWADDR=00:0C:29:11 ...
- 《ARM Cortex-M3权威指南》笔记(1)
http://blog.csdn.net/roverx/article/details/6624859 第1章 介绍 一.ARM Cortex‐M3处理器初探 CM3处理器内核是单片机的中央处理单元( ...
- shell脚本-成长之路
我对shell脚本的认识,除了执行过同事写的shell 脚本外,其他一无所知,为了让自己强大,我决定自己研究shell脚本,也许在你看来很简答,没必要说这么多废话,但是我希望在我的技术log里记录下来 ...
- Django URLs error: view must be a callable or a list/tuple in the case of include()
Django 1.10 no longer allows you to specify views as a string (e.g. 'myapp.views.home') in your URL ...
- Hdu4135 Co-prime 2017-06-27 16:03 25人阅读 评论(0) 收藏
Co-prime Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Subm ...
- java后台技术
本文旨在梳理服务端开发技术栈,希望帮助后端开发同学更全面了解Java服务端主要涉及的知识点 1. 语言相关 1.1 Java 核心知识点 Java的类加载机制 JVM相关:JVM内存模型和结构,GC原 ...
- java并发编程基础-ReentrantLock及LinkedBlockingQueue源码分析
ReentrantLock是一个较为常用的锁对象.在上次分析的uil开源项目中也多次被用到,下面谈谈其概念和基本使用. 概念 一个可重入的互斥锁定 Lock,它具有与使用 synchronized 相 ...
- nodeclub
nodeclub笔记:https://cnodejs.org/topic/535601a20d7d0faf140303d8 先看一下框架,把没有接触过的部分熟悉一下. 熟悉一下package.json ...