管理控制文件 和日志文件
前言
一:管理控制文件
1:控制文件概述
2:控制文件的多路复用
2-1:更改 control_files 参数
示例:oracle 增加控制文件的方法:
1: 查看参数文件存放位置,并关闭数据库实例 orcl:
1 [oracle@localhost orcl]$ sqlplus / as sysdba; 2 3 SQL*Plus: Release 11.2.0.3.0 Production on Tue Jan 9 23:07:02 2018 4 5 Copyright (c) 1982, 2011, Oracle. All rights reserved. 6 7 8 Connected to: 9 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production 10 With the Partitioning, OLAP, Data Mining and Real Application Testing options 11 12 SYS@orcl> show parameter control_files; 13 14 NAME TYPE VALUE 15 ------------------------------------ ----------- ------------------------------ 16 control_files string /u01/app/oracle/oradata/orcl/c 17 ontrol01.ctl, /u01/app/oracle/ 18 fast_recovery_area/orcl/contro 19 l02.ctl 20 21 22 SYS@orcl> select name from v$controlfile; 23 24 NAME 25 -------------------------------------------------------------------------------- 26 /u01/app/oracle/oradata/orcl/control01.ctl 27 /u01/app/oracle/fast_recovery_area/orcl/control02.ctl 28 29 SYS@orcl> shutdown immediate; 30 Database closed. 31 Database dismounted. 32 ORACLE instance shut down. 33 34
2: 退出sqlplus, 复制文件。
1 SYS@orcl> quit 2 Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production 3 With the Partitioning, OLAP, Data Mining and Real Application Testing options 4 [oracle@localhost ~]$ cd /u01/app/oracle/fast_recovery_area/orcl 5 [oracle@localhost orcl]$ pwd 6 /u01/app/oracle/fast_recovery_area/orcl 7 [oracle@localhost orcl]$ ls 8 control02.ctl 9 [oracle@localhost orcl]$ cp control02.ctl control03.ctl 10 [oracle@localhost orcl]$ ls 11 control02.ctl control03.ctl3:登录进入 sqplus ,启动数据库实例进入 nomount状态,并修改控制文件参数
1 [oracle@localhost ~]$ sqlplus / as sysdba; 2 3 SQL*Plus: Release 11.2.0.3.0 Production on Wed Jan 10 00:14:01 2018 4 5 Copyright (c) 1982, 2011, Oracle. All rights reserved. 6 7 8 Connected to: 9 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production 10 With the Partitioning, OLAP, Data Mining and Real Application Testing options 11 12 SYS@orcl> startup nomount; 13 ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance 14 ORACLE instance started. 15 16 Total System Global Area 1221992448 bytes 17 Fixed Size 1344596 bytes 18 Variable Size 771754924 bytes 19 Database Buffers 436207616 bytes 20 Redo Buffers 12685312 bytes 21 SYS@orcl> alter system set control_files='/u01/app/oracle/oradata/orcl/control01.ctl', '/u01/app/oracle/fast_recovery_area/orcl/control02.ctl', '/u01/app/oracle/fast_recovery_area/orcl/control03.ctl' scope=spfile; 22 23 System altered. 24 25 SYS@orcl> shutdown immediate; 26 ORA-01507: database not mounted 27 28 29 ORACLE instance shut down. 30 SYS@orcl> startup 31 ORACLE instance started. 32 33 Total System Global Area 1221992448 bytes 34 Fixed Size 1344596 bytes 35 Variable Size 771754924 bytes 36 Database Buffers 436207616 bytes 37 Redo Buffers 12685312 bytes 38 Database mounted. 39 Database opened. 40 SYS@orcl> create pfile from spfile; 41 42 File created. 43 44 SYS@orcl> select name from v$controlfile; 45 46 NAME 47 -------------------------------------------------------------------------------- 48 /u01/app/oracle/oradata/orcl/control01.ctl 49 /u01/app/oracle/fast_recovery_area/orcl/control02.ctl 50 /u01/app/oracle/fast_recovery_area/orcl/control03.ctl 51 52 SYS@orcl>1 SYS@orcl> shutdown immediate; 2 Database closed. 3 Database dismounted. 4 ORACLE instance shut down. 5 SYS@orcl> startup 6 ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance 7 ORACLE instance started. 8 9 Total System Global Area 1221992448 bytes 10 Fixed Size 1344596 bytes 11 Variable Size 771754924 bytes 12 Database Buffers 436207616 bytes 13 Redo Buffers 12685312 bytes 14 Database mounted. 15 Database opened. 16 SYS@orcl>
2-2:复制控制文件
3: 创建控制文件
1: 查看数据文件和重做日志文件
1 SYS@orcl> select member from v$logfile; 2 3 MEMBER 4 -------------------------------------------------------------------------------- 5 /u01/app/oracle/oradata/orcl/redo03.log 6 /u01/app/oracle/oradata/orcl/redo02.log 7 /u01/app/oracle/oradata/orcl/redo01.log1 SYS@orcl> select name from v$datafile; 2 3 NAME 4 -------------------------------------------------------------------------------- 5 /u01/app/oracle/oradata/orcl/system01.dbf 6 /u01/app/oracle/oradata/orcl/sysaux01.dbf 7 /u01/app/oracle/oradata/orcl/undotbs01.dbf 8 /u01/app/oracle/oradata/orcl/users01.dbf 9 /u01/app/oracle/oradata/orcl/example01.dbf1 SYS@orcl> select name from v$controlfile; 2 3 NAME 4 -------------------------------------------------------------------------------- 5 /u01/app/oracle/oradata/orcl/control01.ctl 6 /u01/app/oracle/fast_recovery_area/orcl/control02.ctl 7 /u01/app/oracle/fast_recovery_area/orcl/control03.ctl 8 9 SYS@orcl>
1 [oracle@localhost ~]$ sqlplus / as sysdba; 2 3 SQL*Plus: Release 11.2.0.3.0 Production on Tue Feb 27 21:59:54 2018 4 5 Copyright (c) 1982, 2011, Oracle. All rights reserved. 6 7 8 Connected to: 9 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production 10 With the Partitioning, OLAP, Data Mining and Real Application Testing options 11 12 SYS@orcl> select member from v$logfile; 13 14 MEMBER 15 -------------------------------------------------------------------------------- 16 /u01/app/oracle/oradata/orcl/redo03.log 17 /u01/app/oracle/oradata/orcl/redo02.log 18 /u01/app/oracle/oradata/orcl/redo01.log 19 20 SYS@orcl> select name from v$datafile; 21 22 NAME 23 -------------------------------------------------------------------------------- 24 /u01/app/oracle/oradata/orcl/system01.dbf 25 /u01/app/oracle/oradata/orcl/sysaux01.dbf 26 /u01/app/oracle/oradata/orcl/undotbs01.dbf 27 /u01/app/oracle/oradata/orcl/users01.dbf 28 /u01/app/oracle/oradata/orcl/example01.dbf 29 30 SYS@orcl> select name from v$controlfile; 31 32 NAME 33 -------------------------------------------------------------------------------- 34 /u01/app/oracle/oradata/orcl/control01.ctl 35 /u01/app/oracle/fast_recovery_area/orcl/control02.ctl 36 /u01/app/oracle/fast_recovery_area/orcl/control03.ctl 37 38 SYS@orcl>
2:关闭数据库
1 SYS@orcl> shutdown immediate; 2 Database closed. 3 Database dismounted. 4 ORACLE instance shut down. 5 SYS@orcl>
3:备份文件
1 Last login: Mon Feb 26 15:36:54 2018 from 192.168.242.1 2 [root@localhost ~]# su - oracle 3 [oracle@localhost ~]$ ls 4 database h:1dept.sql h:1.lst h:emp.txt p10404530_112030_LINUX_1of7.zip p10404530_112030_LINUX_3of7.zip rlwrap-0.37.tar.gz 5 grid h:1emp.txt h:1spooltest.txt oyt.lst p10404530_112030_LINUX_2of7.zip rlwrap-0.37 6 [oracle@localhost ~]$ mkdir oracle_system_files_back 7 [oracle@localhost ~]$ 8 [oracle@localhost ~]$ ls 9 database h:1dept.sql h:1.lst h:emp.txt oyt.lst p10404530_112030_LINUX_2of7.zip rlwrap-0.37 10 grid h:1emp.txt h:1spooltest.txt oracle_system_files_back p10404530_112030_LINUX_1of7.zip p10404530_112030_LINUX_3of7.zip rlwrap-0.37.tar.gz 11 [oracle@localhost ~]$ mv p10* oracle_system_files_back/ 12 [oracle@localhost ~]$ ls 13 database grid h:1dept.sql h:1emp.txt h:1.lst h:1spooltest.txt h:emp.txt oracle_system_files_back oyt.lst rlwrap-0.37 rlwrap-0.37.tar.gz 14 [oracle@localhost ~]$ cd oracle_system_files_back/ 15 [oracle@localhost oracle_system_files_back]$ ls 16 p10404530_112030_LINUX_1of7.zip p10404530_112030_LINUX_2of7.zip p10404530_112030_LINUX_3of7.zip 17 [oracle@localhost oracle_system_files_back]$ mkdir install_zip 18 [oracle@localhost oracle_system_files_back]$ mv p* install_zip/ 19 [oracle@localhost oracle_system_files_back]$ ls 20 install_zip 21 [oracle@localhost oracle_system_files_back]$ mkdir redo_bak 22 [oracle@localhost oracle_system_files_back]$ cd redo_bak/ 23 [oracle@localhost redo_bak]$ mkdir redo_bak_20180227 24 [oracle@localhost redo_bak]$ cd redo_bak_20180227/ 25 [oracle@localhost redo_bak_20180227]$ ls 26 [oracle@localhost redo_bak_20180227]$ cd .. 27 [oracle@localhost redo_bak]$ ls 28 redo_bak_20180227 29 [oracle@localhost redo_bak]$ cp /u01/app/oracle/oradata/orcl/* redo_bak_20180227/ 30 [oracle@localhost redo_bak]$ ls 31 redo_bak_20180227 32 [oracle@localhost redo_bak]$ cd redo_bak_20180227/ 33 [oracle@localhost redo_bak_20180227]$ ls 34 control01.ctl example01.dbf redo01.log redo02.log redo03.log sysaux01.dbf system01.dbf temp01.dbf undotbs01.dbf users01.dbf 35 [oracle@localhost redo_bak_20180227]$ cd ../../.. 36 [oracle@localhost ~]$ ls 37 database grid h:1dept.sql h:1emp.txt h:1.lst h:1spooltest.txt h:emp.txt oracle_system_files_back oyt.lst rlwrap-0.37 rlwrap-0.37.tar.gz 38 [oracle@localhost ~]$ cd oracle_system_files_back/ 39 [oracle@localhost oracle_system_files_back]$ ls 40 install_zip redo_bak 41 [oracle@localhost oracle_system_files_back]$ mkdir datafiles_bak 42 [oracle@localhost oracle_system_files_back]$ cd datafiles_bak/ 43 [oracle@localhost datafiles_bak]$ ls 44 [oracle@localhost datafiles_bak]$ mkdir datafiles_bak_20180227 45 [oracle@localhost datafiles_bak]$ ls 46 datafiles_bak_20180227 47 [oracle@localhost datafiles_bak]$ cp /u01/app/oracle/oradata/orcl/*.dbf 48 cp: target `/u01/app/oracle/oradata/orcl/users01.dbf' is not a directory 49 [oracle@localhost datafiles_bak]$ cp /u01/app/oracle/oradata/orcl/*.dbf datafiles_bak_20180227/ 50 [oracle@localhost datafiles_bak]$ ls 51 datafiles_bak_20180227 52 [oracle@localhost datafiles_bak]$ cd datafiles_bak_20180227/ 53 [oracle@localhost datafiles_bak_20180227]$ ls 54 example01.dbf sysaux01.dbf system01.dbf temp01.dbf undotbs01.dbf users01.dbf 55 [oracle@localhost datafiles_bak_20180227]$ cd ../../ 56 [oracle@localhost oracle_system_files_back]$ ls 57 datafiles_bak install_zip redo_bak 58 [oracle@localhost oracle_system_files_back]$ mkidr controlfile_bak 59 -bash: mkidr: command not found 60 [oracle@localhost oracle_system_files_back]$ mkdir controlfile_bak 61 [oracle@localhost oracle_system_files_back]$ cd controlfile_bak/ 62 [oracle@localhost controlfile_bak]$ ls 63 [oracle@localhost controlfile_bak]$ mkdir controlfile_bak_20180227 64 [oracle@localhost controlfile_bak]$ 65 [oracle@localhost controlfile_bak]$ ls 66 controlfile_bak_20180227 67 [oracle@localhost controlfile_bak]$ cp /u01/app/oracle/oradata/orcl/*.ctl controlfile_bak_20180227/ 68 [oracle@localhost controlfile_bak]$ cp /u01/app/oracle/fast_recovery_area/orcl/*.ctl controlfile_bak_20180227/ 69 [oracle@localhost controlfile_bak]$ ls 70 controlfile_bak_20180227 71 [oracle@localhost controlfile_bak]$ cd controlfile_bak_20180227/ 72 [oracle@localhost controlfile_bak_20180227]$ ls 73 control01.ctl control02.ctl control03.ctl 74 [oracle@localhost controlfile_bak_20180227]$
4:启动数据库
1 SYS@orcl> startup nomount 2 3 ORACLE instance started. 4 5 Total System Global Area 1221992448 bytes 6 Fixed Size 1344596 bytes 7 Variable Size 805309356 bytes 8 Database Buffers 402653184 bytes 9 Redo Buffers 12685312 bytes 10 SYS@orcl>
5:创建新的控制文件
1 create controlfile 2 reuse database 'orcl' 3 logfile 4 group 1 '/u01/app/oracle/oradata/orcl/redo01.log', 5 group 2 '/u01/app/oracle/oradata/orcl/redo02.log', 6 group 3 '/u01/app/oracle/oradata/orcl/redo03.log' 7 datafile '/u01/app/oracle/oradata/orcl/system01.dbf', 8 '/u01/app/oracle/oradata/orcl/sysaux01.dbf' , 9 '/u01/app/oracle/oradata/orcl/sysaux01.dbf', 10 '/u01/app/oracle/oradata/orcl/users01.dbf', 11 '/u01/app/oracle/oradata/orcl/example01.dbf' 12 maxlogfiles 50 13 maxinstances 60 14 maxdatafiles 200 15 noresetlogs 16 noarchivelog;6:编辑参数
7:打开数据库
1 2 SYS@orcl> alter database mount; 3 4 Database altered. 5 6 SYS@orcl> alter database open; 7 8 Database altered. 9 10 SYS@orcl>
4:备份和恢复控制文件
1: 备份控制文件
1:备份二进制文件需要使用”alter database backup controlfile“语句
将数据库的控制文件备份为一个二进制文件,即复制当前的控制文件:
1 SYS@orcl> alter database backup controlfile to '/home/oracle/oracle_system_files_back/controlfile_bak/controlfile_bak_20180227_1/control_file1.bkp'; 2 3 Database altered. 4 5 SYS@orcl> 6
2: 备份为脚本文件,实际上就是备份为可读的文本文件。同样使用 ”alter database backup controlfile “ 语句
将数据库的控制文件备份为一个可读的文件文件:
将控制文件以文本形式备份时,所创建的文件也称为跟踪文件,该文件实际上是一个SQL脚本,可以利用它来”重新创建“ 新的控制文件。跟踪文件的存放位置由spfile文件中的user_dump_dest参数决定;
1 2 SYS@orcl> show parameter user_dump_dest; 3 4 NAME TYPE VALUE 5 ------------------------------------ ----------- ------------------------------ 6 user_dump_dest string /u01/app/oracle/diag/rdbms/orc 7 l/orcl/trace 8 SYS@orcl>查看其文件内容:
1 2 [oracle@localhost trace]$ cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace 3 [oracle@localhost trace]$ ls 4 alert_orcl.log orcl_dbrm_16304.trm orcl_j000_6133.trm orcl_m000_16375.trm orcl_mmon_16320.trm orcl_ora_16328.trm orcl_p000_5631.trm orcl_vkrm_16541.trm 5 orcl_cjq0_16411.trc orcl_dbrm_16478.trc orcl_j001_16032.trc orcl_mman_16308.trc orcl_mmon_16494.trc orcl_ora_16436.trc orcl_p001_5633.trc orcl_vkrm_6139.trc 6 orcl_cjq0_16411.trm orcl_dbrm_16478.trm orcl_j001_16032.trm orcl_mman_16308.trm orcl_mmon_16494.trm orcl_ora_16436.trm orcl_p001_5633.trm orcl_vkrm_6139.trm 7 orcl_cjq0_16539.trc orcl_dbrm_5585.trc orcl_j004_5883.trc orcl_mman_16482.trc orcl_mmon_5601.trc orcl_ora_16502.trc orcl_p002_5635.trc orcl_vktm_16296.trc 8 orcl_cjq0_16539.trm orcl_dbrm_5585.trm orcl_j004_5883.trm orcl_mman_16482.trm orcl_mmon_5601.trm orcl_ora_16502.trm orcl_p002_5635.trm orcl_vktm_16296.trm 9 orcl_cjq0_5655.trc orcl_j000_14819.trc orcl_j008_5674.trc orcl_mman_5589.trc orcl_ora_16022.trc orcl_ora_5541.trc orcl_vkrm_16024.trc orcl_vktm_16470.trc 10 orcl_cjq0_5655.trm orcl_j000_14819.trm orcl_j008_5674.trm orcl_mman_5589.trm orcl_ora_16022.trm orcl_ora_5541.trm orcl_vkrm_16024.trm orcl_vktm_16470.trm 11 orcl_ckpt_5595.trc orcl_j000_4910.trc orcl_lgwr_5593.trc orcl_mmnl_5603.trc orcl_ora_16262.trc orcl_ora_5629.trc orcl_vkrm_16413.trc orcl_vktm_5577.trc 12 orcl_ckpt_5595.trm orcl_j000_4910.trm orcl_lgwr_5593.trm orcl_mmnl_5603.trm orcl_ora_16262.trm orcl_ora_5629.trm orcl_vkrm_16413.trm orcl_vktm_5577.trm 13 orcl_dbrm_16304.trc orcl_j000_6133.trc orcl_m000_16375.trc orcl_mmon_16320.trc orcl_ora_16328.trc orcl_p000_5631.trc orcl_vkrm_16541.trc 14 [oracle@localhost trace]$ ll 15 total 656获取 最后生成的 文本文件:
1 orcl_ora_16502.trc orcl_ora_16502.trm 2 [oracle@localhost trace]$ cat orcl_ora_16502.trc 3 Trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_16502.trc 4 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production 5 With the Partitioning, OLAP, Data Mining and Real Application Testing options 6 ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1 7 System name: Linux 8 Node name: localhost.localdomain 9 Release: 2.6.18-164.el5xen 10 Version: #1 SMP Thu Sep 3 02:41:56 EDT 2009 11 Machine: i686 12 VM name: Xen Version: 3.1 (PVM) 13 Instance name: orcl 14 Redo thread mounted by this instance: 1 15 Oracle process number: 19 16 Unix process pid: 16502, image: oracle@localhost.localdomain (TNS V1-V3) 17 18 19 *** 2018-02-27 23:07:19.329 20 *** SESSION ID:(191.1) 2018-02-27 23:07:19.329 21 *** CLIENT ID:() 2018-02-27 23:07:19.329 22 *** SERVICE NAME:(SYS$USERS) 2018-02-27 23:07:19.329 23 *** MODULE NAME:(sqlplus@localhost.localdomain (TNS V1-V3)) 2018-02-27 23:07:19.329 24 *** ACTION NAME:() 2018-02-27 23:07:19.329 25 26 kwqmnich: current time:: 15: 7: 19: 0 27 kwqmnich: instance no 0 repartition flag 1 28 kwqmnich: initialized job cache structure 29 kwqinfy: Call kwqrNondurSubInstTsk 30 31 *** 2018-02-27 23:36:19.737 32 -- The following are current System-scope REDO Log Archival related 33 -- parameters and can be included in the database initialization file. 34 -- 35 -- LOG_ARCHIVE_DEST='' 36 -- LOG_ARCHIVE_DUPLEX_DEST='' 37 -- 38 -- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf 39 -- 40 -- DB_UNIQUE_NAME="orcl" 41 -- 42 -- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG' 43 -- LOG_ARCHIVE_MAX_PROCESSES=4 44 -- STANDBY_FILE_MANAGEMENT=MANUAL 45 -- STANDBY_ARCHIVE_DEST=?/dbs/arch 46 -- FAL_CLIENT='' 47 -- FAL_SERVER='' 48 -- 49 -- LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST' 50 -- LOG_ARCHIVE_DEST_1='MANDATORY NOREOPEN NODELAY' 51 -- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM EXPEDITE NOVERIFY SYNC' 52 -- LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE NODEPENDENCY' 53 -- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME' 54 -- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)' 55 -- LOG_ARCHIVE_DEST_STATE_1=ENABLE 56 -- 57 -- Below are two sets of SQL statements, each of which creates a new 58 -- control file and uses it to open the database. The first set opens 59 -- the database with the NORESETLOGS option and should be used only if 60 -- the current versions of all online logs are available. The second 61 -- set opens the database with the RESETLOGS option and should be used 62 -- if online logs are unavailable. 63 -- The appropriate set of statements can be copied from the trace into 64 -- a script file, edited as necessary, and executed when there is a 65 -- need to re-create the control file. 66 -- 67 -- Set #1. NORESETLOGS case 68 -- 69 -- The following commands will create a new control file and use it 70 -- to open the database. 71 -- Data used by Recovery Manager will be lost. 72 -- Additional logs may be required for media recovery of offline 73 -- Use this only if the current versions of all online logs are 74 -- available. 75 -- After mounting the created controlfile, the following SQL 76 -- statement will place the database in the appropriate 77 -- protection mode: 78 -- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE 79 STARTUP NOMOUNT 80 CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS NOARCHIVELOG 81 MAXLOGFILES 16 82 MAXLOGMEMBERS 3 83 MAXDATAFILES 100 84 MAXINSTANCES 8 85 MAXLOGHISTORY 292 86 LOGFILE 87 GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log' SIZE 50M BLOCKSIZE 512, 88 GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log' SIZE 50M BLOCKSIZE 512, 89 GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log' SIZE 50M BLOCKSIZE 512 90 -- STANDBY LOGFILE 91 DATAFILE 92 '/u01/app/oracle/oradata/orcl/system01.dbf', 93 '/u01/app/oracle/oradata/orcl/sysaux01.dbf', 94 '/u01/app/oracle/oradata/orcl/undotbs01.dbf', 95 '/u01/app/oracle/oradata/orcl/users01.dbf', 96 '/u01/app/oracle/oradata/orcl/example01.dbf' 97 CHARACTER SET ZHS16GBK 98 ; 99 -- Commands to re-create incarnation table 100 -- Below log names MUST be changed to existing filenames on 101 -- disk. Any one log file from each branch can be used to 102 -- re-create incarnation records. 103 -- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_02_27/o1_mf_1_1_%u_.arc'; 104 -- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_02_27/o1_mf_1_1_%u_.arc'; 105 -- Recovery is required if any of the datafiles are restored backups, 106 -- or if the last shutdown was not normal or immediate. 107 RECOVER DATABASE 108 -- Database can now be opened normally. 109 ALTER DATABASE OPEN; 110 -- Commands to add tempfiles to temporary tablespaces. 111 -- Online tempfiles have complete space information. 112 -- Other tempfiles may require adjustment. 113 ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' 114 SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; 115 -- End of tempfile additions. 116 -- 117 -- Set #2. RESETLOGS case 118 -- 119 -- The following commands will create a new control file and use it 120 -- to open the database. 121 -- Data used by Recovery Manager will be lost. 122 -- The contents of online logs will be lost and all backups will 123 -- be invalidated. Use this only if online logs are damaged. 124 -- After mounting the created controlfile, the following SQL 125 -- statement will place the database in the appropriate 126 -- protection mode: 127 -- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE 128 STARTUP NOMOUNT 129 CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS NOARCHIVELOG 130 MAXLOGFILES 16 131 MAXLOGMEMBERS 3 132 MAXDATAFILES 100 133 MAXINSTANCES 8 134 MAXLOGHISTORY 292 135 LOGFILE 136 GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log' SIZE 50M BLOCKSIZE 512, 137 GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log' SIZE 50M BLOCKSIZE 512, 138 GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log' SIZE 50M BLOCKSIZE 512 139 -- STANDBY LOGFILE 140 DATAFILE 141 '/u01/app/oracle/oradata/orcl/system01.dbf', 142 '/u01/app/oracle/oradata/orcl/sysaux01.dbf', 143 '/u01/app/oracle/oradata/orcl/undotbs01.dbf', 144 '/u01/app/oracle/oradata/orcl/users01.dbf', 145 '/u01/app/oracle/oradata/orcl/example01.dbf' 146 CHARACTER SET ZHS16GBK 147 ; 148 -- Commands to re-create incarnation table 149 -- Below log names MUST be changed to existing filenames on 150 -- disk. Any one log file from each branch can be used to 151 -- re-create incarnation records. 152 -- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_02_27/o1_mf_1_1_%u_.arc'; 153 -- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_02_27/o1_mf_1_1_%u_.arc'; 154 -- Recovery is required if any of the datafiles are restored backups, 155 -- or if the last shutdown was not normal or immediate. 156 RECOVER DATABASE USING BACKUP CONTROLFILE 157 -- Database can now be opened zeroing the online logs. 158 ALTER DATABASE OPEN RESETLOGS; 159 -- Commands to add tempfiles to temporary tablespaces. 160 -- Online tempfiles have complete space information. 161 -- Other tempfiles may require adjustment. 162 ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' 163 SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; 164 -- End of tempfile additions. 165 -- 166 [oracle@localhost trace]$
2:恢复控制文件
5: 删除 控制文件
6:查询控制文件的信息
1 2 3 SYS@orcl> select type,record_size,records_total,records_used from v$controlfile_record_section; 4 5 TYPE RECORD_SIZE RECORDS_TOTAL RECORDS_USED 6 ---------------------------- ----------- ------------- ------------ 7 DATABASE 316 1 1 8 CKPT PROGRESS 8180 11 0 9 REDO THREAD 256 8 1 10 REDO LOG 72 16 3 11 DATAFILE 520 100 5 12 FILENAME 524 2298 10 13 TABLESPACE 68 100 6 14 TEMPORARY FILENAME 56 100 1 15 RMAN CONFIGURATION 1108 50 0 16 LOG HISTORY 56 292 95 17 OFFLINE RANGE 200 163 0 18 19 TYPE RECORD_SIZE RECORDS_TOTAL RECORDS_USED 20 ---------------------------- ----------- ------------- ------------ 21 ARCHIVED LOG 584 28 14 22 BACKUP SET 40 409 0 23 BACKUP PIECE 736 200 0 24 BACKUP DATAFILE 200 245 0 25 BACKUP REDOLOG 76 215 0 26 DATAFILE COPY 736 200 2 27 BACKUP CORRUPTION 44 371 0 28 COPY CORRUPTION 40 409 0 29 DELETED OBJECT 20 818 2 30 PROXY COPY 928 246 0 31 BACKUP SPFILE 124 131 0 32 33 TYPE RECORD_SIZE RECORDS_TOTAL RECORDS_USED 34 ---------------------------- ----------- ------------- ------------ 35 DATABASE INCARNATION 56 292 2 36 FLASHBACK LOG 84 2048 0 37 RECOVERY DESTINATION 180 1 1 38 INSTANCE SPACE RESERVATION 28 1055 1 39 REMOVABLE RECOVERY FILES 32 1000 0 40 RMAN STATUS 116 141 0 41 THREAD INSTANCE NAME MAPPING 80 8 8 42 MTTR 100 8 1 43 DATAFILE HISTORY 568 57 0 44 STANDBY DATABASE MATRIX 400 31 31 45 GUARANTEED RESTORE POINT 212 2048 0 46 47 TYPE RECORD_SIZE RECORDS_TOTAL RECORDS_USED 48 ---------------------------- ----------- ------------- ------------ 49 RESTORE POINT 212 2083 0 50 DATABASE BLOCK CORRUPTION 80 8384 0 51 ACM OPERATION 104 64 6 52 FOREIGN ARCHIVED LOG 604 1002 0 53 54 37 rows selected. 55 56 SYS@orcl>type 列 表示记录文档段的类型;
二: 管理重做日志文件
1:重做日志文件概述
1:日志文件的内容及数据恢复
2:写入 重做日志文件
2:增加日志组及其成员
1:添加新的重做日志文件组
在 System 模式下,向数据库中添加一个新的重做日志文件组:
1:先创建新的 日志文件存放的文件夹路径
1 [oracle@localhost /]$ cd ~ 2 [oracle@localhost ~]$ ls 3 database grid h:1dept.sql h:1emp.txt h:1.lst h:1spooltest.txt h:emp.txt oracle_system_files_back oyt.lst rlwrap-0.37 rlwrap-0.37.tar.gz 4 [oracle@localhost ~]$ cd oracle_system_files_back/ 5 [oracle@localhost oracle_system_files_back]$ ls 6 controlfile_bak datafiles_bak install_zip redo_bak 7 [oracle@localhost oracle_system_files_back]$ mkdir logfile_bak 8 [oracle@localhost oracle_system_files_back]$ ls 9 controlfile_bak datafiles_bak install_zip logfile_bak redo_bak 10 [oracle@localhost oracle_system_files_back]$ cd logfile_bak/ 11 [oracle@localhost logfile_bak]$ ls 12 [oracle@localhost logfile_bak]$ mkdir logfile_bak_20180228 13 [oracle@localhost logfile_bak]$ ls 14 logfile_bak_20180228 15 [oracle@localhost logfile_bak]$ cd logfile_bak_20180228/ 16 [oracle@localhost logfile_bak_20180228]$ pwd 17 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_2018022818 [oracle@localhost logfile_bak_20180228]$
2:在 sql 命令里创建 新的 日志组文件
新增 日志文件前:
1 SYS@orcl> select * from v$logfile; 2 3 GROUP# STATUS TYPE MEMBER IS_ 4 ---------- ------- ------- -------------------------------------------------------------------------------- 5 3 ONLINE /u01/app/oracle/oradata/orcl/redo03.log NO 6 2 ONLINE /u01/app/oracle/oradata/orcl/redo02.log NO 7 1 ONLINE /u01/app/oracle/oradata/orcl/redo01.log NO 8新增日志文件组脚本:
1 SYS@orcl> alter database add logfile ('/home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log', 2 '/home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log') size 50M; 3 4 Database altered.新增文件后:
向数据库中添加一个新的 重做日志文件组,并指定组编码号为5 :
新增执行脚本:
1:创建新的文件存放路径:
1 [oracle@localhost logfile_bak]$ ls 2 logfile_bak_20180228 3 [oracle@localhost logfile_bak]$ pwd 4 /home/oracle/oracle_system_files_back/logfile_bak 5 [oracle@localhost logfile_bak]$ mkdir logfile_bak_20180228_1 6 [oracle@localhost logfile_bak]$ ls 7 logfile_bak_20180228 logfile_bak_20180228_1 8 [oracle@localhost logfile_bak]$ cd logfile_bak_20180228_1/ 9 [oracle@localhost logfile_bak_20180228_1]$ pwd 10 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1 11 [oracle@localhost logfile_bak_20180228_1]$ 12 [oracle@localhost logfile_bak_20180228_1]$ 132:创建新的日志组
1 SYS@orcl> alter database add logfile group 5 ('/home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_A.log', 2 '/home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_B.log') size 50M; 3 4 Database altered. 5 6 SYS@orcl> 7 83:查看新增的日志文件信息:
2:创建日志成员文件
如果某个日志组中的所有日志成员都被损坏了,那么后台进程LGWR 切换到该日志组时候,Oracle 会停止工作,并对该数据库执行不完全恢复,为此数据库管理员需要想该日志组中添加一个或者多个日志成员。
为重做日志组添加新的成员,需要使用 ALTER DATABASE ADD LOG MEMBER 语句。
示例:为第四个日志组添加 一个新的日志文件成员:
新增执行脚本为:
1 SYS@orcl> alter database add logfile member '/u01/app/oracle/oradata/orcl/redo4.log' to group 4; 2 3 Database altered. 4 5 SYS@orcl>
查看执行后的文件变化情况:
示例:通过指定重做日志组中其他成员的名称,以确定要添加的新日志成员所属于的重做日志组:
新增日志命令;
1 SYS@orcl> alter database add logfile member '/u01/app/oracle/oradata/orcl/redo04.log' to ('/u01/app/oracle/oradata/orcl/redo01.log') ; 2 3 Database altered. 4 5 SYS@orcl> 6
3:删除重做日志
1: 删除日志成员
要删除1个日志成员文件,可以使用 “ ALTER DATABASE DROP LOGFILE MEMBER ” 语句。
示例如下:
执行脚本:
1 2 SYS@orcl> alter database drop logfile member '/u01/app/oracle/oradata/orcl/redo4.log' ; 3 4 Database altered. 5 6 SYS@orcl>
执行后结果:
2:删除日志文件组
1:进行日志切换:
1 2 SYS@orcl> set linesize 300 ; 3 SYS@orcl> col member for a250; 4 SYS@orcl> select group#,status,member from v$logfile; 5 6 GROUP# STATUS MEMBER 7 ---------- ------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 8 3 /u01/app/oracle/oradata/orcl/redo03.log 9 2 /u01/app/oracle/oradata/orcl/redo02.log 10 1 /u01/app/oracle/oradata/orcl/redo01.log 11 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log 12 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log 13 5 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_A.log 14 5 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_B.log 15 1 INVALID /u01/app/oracle/oradata/orcl/redo04.log 16 17 8 rows selected. 18 19 SYS@orcl> alter system switch logfile; 20 21 System altered. 22 23 SYS@orcl> select group#,status,member from v$logfile; 24 25 GROUP# STATUS MEMBER 26 ---------- ------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 27 3 /u01/app/oracle/oradata/orcl/redo03.log 28 2 /u01/app/oracle/oradata/orcl/redo02.log 29 1 /u01/app/oracle/oradata/orcl/redo01.log 30 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log 31 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log 32 5 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_A.log 33 5 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_B.log 34 1 INVALID /u01/app/oracle/oradata/orcl/redo04.log 35 36 8 rows selected. 37 38 SYS@orcl> alter system switch logfile; 39 40 System altered. 41 42 SYS@orcl> select group#,status,member from v$logfile; 43 44 GROUP# STATUS MEMBER 45 ---------- ------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 46 3 /u01/app/oracle/oradata/orcl/redo03.log 47 2 /u01/app/oracle/oradata/orcl/redo02.log 48 1 /u01/app/oracle/oradata/orcl/redo01.log 49 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log 50 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log 51 5 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_A.log 52 5 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_B.log 53 1 INVALID /u01/app/oracle/oradata/orcl/redo04.log 54 55 8 rows selected. 56 57 SYS@orcl> select group#,status from v$log; 58 59 GROUP# STATUS 60 ---------- ---------------- 61 1 INACTIVE ---非活动状态 62 2 CURRENT ---当前数据库正在使用的日志文件组 63 3 INACTIVE ---非活动状态 64 4 ACTIVE ---活动窗台 65 5 ACTIVE ---活动窗台 66 67 SYS@orcl>2:继续切换 日志组:
1 SYS@orcl> alter system switch logfile; 2 3 System altered. 4 5 SYS@orcl> select group#,status from v$log; 6 7 GROUP# STATUS 8 ---------- ---------------- 9 1 INACTIVE 10 2 ACTIVE 11 3 CURRENT 12 4 ACTIVE 13 5 ACTIVE 14 15 SYS@orcl> alter system switch logfile; 16 17 System altered. 18 19 SYS@orcl> select group#,status from v$log; 20 21 GROUP# STATUS 22 ---------- ---------------- 23 1 CURRENT 24 2 ACTIVE 25 3 ACTIVE 26 4 ACTIVE 27 5 ACTIVE 28 29 SYS@orcl>
3:删除 日志组5 的文件
1 SYS@orcl> select group#,status from v$log; 2 3 GROUP# STATUS 4 ---------- ---------------- 5 1 CURRENT 6 2 ACTIVE 7 3 ACTIVE 8 4 ACTIVE 9 5 ACTIVE 10 11 SYS@orcl> select group#,status,member from v$logfile; 12 13 GROUP# STATUS MEMBER 14 ---------- ------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 15 3 /u01/app/oracle/oradata/orcl/redo03.log 16 2 /u01/app/oracle/oradata/orcl/redo02.log 17 1 /u01/app/oracle/oradata/orcl/redo01.log 18 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log 19 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log 20 5 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_A.log 21 5 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228_1/20180228_B.log 22 1 /u01/app/oracle/oradata/orcl/redo04.log 23 24 8 rows selected. 25 26 SYS@orcl> alter database drop logfile group 5; 27 28 Database altered. 29 30 SYS@orcl>
3:清空 重做日志文件
1:查看日志文件状态:
1 2 SYS@orcl> select group#,status from v$log; 3 4 GROUP# STATUS 5 ---------- ---------------- 6 1 CURRENT 7 2 INACTIVE 8 3 INACTIVE 9 4 INACTIVE 10
2:清空 日志组4 的所有文件内容信息
4:更改重做日志的位置或者名称
1: 查看数据库重做日志的位置
1 SYS@orcl> set linesize 300; 2 SYS@orcl> col member for a250; 3 SYS@orcl> select * from v$logfile; 4 5 GROUP# STATUS TYPE MEMBER IS_ 6 ---------- ------- ------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7 3 ONLINE /u01/app/oracle/oradata/orcl/redo03.log NO 8 2 ONLINE /u01/app/oracle/oradata/orcl/redo02.log NO 9 1 ONLINE /u01/app/oracle/oradata/orcl/redo01.log NO 10 4 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log NO 11 4 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log NO 12 1 ONLINE /u01/app/oracle/oradata/orcl/redo04.log NO 13 14 6 rows selected. 15 16 17 SYS@orcl> select * from v$log; 18 19 GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME 20 ---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ --------- 21 1 1 102 52428800 512 2 NO INACTIVE 2714486 01-MAR-18 2745620 01-MAR-18 22 2 1 100 52428800 512 1 NO INACTIVE 2714333 01-MAR-18 2714470 01-MAR-18 23 3 1 101 52428800 512 1 NO INACTIVE 2714470 01-MAR-18 2714486 01-MAR-18 24 4 1 103 52428800 512 2 NO CURRENT 2745620 01-MAR-18 2.8147E+14 25 26 SYS@orcl>2: 关闭数据库;
1 SYS@orcl> shutdown 2 Database closed. 3 Database dismounted. 4 ORACLE instance shut down. 5 SYS@orcl>
3:手动复制源文件到目标位置,设置可以对i复制后的进行重命名。
1 [root@localhost ~]# su - oracle 2 [oracle@localhost ~]$ cd /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/ 3 [oracle@localhost logfile_bak_20180228]$ pwd 4 /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228 5 [oracle@localhost logfile_bak_20180228]$ ls 6 redo20180228_1.log redo20180228.log 7 [oracle@localhost logfile_bak_20180228]$ cp /u01/app/oracle/oradata/orcl/redo04.log /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo04.log 8 [oracle@localhost logfile_bak_20180228]$ ls 9 redo04.log redo20180228_1.log redo20180228.log 10 [oracle@localhost logfile_bak_20180228]$
4:再次启动数据库实例,加载数据库,打不打开数据库。
1 SYS@orcl> startup mount; 2 ORACLE instance started. 3 4 Total System Global Area 1221992448 bytes 5 Fixed Size 1344596 bytes 6 Variable Size 805309356 bytes 7 Database Buffers 402653184 bytes 8 Redo Buffers 12685312 bytes 9 Database mounted. 10 SYS@orcl>5:使用 alter database rename file 语句重新设置重做日志文件的路径及名称。
1 2 SYS@orcl> select * from v$logfile; 3 4 GROUP# STATUS TYPE MEMBER IS_ 5 ---------- ------- ------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- 6 3 ONLINE /u01/app/oracle/oradata/orcl/redo03.log NO 7 2 ONLINE /u01/app/oracle/oradata/orcl/redo02.log NO 8 1 ONLINE /u01/app/oracle/oradata/orcl/redo01.log NO 9 4 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log NO 10 4 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log NO 11 1 ONLINE /u01/app/oracle/oradata/orcl/redo04.log NO 12 13 6 rows selected. 14 15 SYS@orcl> alter database rename file '/u01/app/oracle/oradata/orcl/redo04.log' to '/home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo04.log'; 16 17 Database altered. 18 19 SYS@orcl>6: 打开 数据库
7:打开数据库后,新的重做日志文件的位置和名将生效,通过查询V$LOGFILE 数据字典视图可以获知数据库现在所使用的重做日志文件
1 2 SYS@orcl> select * from v$logfile; 3 4 GROUP# STATUS TYPE MEMBER IS_ 5 ---------- ------- ------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- 6 3 ONLINE /u01/app/oracle/oradata/orcl/redo03.log NO 7 2 ONLINE /u01/app/oracle/oradata/orcl/redo02.log NO 8 1 ONLINE /u01/app/oracle/oradata/orcl/redo01.log NO 9 4 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log NO 10 4 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log NO 11 1 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo04.log NO 12 13 6 rows selected. 14 15 SYS@orcl> shutdown immediate; 16 Database closed. 17 Database dismounted. 18 ORACLE instance shut down. 19 SYS@orcl> startup 20 ORACLE instance started. 21 22 Total System Global Area 1221992448 bytes 23 Fixed Size 1344596 bytes 24 Variable Size 805309356 bytes 25 Database Buffers 402653184 bytes 26 Redo Buffers 12685312 bytes 27 Database mounted. 28 Database opened. 29 SYS@orcl> select * from v$logfile; 30 31 GROUP# STATUS TYPE MEMBER IS_ 32 ---------- ------- ------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- 33 3 ONLINE /u01/app/oracle/oradata/orcl/redo03.log NO 34 2 ONLINE /u01/app/oracle/oradata/orcl/redo02.log NO 35 1 ONLINE /u01/app/oracle/oradata/orcl/redo01.log NO 36 4 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228.log NO 37 4 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo20180228_1.log NO 38 1 ONLINE /home/oracle/oracle_system_files_back/logfile_bak/logfile_bak_20180228/redo04.log NO 39 40 6 rows selected. 41 42 SYS@orcl>
5:查看 重做日志信息
1 SYS@orcl> set linesize 50; 2 SYS@orcl> desc v$log; 3 Name Null? Type 4 ----------------------- -------- ---------------- 5 GROUP# NUMBER 6 THREAD# NUMBER 7 SEQUENCE# NUMBER 8 BYTES NUMBER 9 BLOCKSIZE NUMBER 10 MEMBERS NUMBER 11 ARCHIVED VARCHAR2(3) 12 STATUS VARCHAR2(16) 13 FIRST_CHANGE# NUMBER 14 FIRST_TIME DATE 15 NEXT_CHANGE# NUMBER 16 NEXT_TIME DATE 17 18 SYS@orcl>
三:管理归档日志文件
1:日志模式分类
1:归档模式:(archivelog)
2:非归档模式 noarchivelog
2:管理归档操作
1: 日志切换
在 oracle11g 中,归档日志文件默认情况下是存放到快速恢复区所对应的目录(由系统参数: db_recovery_file_dest 设定)中,并且会按照特定的格式生成归档日志文件名。如果只想将归档日志文件放在默认的路径下,那么只需要执行 alter database archivelog 语句即可 。
日志切换示例 一:改变日志操作模式时,用户需要以 sysdba的身份执行相应操作。
1:查看当前日志模式
1 [oracle@localhost ~]$ sqlplus / as sysdba; 2 3 SQL*Plus: Release 11.2.0.3.0 Production on Sun Mar 4 23:34:07 2018 4 5 Copyright (c) 1982, 2011, Oracle. All rights reserved. 6 7 8 Connected to: 9 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production 10 With the Partitioning, OLAP, Data Mining and Real Application Testing options 11 12 SYS@orcl> select log_mode from v$database ; 13 14 LOG_MODE 15 ------------ 16 NOARCHIVELOG ---- 非归档模式 17 18 SYS@orcl>.通过查询结果可以看到,数据库当前处于非归档模式 noarchivelog
2:关闭并重新启动数据库
改变日志操作模式必须在mount状态进行,因此必须先关闭数据库,然后再重新装载数据库。
1 SYS@orcl> shutdown immediate; 2 Database closed. 3 Database dismounted. 4 ORACLE instance shut down. 5 SYS@orcl> startup mount; 6 7 ORACLE instance started. 8 9 Total System Global Area 1221992448 bytes 10 Fixed Size 1344596 bytes 11 Variable Size 805309356 bytes 12 Database Buffers 402653184 bytes 13 Redo Buffers 12685312 bytes 14 Database mounted. 15 SYS@orcl>3:改变日志模式
使用 alter database archivelog 语句将数据库切换到归档模式。
4:打开数据库
使用 alter database open 语句打开数据库。
1 SYS@orcl> alter database open; 2 3 Database altered. 4 5 SYS@orcl> select log_mode from v$database; 6 7 LOG_MODE 8 ------------ 9 ARCHIVELOG 10 11 SYS@orcl>示例:把归日日志切换为非归档日志:
1 2 SYS@orcl> select log_mode from V$database; 3 4 LOG_MODE 5 ------------ 6 ARCHIVELOG 7 8 SYS@orcl> shutdown immediate; 9 Database closed. 10 Database dismounted. 11 ORACLE instance shut down. 12 SYS@orcl> startup mount; 13 14 ORACLE instance started. 15 16 Total System Global Area 1221992448 bytes 17 Fixed Size 1344596 bytes 18 Variable Size 805309356 bytes 19 Database Buffers 402653184 bytes 20 Redo Buffers 12685312 bytes 21 Database mounted. 22 23 24 SYS@orcl> alter database noarchivelog; 25 26 Database altered. 27 28 SYS@orcl> alter database open; 29 30 Database altered. 31 32 SYS@orcl> select log_mode from v$database; 33 34 LOG_MODE 35 ------------ 36 NOARCHIVELOG 37 38 SYS@orcl>
2:配置归档进程
如果oracle 系统的后台进程 LGWR 经常出现等待的状态。就可以考虑启动多个 ARCN进程,通过修改系统初始化参数 “ log_archive_max_processes ” 就可以调整启动 ARCN 进程数量
1 2 SYS@orcl> select log_mode from V$database; 3 4 LOG_MODE 5 ------------ 6 ARCHIVELOG 7 8 SYS@orcl> shutdown immediate; 9 Database closed. 10 Database dismounted. 11 ORACLE instance shut down. 12 SYS@orcl> startup mount; 13 ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance 14 ORACLE instance started. 15 16 Total System Global Area 1221992448 bytes 17 Fixed Size 1344596 bytes 18 Variable Size 805309356 bytes 19 Database Buffers 402653184 bytes 20 Redo Buffers 12685312 bytes 21 Database mounted. 22 SYS@orcl> alter databae noarchivelog; 23 alter databae noarchivelog 24 * 25 ERROR at line 1: 26 ORA-00940: invalid ALTER command 27 28 29 SYS@orcl> alter database noarchivelog; 30 31 Database altered. 32 33 SYS@orcl> alter database open; 34 35 Database altered. 36 37 SYS@orcl> select log_mode from v$database; 38 39 LOG_MODE 40 ------------ 41 NOARCHIVELOG 42 43 SYS@orcl>
3:设置归档文件位置
1:本地归档目标 location
若在设置 log_archive_dest_n 参数时使用 location 关键字,则表示指定的归档目标在本地机器上
1 Last login: Sun Mar 4 23:33:15 2018 from 192.168.242.1 2 [root@localhost ~]# su - oracle 3 [oracle@localhost ~]$ ls 4 database Desktop grid h:1dept.sql h:1emp.txt h:1.lst h:1spooltest.txt h:emp.txt oracle_system_files_back oyt.lst rlwrap-0.37 rlwrap-0.37.tar.gz 5 [oracle@localhost ~]$ cd o 6 oracle_system_files_back/ oyt.lst 7 [oracle@localhost ~]$ cd oracle_system_files_back/ 8 [oracle@localhost oracle_system_files_back]$ ls 9 controlfile_bak datafiles_bak install_zip logfile_bak redo_bak 10 [oracle@localhost oracle_system_files_back]$ mkdir archivelog 11 [oracle@localhost oracle_system_files_back]$ cd archivelog/ 12 [oracle@localhost archivelog]$ ls 13 [oracle@localhost archivelog]$ mkdir archivelog_20180305 14 [oracle@localhost archivelog]$ cd archivelog_20180305/ 15 [oracle@localhost archivelog_20180305]$ pwd 16 /home/oracle/oracle_system_files_back/archivelog/archivelog_20180305 17 [oracle@localhost archivelog_20180305]$ ls 18 [oracle@localhost archivelog_20180305]$ mkdir archive1 19 [oracle@localhost archivelog_20180305]$ ls 20 archive1 21 [oracle@localhost archivelog_20180305]$ mkdir archive2 22 [oracle@localhost archivelog_20180305]$1 SYS@orcl> show parameter log_archive_dest_1 2 3 NAME TYPE VALUE 4 ------------------------------------ ----------- ------------------------------ 5 log_archive_dest_1 string 6 log_archive_dest_10 string 7 log_archive_dest_11 string 8 log_archive_dest_12 string 9 log_archive_dest_13 string 10 log_archive_dest_14 string 11 log_archive_dest_15 string 12 log_archive_dest_16 string 13 log_archive_dest_17 string 14 log_archive_dest_18 string 15 log_archive_dest_19 string 16 SYS@orcl> select log_mode from v$database ; 17 18 LOG_MODE 19 ------------ 20 NOARCHIVELOG 21 22 SYS@orcl> shutdown immediate; 23 Database closed. 24 Database dismounted. 25 ORACLE instance shut down. 26 SYS@orcl> startup mount; 27 ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance 28 ORACLE instance started. 29 30 Total System Global Area 1221992448 bytes 31 Fixed Size 1344596 bytes 32 Variable Size 805309356 bytes 33 Database Buffers 402653184 bytes 34 Redo Buffers 12685312 bytes 35 Database mounted. 36 SYS@orcl> alter database archivelog; 37 38 Database altered. 39 40 SYS@orcl> alter database open; 41 42 Database altered. 43 44 SYS@orcl> select log_mode from v$database; 45 46 LOG_MODE 47 ------------ 48 ARCHIVELOG 49 50 SYS@orcl> show parameter log_archive_dest_1 51 52 NAME TYPE VALUE 53 ------------------------------------ ----------- ------------------------------ 54 log_archive_dest_1 string 55 log_archive_dest_10 string 56 log_archive_dest_11 string 57 log_archive_dest_12 string 58 log_archive_dest_13 string 59 log_archive_dest_14 string 60 log_archive_dest_15 string 61 log_archive_dest_16 string 62 log_archive_dest_17 string 63 log_archive_dest_18 string 64 log_archive_dest_19 string 65 SYS@orcl> alter system set log_archive_dest_1='location=/home/oracle/oracle_system_files_back/archivelog/archivelog_20180305/archive1'; 66 67 System altered. 68 69 SYS@orcl> alter system set log_archive_dest_10='location=/home/oracle/oracle_system_files_back/archivelog/archivelog_20180305/archive2'; 70 71 System altered. 72 73 SYS@orcl> show parameter log_archive_dest_1 74 75 NAME TYPE VALUE 76 ------------------------------------ ----------- ------------------------------ 77 log_archive_dest_1 string location=/home/oracle/oracle_s 78 ystem_files_back/archivelog/ar 79 chivelog_20180305/archive1 80 log_archive_dest_10 string location=/home/oracle/oracle_s 81 ystem_files_back/archivelog/ar 82 chivelog_20180305/archive2 83 log_archive_dest_11 string 84 log_archive_dest_12 string 85 log_archive_dest_13 string 86 log_archive_dest_14 string 87 log_archive_dest_15 string 88 89 NAME TYPE VALUE 90 ------------------------------------ ----------- ------------------------------ 91 log_archive_dest_16 string 92 log_archive_dest_17 string 93 log_archive_dest_18 string 94 log_archive_dest_19 string 95 SYS@orcl>1 2 [oracle@localhost archivelog_20180305]$ mkdir archive2 3 [oracle@localhost archivelog_20180305]$ mkdir archive2_1 4 [oracle@localhost archivelog_20180305]$ mkdir archive3_1 5 [oracle@localhost archivelog_20180305]$ mkdir archive5 6 [oracle@localhost archivelog_20180305]$ mkdir archive4 7 [oracle@localhost archivelog_20180305]$ pwd 8 /home/oracle/oracle_system_files_back/archivelog/archivelog_20180305[oracle@localhost archivelog_20180305]$ ls 9 archive1 archive2 archive2_1 archive3_1 archive4 archive5 10 [oracle@localhost archivelog_20180305]$
1 2 3 SYS@orcl> show parameter log_archive_dest_ 4 5 NAME TYPE VALUE 6 ------------------------------------ ----------- ------------------------------ 7 log_archive_dest_1 string 8 log_archive_dest_10 string 9 log_archive_dest_11 string 10 log_archive_dest_12 string 11 log_archive_dest_13 string 12 log_archive_dest_14 string 13 log_archive_dest_15 string 14 log_archive_dest_16 string 15 log_archive_dest_17 string 16 log_archive_dest_18 string 17 log_archive_dest_19 string 18 19 NAME TYPE VALUE 20 ------------------------------------ ----------- ------------------------------ 21 log_archive_dest_2 string 22 log_archive_dest_20 string 23 log_archive_dest_21 string 24 log_archive_dest_22 string 25 log_archive_dest_23 string 26 log_archive_dest_24 string 27 log_archive_dest_25 string 28 log_archive_dest_26 string 29 log_archive_dest_27 string 30 log_archive_dest_28 string 31 log_archive_dest_29 string 32 33 NAME TYPE VALUE 34 ------------------------------------ ----------- ------------------------------ 35 log_archive_dest_3 string 36 log_archive_dest_30 string 37 log_archive_dest_31 string 38 log_archive_dest_4 string 39 log_archive_dest_5 string 40 log_archive_dest_6 string 41 log_archive_dest_7 string 42 log_archive_dest_8 string 43 log_archive_dest_9 string 44 log_archive_dest_state_1 string enable 45 log_archive_dest_state_10 string enable 46 47 NAME TYPE VALUE 48 ------------------------------------ ----------- ------------------------------ 49 log_archive_dest_state_11 string enable 50 log_archive_dest_state_12 string enable 51 log_archive_dest_state_13 string enable 52 log_archive_dest_state_14 string enable 53 log_archive_dest_state_15 string enable 54 log_archive_dest_state_16 string enable 55 log_archive_dest_state_17 string enable 56 log_archive_dest_state_18 string enable 57 log_archive_dest_state_19 string enable 58 log_archive_dest_state_2 string enable 59 log_archive_dest_state_20 string enable 60 61 NAME TYPE VALUE 62 ------------------------------------ ----------- ------------------------------ 63 log_archive_dest_state_21 string enable 64 log_archive_dest_state_22 string enable 65 log_archive_dest_state_23 string enable 66 log_archive_dest_state_24 string enable 67 log_archive_dest_state_25 string enable 68 log_archive_dest_state_26 string enable 69 log_archive_dest_state_27 string enable 70 log_archive_dest_state_28 string enable 71 log_archive_dest_state_29 string enable 72 log_archive_dest_state_3 string enable 73 log_archive_dest_state_30 string enable 74 75 NAME TYPE VALUE 76 ------------------------------------ ----------- ------------------------------ 77 log_archive_dest_state_31 string enable 78 log_archive_dest_state_4 string enable 79 log_archive_dest_state_5 string enable 80 log_archive_dest_state_6 string enable 81 log_archive_dest_state_7 string enable 82 log_archive_dest_state_8 string enable 83 log_archive_dest_state_9 string enable 84 SYS@orcl> show parameter log_archive_dest_1 85 86 SYS@orcl> ho clear 87 88 89 SYS@orcl> show parameter log_archive_dest_1 90 91 NAME TYPE VALUE 92 ------------------------------------ ----------- ------------------------------ 93 log_archive_dest_1 string 94 log_archive_dest_10 string 95 log_archive_dest_11 string 96 log_archive_dest_12 string 97 log_archive_dest_13 string 98 log_archive_dest_14 string 99 log_archive_dest_15 string 100 log_archive_dest_16 string 101 log_archive_dest_17 string 102 log_archive_dest_18 string 103 log_archive_dest_19 string 1041 SYS@orcl> alter system set log_archive_dest_2='location=/home/oracle/oracle_system_files_back/archivelog/archivelog_20180305/archive2_1 optional '; 2 3 System altered. 4 5 SYS@orcl> alter system set log_archive_dest_3='location=/home/oracle/oracle_system_files_back/archivelog/archivelog_20180305/archive3_1 mandatory '; 6 7 System altered. 8 9 SYS@orcl> alter system set log_archive_dest_4='location=/home/oracle/oracle_system_files_back/archivelog/archivelog_20180305/archive4 mandatory reopen=400 '; 10 11 System altered. 12 13 SYS@orcl> alter system set log_archive_dest_5='location=/home/oracle/oracle_system_files_back/archivelog/archivelog_20180305/archive5 '; 14 15 System altered. 16 17 SYS@orcl> show parameter log_archive_dest_ 18 19 NAME TYPE VALUE 20 ------------------------------------ ----------- ------------------------------ 21 log_archive_dest_1 string location=/home/oracle/oracle_s 22 ystem_files_back/archivelog/ar 23 chivelog_20180305/archive1 24 log_archive_dest_10 string location=/home/oracle/oracle_s 25 ystem_files_back/archivelog/ar 26 chivelog_20180305/archive2 27 log_archive_dest_11 string 28 log_archive_dest_12 string 29 log_archive_dest_13 string 30 log_archive_dest_14 string 31 log_archive_dest_15 string 32 33 NAME TYPE VALUE 34 ------------------------------------ ----------- ------------------------------ 35 log_archive_dest_16 string 36 log_archive_dest_17 string 37 log_archive_dest_18 string 38 log_archive_dest_19 string 39 log_archive_dest_2 string location=/home/oracle/oracle_s 40 ystem_files_back/archivelog/ar 41 chivelog_20180305/archive2_1 o 42 ptional 43 log_archive_dest_20 string 44 log_archive_dest_21 string 45 log_archive_dest_22 string 46 47 NAME TYPE VALUE 48 ------------------------------------ ----------- ------------------------------ 49 log_archive_dest_23 string 50 log_archive_dest_24 string 51 log_archive_dest_25 string 52 log_archive_dest_26 string 53 log_archive_dest_27 string 54 log_archive_dest_28 string 55 log_archive_dest_29 string 56 log_archive_dest_3 string location=/home/oracle/oracle_s 57 ystem_files_back/archivelog/ar 58 chivelog_20180305/archive3_1 59 mandatory 60 61 NAME TYPE VALUE 62 ------------------------------------ ----------- ------------------------------ 63 log_archive_dest_30 string 64 log_archive_dest_31 string 65 log_archive_dest_4 string location=/home/oracle/oracle_s 66 ystem_files_back/archivelog/ar 67 chivelog_20180305/archive4 man 68 datory reopen=400 69 log_archive_dest_5 string location=/home/oracle/oracle_s 70 ystem_files_back/archivelog/ar 71 chivelog_20180305/archive5 72 log_archive_dest_6 string 73 log_archive_dest_7 string 74 75 NAME TYPE VALUE 76 ------------------------------------ ----------- ------------------------------ 77 log_archive_dest_8 string 78 log_archive_dest_9 string 79 log_archive_dest_state_1 string enable 80 log_archive_dest_state_10 string enable 81 log_archive_dest_state_11 string enable 82 log_archive_dest_state_12 string enable 83 log_archive_dest_state_13 string enable 84 log_archive_dest_state_14 string enable 85 log_archive_dest_state_15 string enable 86 log_archive_dest_state_16 string enable 87 log_archive_dest_state_17 string enable 88 89 NAME TYPE VALUE 90 ------------------------------------ ----------- ------------------------------ 91 log_archive_dest_state_18 string enable 92 log_archive_dest_state_19 string enable 93 log_archive_dest_state_2 string enable 94 log_archive_dest_state_20 string enable 95 log_archive_dest_state_21 string enable 96 log_archive_dest_state_22 string enable 97 log_archive_dest_state_23 string enable 98 log_archive_dest_state_24 string enable 99 log_archive_dest_state_25 string enable 100 log_archive_dest_state_26 string enable 101 log_archive_dest_state_27 string enable 102 103 NAME TYPE VALUE 104 ------------------------------------ ----------- ------------------------------ 105 log_archive_dest_state_28 string enable 106 log_archive_dest_state_29 string enable 107 log_archive_dest_state_3 string enable 108 log_archive_dest_state_30 string enable 109 log_archive_dest_state_31 string enable 110 log_archive_dest_state_4 string enable 111 log_archive_dest_state_5 string enable 112 log_archive_dest_state_6 string enable 113 log_archive_dest_state_7 string enable 114 log_archive_dest_state_8 string enable 115 log_archive_dest_state_9 string enable 116 SYS@orcl>初始化 最小的 归档日志组的个数
1 2 SYS@orcl> show parameter log_archive_min_succeed_dest 3 4 NAME TYPE VALUE 5 ------------------------------------ ----------- ------------------------------ 6 log_archive_min_succeed_dest integer 1 7 SYS@orcl> alter system set log_archive_min_succeed_dest=4; 8 9 System altered. 10 11 12 SYS@orcl> show parameter log_archive_min_succeed_dest 13 14 NAME TYPE VALUE 15 ------------------------------------ ----------- ------------------------------ 16 log_archive_min_succeed_dest integer 4 17 SYS@orcl>1 SYS@orcl> alter system set log_archive_dest_state_4=defer; 2 3 System altered. 4 5 SYS@orcl
2:远程归档目标
4: 查看归档日志信息
1 SYS@orcl> archive log list 2 Database log mode Archive Mode 3 Automatic archival Enabled 4 Archive destination /home/oracle/oracle_system_files_back/archivelog/archivelog_20180305/archive2 5 Oldest online log sequence 109 6 Next log sequence to archive 112 7 Current log sequence 112 8 SYS@orcl>————————————————————————————————————————————————————————————————————————————————
————————————————————————————————————————————————————————————————————————————————————————————
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
.....................................................................
------- 桃之夭夭,灼灼其华。之子于归,宜其室家。 ---------------
------- 桃之夭夭,有蕡其实。之子于归,宜其家室。 ---------------
------- 桃之夭夭,其叶蓁蓁。之子于归,宜其家人。 ---------------
=====================================================================
* 博客文章部分截图及内容来自于学习的书本及相应培训课程以及网络其他博客,仅做学习讨论之用,不做商业用途。
* 如有侵权,马上联系我,我立马删除对应链接。 * @author Alan -liu * @Email no008@foxmail.com
转载请标注出处! ✧*꧁一品堂.技术学习笔记꧂*✧. ---> https://www.cnblogs.com/ios9/