목차
교육개요 2
서버정보 2
초기작업 2
오라클 기본 구조 2
실습환경 2
오라클 서버의 구성 요소 4
사용자 연결에 따른 서버의 동작 4
장애 발생시 5
실습) 오라클 시작 과정 확인 5
데이터 베이스 시작/종료 8
데이터 베이스의 시작 8
데이터 베이스의 종료 10
실습) 데이터베이스 상태 전환 10
Archivelog 모드 12
사용자 백업/복구 13
No Archive Log 모드에서의 백업 및 복구 14
Archive Log 모드에서의 백업 및 복구 18
아카이브 로그 프로세스 동작 확인 20
전체 데이터 베이스 복구 시나리오 26
한 개 데이터 파일 장애시 복구 시나리오 30
다수 데이터 베이스 파일 장애시 복구 시나리오 34
테이블 스페이스 온라인 복구 42
교육개요
교육담당자 : 오수진
Email : sujinjin.oh@samsung.com
TEL:3429-5190
CP:011-1704-9992
과정명 : 신입사원 직무역량 강화교육 - 인프라(오라클)
강사명 : 오지영 강사
강의의 목적은 장애상황에서 데이터 베이스 복구하는 방법이 주요 내용임
오라클 구성을 위한 서버와 클라이언트를 매핑하는 작업을 배우게 됌
※ RMAN : 회사에 따라서 사용하는 곳도 있고, 아닌 곳도 있다.
서버정보
서버 리스트
70.12.200.151
70.12.200.152 / dba25
초기작업
dba25@sun02-zone:/oracle/dba/dba25] sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Nov 5 08:33:52 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted.
Database opened.
SQL>
오라클 관리자로 접속하여, 데이터베이스를 기동.
오라클 기본 구조
실습환경
현재 우리의 실습 환경은 한개의 서버에 다수의 오라클 데이터베이스가 존재하는 상황.
Control, Datafile, Redo log file 를 한개로 묶어서 한개의 DB라고 부르며, 각각의 DB에는 다른 명칭을 붙이는 것이 가능. (이런 명칭은 control 파일에 명시)
sqlplus 환경에서 startup 이라는 명령어를 치면 해당 DB를 시작하겠다는 의미임
dba25@sun02-zone:/oracle/dba/dba25] cat .profile
#
# @(#)local.profile 1.4 93/09/15 SMI
#
.
.
.
#***********************************************
# Environment for Oracle
#***********************************************
export ORACLE_BASE=/oracle/dba/dba25
export ORACLE_HOME=/oracle/dba/dba25
export ORACLE_SID=DBA25
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/usr/lib:$ORACLE_HOME/lib32
export ORACLE_TERM=vt100
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export PATH=$PATH:$ORACLE_HOME/bin:/usr/bin:/usr/ucb:/usr/lib:/usr/ccs/bin
export NLS_LANG=AMERICAN_AMERICA.US7ASCII
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_OWNER=dba25
export DISPLAY=:0.0
export TERM=vt100
export ORACLE_TERM=vt100
dba25@sun02-zone:/oracle/dba/dba25]
startup 이라는 명령으로 어떤 DB가 시동돼는지는 .profile 에서 확인이 가능하다. ORACLE_SID로 관리 DB가 결정되는 구조이기 때문에 각기 다른 DB는 각기 다른 유저를 이용해서 관리하는 것이 일반적.
DB의 시작시에는 데이터 베이스의 무결성을 체크한다.
Control File : Checkpoint + Log Sequence, RBA(Redo Block Address)
※ 컨트롤 파일의 이러한 정보는 Datafile, Redo logfile 의 무결성을 확인하는데 이용한다. CKPT라는 프로세스가 이러한 정보를 일괄적으로 유지하는 역할을 한다.
오라클 서버의 구성 요소
SGA : System Global Area
DBWR (DB WRiter)
CKPT
LGWR (Log WRiter)
오라클 인스턴스 : 백그라운트 프로세스 + SGA
오라클 데이터베이스 : Control file + Data file + Redo logfile
> 3개의 데이터 베이스 파일은 시점 정보가 일치해야지만 실행이 가능하다.
파라미터 파일 : 데이터 베이스의 메모리 값과 같은 설정 내역이 저장된 파일
패스워드 파일 : 관리자 유저의 인증을 위해서 사용하는 파일
아카이브 로그 파일 : 아카이브 로그 모드에서 생성되는 로그 파일.
실제로는 리두 로그 파일의 복사본이 저장된다.
SGA-----------------------------------------------------------------------------------
| [Shared Pool] [DB Buffer Cache] [Redo Log Buffer] [Large Pool] [Java Pool] |
--------------------------------------------------------------------------------------
[Control file] [Datafile][Undo Segment, Rollback Segment] [Redo Logfile]
Large Pool, Java Pool is available to set 0 (optional memory)
사용자 연결에 따른 서버의 동작
사용자 연결 ----> [서버 프로세스]
(SQL*Plus, Toad)
statement 1. Parsing : 오타 검증
-> Parse Tree, Execution Plan 생성
-> statements:PT, EP CACHE (Shared pool)
2. Execute : 실재 명령문의 실행
-> Datafile Block Load (DB Buffer Cache)
-> Rollback Segment Block Load (DB Buffer Cache)
3. Locking Process
4. DML Logging (Redo Log Buffer)
-> 로그 내용은 오라클 내부적 최적화된 내용 기록
작업시점, 작업내역 저장
5. DB 버퍼 캐시내의 데이터 블록에서 롤백 세그먼트 블록으로
DML 수정에 따른 변경 내역이 저장됨.
commit 1. Redo Log Buffer 에 작업 기록
2. Signal to LGWR
3. Redo Logfile Will Be Written by LGWR
4. Commit Complete Message Display
5. DB 버퍼 캐시 Unlocking
※ 메모리에서 실재 디스크로 저장되는 시점은 i) 메모리가 풀인 경우 ii) 체크 포인트 맞추는 이벤트 발생 두가지의 경우에만 기록된다. (DBWR이 블록단위 카피 실행, 비교 복사 X)
장애 발생시
DB startup
체크 포인트 검증 시작
RBA(Redo Block Address)의 내용과 Redo Logfile 의 시점 데이터를 비교해서 해당 시점 이후의 로그 파일이 존재하는 경우 SMON 이 로그를 읽어서 Datafile 에 적용.
※ Redo Logfile 의 문제가 발생할 경우에는 오라클의 자동적인 복구 과정으로는 복구할 수 없음.
실습) 오라클 시작 과정 확인
SQL> startup
ORACLE instance started. > NOMOUNT 단계
Total System Global Area 22630360 bytes > 메모리 정보를 보여준다
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted. > MOUNT 단계
Database opened. > OPEN 단계
SQL> QUIT
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
dba25@sun02-zone:/oracle/dba/dba25] cd $ORACLE_HOME/dbs
dba25@sun02-zone:/oracle/dba/dba25/dbs] ls
create_dba25.sql initDBA25.ora log02a.rdo system01.dbf users01.dbf
ctrl01.ctl lkDBA25 querydata01.dbf temp01.dbf
indx01.dbf log01a.rdo sample01.dbf undotbs.dbf
dba25@sun02-zone:/oracle/dba/dba25/dbs] cat initDBA25.ora > 오라클 파라미터 파일
##########################
#
# Date: 28 Feb 2001
# Updated: 24 Apr 2001
# File Name: initsid.ora
# File Version: 1.1.3
#
###########################
background_dump_dest=$ORACLE_HOME/ADMIN/BDUMP
compatible=9.2.0
control_files=$ORACLE_HOME/dbs/ctrl01.ctl
core_dump_dest=$ORACLE_HOME/ADMIN/CDUMP
db_block_size=4096
db_cache_size=4M
db_domain=world
db_name=DBA25
global_names=TRUE
instance_name=DBA25
java_pool_size=0
#log_archive_dest_1="LOCATION=$ORACLE_HOME/ORADATA/ARCHIVE1/ MANDATORY"
#log_archive_dest_2="LOCATION=$ORACLE_HOME/ORADATA/ARCHIVE2/ OPTIONAL"
#log_archive_format=arch_%s.arc
#log_archive_max_processes=2
#log_archive_start=true
max_dump_file_size=10240
remote_login_passwordfile=NONE
service_names=DBA25
shared_pool_size=4M
undo_management=AUTO
undo_tablespace=UNDOTBS
user_dump_dest=$ORACLE_HOME/ADMIN/UDUMP
dba25@sun02-zone:/oracle/dba/dba25/dbs]
※ 파라미터 파일에 설정이 저장된 내용은 기본 설정값을 사용하고 싶지 않은 경우에 사용된다.
dba25@sun02-zone:/oracle/dba/dba25/dbs] sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Nov 5 09:43:41 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
1. 데이터 베이스 이름 확인
SQL> select name from v$database;
NAME
---------
DBA25
2. 데이터 베이스 구성 파일 이름, 위치 확인 (장애복구에 실재 사용되는 내용)
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/oracle/dba/dba25/dbs/ctrl01.ctl
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/oracle/dba/dba25/dbs/system01.dbf
/oracle/dba/dba25/dbs/undotbs.dbf
/oracle/dba/dba25/dbs/users01.dbf
/oracle/dba/dba25/dbs/indx01.dbf
/oracle/dba/dba25/dbs/sample01.dbf
/oracle/dba/dba25/dbs/querydata01.dbf
6 rows selected.
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/oracle/dba/dba25/dbs/log01a.rdo
/oracle/dba/dba25/dbs/log02a.rdo
3. 현재 DB에 만들어진 계정 정보 확인
SQL> select username from dba_users;
USERNAME
------------------------------
SYS
SYSTEM
OUTLN
DBSNMP
SQL>
데이터 베이스 시작/종료
데이터 베이스의 시작
NOMOUNT
파라미터파일을 읽고 확인 (기본 위치를 가지고 있음)
$ORACLE_HOME/dbs/spfile*.ora
$ORACLE_HOME/dbs/init*.ora
SGA 할당, BG프로세스 기동
MOUNT
컨트롤 파일 확인후 사용 가능 상태로 만듬
(컨트롤 파일의 위치는 파라미터 파일에서 결정)
컨트롤 파일
시점정보 : SCN#, LOGSEQ#
데이터파일위치
리두로그파일위치
dba25@sun02-zone:/oracle/dba/dba25/dbs] strings ctrl01.ctl
Z[\]
DBA25
]DBA25
bDBA25
bDBA25
/oracle/dba/dba25/dbs/log01a.rdo
/oracle/dba/dba25/dbs/log02a.rdo
/oracle/dba/dba25/dbs/system01.dbf
/oracle/dba/dba25/dbs/undotbs.dbf
/user4/dba25/dbs/temp01.dbf
/oracle/dba/dba25/dbs/users01.dbf
/oracle/dba/dba25/dbs/indx01.dbf
/oracle/dba/dba25/dbs/sample01.dbf
/oracle/dba/dba25/dbs/log01a.rdo
/user4/dba25/dbs/log02a.rdo
/oracle/dba/dba25/dbs/system01.dbf
/oracle/dba/dba25/dbs/undotbs.dbf
/user4/dba25/dbs/temp01.dbf
/oracle/dba/dba25/dbs/users01.dbf
/oracle/dba/dba25/dbs/indx01.dbf
/oracle/dba/dba25/dbs/sample01.dbf
/oracle/dba/dba25/dbs/querydata01.dbf
/user4/dba25/dbs/querydata01.dbf
SYSTEM
UNDOTBS
TEMP
USERS
INDX
SAMPLE
QUERY_DATA
SYSTEM
UNDOTBS
TEMP
USERS
INDX
SAMPLE
QUERY_DATA
dba25@sun02-zone:/oracle/dba/dba25/dbs]
OPEN
데이터 파일, 리두 로그 파일 확인 및 OPEN
(해당 파일의 위치는 컨트롤 파일의 위치에서 확인한다)
|
※ 어떤 단계에서 어떤 정보의 확인이 가능할까?
select * from v$instance; ; NOMOUNT 단계 이후에 조회 가능
select * from emp; ; OPEN 단계 이후에 조회 가능
select member from v$logfile; ; MOUNT 단계 이후에 조회 가능
※ start up error 대처
i) 시작 후 바로 error
파라미터 파일의 에러
ii) instance started 후 error
컨트롤 파일의 에러
iii) mounted 후 error
데이터, 리두 로그 파일 error
|
|
SHUTDOWN
(start nomount)
|
|
|
NOMOUNT
(alter database mount)
|
control file 문제 발생시 재성성/복구
|
|
MOUNT
(alter database open)
|
DB운영 모드 변경. archive log <-> no archive log, alter database noarchivelog
데이터파일, 리두 파일 위치 이동시킨후
alter database rename file '이전파일명' to '새로운 파일명'
복구 명령중 전체 DB 복구시
recover database ~;
|
|
OPEN
|
|
일반 사용자 접속 제한을 위한 모드
운영중 : alter system enable restricted session;
시작시 : startup restrict;
해제 : alter system disable restricted session;
데이터 베이스의 종료
종료방법
shutdown [normal]
shutdown transactional
shutdown immediate
shutdown abort
강제 종료. commit 적용이 되지 않기 때문에 startup 시 SMON의 동작이 이루어진다.
실습) 데이터베이스 상태 전환
dba25@sun02-zone:/oracle/dba/dba25/dbs] sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Nov 5 10:32:39 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
1. 현재 어느 단계인지 확인
SQL> select status from v$instance;
STATUS
------------
OPEN
2. DB를 nomount 단계로 이동
(원래 단계에서 이전단계로 이동은 shutdown 후에만 가능)
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
SQL> select status from v$instance;
STATUS
------------
STARTED
SQL> select name from v$datafile;
select name from v$datafile
*
ERROR at line 1:
ORA-01507: database not mounted
3. DB를 mount 단계로 이동
SQL> alter database mount;
Database altered.
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/oracle/dba/dba25/dbs/system01.dbf
/oracle/dba/dba25/dbs/undotbs.dbf
/oracle/dba/dba25/dbs/users01.dbf
/oracle/dba/dba25/dbs/indx01.dbf
/oracle/dba/dba25/dbs/sample01.dbf
/oracle/dba/dba25/dbs/querydata01.dbf
6 rows selected.
SQL> select * from emp;
select * from emp
*
ERROR at line 1:
ORA-01219: database not open: queries allowed on fixed tables/views only
SQL> create table t1(id number(4));
create table t1(id number(4))
*
ERROR at line 1:
ORA-01109: database not open
4. DB를 open 단계로 이동
SQL> alter database open;
Database altered.
SQL> create table t1 (id number(4));
Table created.
SQL> select status from v$instance;
STATUS
------------
OPEN
Archivelog 모드
noarchive 모드 vs archive 모드
: redo log file 복사본 생성 여부에 따라서 구분됨
redo log buffer 내용 ---[LGWR]---> stored at redo log file
: 모든 수정 작업 history 기록. insert/delete/update/create/alter/drop....
※ LGWR
기록시점 : commit, 버퍼 1/3, DBWR동작 직전
기록방법 : redo group 1개에만 정보 기록
(오라클 redo log group은 여러개의 파일a.k.a member로 구성이 가능함)
|
[group 1]
|
[group 2]
|
|
log1.rdo
delete/commit~~~....
|
log2.rdo
insert/commit~~~...
another member file
|
group 1이 모두 찬 경우 group 2로 log switch가 일어난다. 차후 group2 역시 모두 찬 경우 log switch 가 일어나는데 이때 기존에 group 1에 기존의 로그가 존재하더라도 신경쓰지 않고 모두 덮어써버린다.
문제는 이럴 경우 차후 데이터 베이스 백업에 문제가 발생하기 때문에 이런 일이 발생하지 않게 하기위해서 archive log 모드를 운영하여, 기존에 존재하는 로그의 복제본을 만드는 것임.
archive log 의 복사 시점은 log switch 가 일어나는 시점에 시작됨.
※ 오라클 DB의 경우 log group 은 최소한 2개 이상이어야함.
※왜 로그 그룹에 멤버를 추가하는가?
만 약 로그 그룹에 저장 파일이 한개인 경우 해당 파일이 스위치 시점에 LGWR의 접근이 불가한 상황이라면 해당 문제로 인해서 최악의 경우 DB가 뻗는 상황이 발생하기 때문에 이런 상황을 피하기 위해서 파일을 여러개 만들어두고서 사용하는 것임.
※ 왜 로그 버퍼를 이용하는가?
: 로그 발생시마다 디스크에 데이터를 옮겨적는다면 CPU IOwait 이 과다하게 발생하여 퍼포먼스에 악영향
1. 아카이브 로그 정보 확인
SQL> select log_mode from v$database;
LOG_MODE
------------
NOARCHIVELOG
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /oracle/dba/dba25/dbs/arch
Oldest online log sequence 98
Current log sequence 99
SQL>
참고) 단어 정의
SCNSystemChangeNumber:커밋또는 내부 변경시 발생
Log Sequence # : Redo Logfile 에 부여된 번호. 그룹별 번호 할당
Checkpoint 정보 : SCN+Log Seq # 헤더에 기록 (by CKPT)
사용자 백업/복구
|
*.50 : 11/4 AM2:00
[1.ch]
|
|
*.50
T1:100건
[a.bdf]
|
|
50
11/4 AM2:00
log1.rdo
|
|
49
log2.rdo
|
| |
|
|
|
|
|
|
| |
|
[b.bdf]
|
|
|
|
|
DB 전체 백업
상기의 모든 내용을 별도의 디스크 영역에 저장한다는 말임.
50번 로그에 작업 내역이 모두 찬 경우 group 2의 logseq가 51로 변하면서 control file, datafile 의 시점정보 logseq로 다른 번호로 변하게 된다.
이 렇게 로깅 작업이 진행될 경우 full backup 이후 장애 발생시 백업 이후의 시점의 데이터를 복구하기 위해서는 redo log 이 필요하게 돼는데 문제는 이럴 경우 noarchivelog 의 경우 중간 데이터가 존재하지 않을 경우 데이터의 복구가 불가능하다.
No Archive Log 모드에서의 백업 및 복구
no archive log 모드에서의 full backup
교재 64page
noarchive log 모드에서의 복구
교재 77page
(실재 no archive log 모드의 경우 redo logfile 유지가 안돼기 때문에 사실상 데이터를 백업 복구하는데는 제약사항이 많다)
1. noarchivelog 모드에서 백업 수행해 보기
SQL> select log_mode from v$database;
LOG_MODE
------------
NOARCHIVELOG
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /oracle/dba/dba25/dbs/arch
Oldest online log sequence 98
Current log sequence 99
SQL> select log_mode from v$database;
LOG_MODE
------------
NOARCHIVELOG
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
2. 데이터 베이스 백업 실시
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
dba25@sun02-zone:/oracle/dba/dba25/dbs] cp $HOME/dbs/*.* $HOME/BACKUP/.
dba25@sun02-zone:/oracle/dba/dba25/dbs] ls -al /oracle/dba/dba25/BACKUP/
total 485730
drwxrwxr-x 6 dba25 dba 512 Nov 5 11:37 .
drwxrwxr-x 62 dba25 dba 1024 Aug 31 2003 ..
drwxrwxr-x 2 dba25 dba 512 Aug 31 2003 LOG
drwxrwxr-x 2 dba25 dba 512 Aug 31 2003 NOARCH
drwxrwxr-x 2 dba25 dba 512 Aug 31 2003 RMAN
drwxrwxr-x 2 dba25 dba 512 Aug 31 2003 UMAN
-rw-r--r-- 1 dba25 dba 1946 Nov 5 11:35 create_dba25.sql
-rwxr-x--- 1 dba25 dba 954368 Nov 5 11:35 ctrl01.ctl
-rwxr-x--- 1 dba25 dba 5246976 Nov 5 11:35 indx01.dbf
-rwxr-x--- 1 dba25 dba 842 Nov 5 11:35 initDBA25.ora
-rwxr-x--- 1 dba25 dba 5243392 Nov 5 11:35 log01a.rdo
-rwxr-x--- 1 dba25 dba 5243392 Nov 5 11:35 log02a.rdo
-rwxr-x--- 1 dba25 dba 1052672 Nov 5 11:35 querydata01.dbf
-rwxr-x--- 1 dba25 dba 10489856 Nov 5 11:35 sample01.dbf
-rwxr-x--- 1 dba25 dba 104861696 Nov 5 11:36 system01.dbf
-rwxr-x--- 1 dba25 dba 15732736 Nov 5 11:36 temp01.dbf
-rwxr-x--- 1 dba25 dba 94375936 Nov 5 11:37 undotbs.dbf
-rwxr-x--- 1 dba25 dba 5246976 Nov 5 11:37 users01.dbf
dba25@sun02-zone:/oracle/dba/dba25/dbs] sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Nov 5 11:38:38 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
SQL> alter database mount;
Database altered.
SQL> alter database open;
Database altered.
SQL> insert into t1 values (1);
1 row created.
SQL> insert into t1 values (2);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> select count(*) from t1;
COUNT(*)
----------
2
4. 장애 상황 재현하기
SQL> !rm $HOME/dbs/users01.dbf
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: '/oracle/dba/dba25/dbs/users01.dbf'
5. 장애난 파일만 복사하여 복구
SQL> !cp $HOME/BACKUP/users01.dbf $HOME/dbs/
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 3 needs media recovery
ORA-01110: data file 3: '/oracle/dba/dba25/dbs/users01.dbf'
SQL> recover database;
ORA-00279: change 191675 generated at 11/05/2008 11:34:05 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/dbs/arch1_99.dbf
ORA-00280: change 191675 for thread 1 is in sequence #99
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00308: cannot open archived log '/oracle/dba/dba25/dbs/arch1_99.dbf'
ORA-27037: unable to obtain file status
SVR4 Error: 2: No such file or directory
Additional information: 3
6. 현재 redo logfile에 남겨진 정보의 시간 확인
SQL> select group#, first_time from v$log;
GROUP# FIRST_TIM
---------- ---------
1 05-NOV-08
2 05-NOV-08
SQL> alter session set nls_date_format='yy-mm-dd:hh24:mi:ss';
Session altered.
SQL> select group#, first_time from v$log;
GROUP# FIRST_TIME
---------- -----------------
1 08-11-05:11:41:10
2 08-11-05:11:41:49
※ 현재 저장된 데이터 베이스의 시간 정보는 34분대의 내용인데 로그에 저장된 시작시점의 내용이 41분대의 내용인 것으로 보아서 데이터 갭이 발생했음을 확인가능하다.
7. 전체 파일 복사하는 방법으로 복구
SQL> shutdown abort;
ORACLE instance shut down.
SQL> !cp $HOME/BACKUP/*.* $HOME/dbs/.
SQL> startup
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted.
Database opened.
SQL> select * from t1;
no rows selected
※ 데이터 없음. redo 적용이 안돼어서 데이터 손실이 발생했음을 알수 있다.
SQL>
Archive Log 모드에서의 백업 및 복구
- 로그 스위치 할때마다 redo logfile 복사본 생성
- MOUNT 단계에서 변경 수행
- 교재 83page
|
group 1
|
|
group 2
|
|
LOGSEQ : 40
11/5 AM10
log1.rdo
|
|
LOGSEQ : 41
log2.rdo
|
1) group 1 is full. and then LGWR will start logging on group 2.
2) when log switch is occured, group 1 is copied to archive log by DBAby command or BGProcessARC0, ARC1, log_archive_start=true
(if you use oracle 10g, archive log shipping by background process is default.)
3) where does the orginal log copy to ?
on oracle 8i
log_archive_dest=location1
log_archive_duplex_dest=location2
on oracle 8i later (is available)
log_archive_dest_1=location1
log_archive_dest_2=location2
....
log_archive_dest_10=location10
filename is determined by following value
log_archive_format=a%s.log (%s : LOGSEQ, %t : thread # on RAC, OPS environment)
(this configuration is done at parameter file)
※ 아카이브 로그와 관련된 파라미터 설정값을 LIKE 검색하여 보여준다.
SQL> show parameter log_archive
로그의 저장위치를 지정함.
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest string
log_archive_dest_1 string
log_archive_dest_10 string
log_archive_dest_2 string
log_archive_dest_3 string
log_archive_dest_4 string
log_archive_dest_5 string
log_archive_dest_6 string
log_archive_dest_7 string
log_archive_dest_8 string
log_archive_dest_9 string
로그 파일이 full 된경우 해당 로그파일에 쓰기를 잠시 중단 가능한가를 결정
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_1 string enable
log_archive_dest_state_10 string enable
log_archive_dest_state_2 string enable
log_archive_dest_state_3 string enable
log_archive_dest_state_4 string enable
log_archive_dest_state_5 string enable
log_archive_dest_state_6 string enable
log_archive_dest_state_7 string enable
log_archive_dest_state_8 string enable
log_archive_dest_state_9 string enable
log_archive_duplex_dest string
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_format string %t_%s.dbf
log_archive_max_processes integer 2
log_archive_min_succeed_dest integer 1
log_archive_start boolean FALSE
log_archive_trace integer 0
SQL>
log_archive_dest_1="location=$HOME/DEMO mandatory reopen=300"
로컬의 지정 디렉토리에 반드시 로그를 남겨야한다.
이경우 차후 해당 그룹으로 다시 로그 스위치가 일어날 때 기존 로깅 실패시 pending 상태.
log_archive_dest_2="service=oratest optional reopen"
원격 서버에 로그를 쓰되 실패해도 차후 해당 그룹에 로깅이 가능함.
REPOEN 설정은 해당 로깅에 실패했을때 재시도를 시도할지 말지의 여부를 결정
REOPEN=600형태의 설정가능
log_archive_dest_3="location=$HOME/DEMO2 optional"
로컬의 지정 디렉토리에 로그를 남기되 실패해도 무방함.
log_archive_min_succeed_dest=1
최소한 몇개의 로깅이 성공해야 로깅이 성공했다고 보는가?
설정값이 2라면, 1만 성공하고 2,3이 실패한 경우에는 로깅이 실패했다 고 본다.
아카이브 로그 프로세스 동작 확인
1. 아카이브 모드로 변경하기 위해서 파라미터 파일 설정 변경
(아래 반전된 부분의 주석을 제거함)
SQL> !vi $HOME/dbs/init*.ora
##########################
#
# Date: 28 Feb 2001
# Updated: 24 Apr 2001
# File Name: initsid.ora
# File Version: 1.1.3
#
###########################
background_dump_dest=$ORACLE_HOME/ADMIN/BDUMP
compatible=9.2.0
control_files=$ORACLE_HOME/dbs/ctrl01.ctl
core_dump_dest=$ORACLE_HOME/ADMIN/CDUMP
db_block_size=4096
db_cache_size=4M
db_domain=world
db_name=DBA25
global_names=TRUE
instance_name=DBA25
java_pool_size=0
log_archive_dest_1="LOCATION=$ORACLE_HOME/ORADATA/ARCHIVE1/ MANDATORY"
log_archive_dest_2="LOCATION=$ORACLE_HOME/ORADATA/ARCHIVE2/ OPTIONAL"
log_archive_format=arch_%s.arc
#log_archive_max_processes=2
log_archive_start=true
max_dump_file_size=10240
remote_login_passwordfile=NONE
service_names=DBA25
shared_pool_size=4M
undo_management=AUTO
undo_tablespace=UNDOTBS
user_dump_dest=$ORACLE_HOME/ADMIN/UDUMP
2. MOUNT단계로 이동해서 DB모드 변경
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
4.
SQL> !ps -ef|grep dba25
dba25 5908 4432 0 13:42:13 pts/17 0:00 grep dba25
dba25 5726 8843 0 13:40:15 ? 0:00 ora_smon_DBA25
dba25 5718 8843 0 13:40:15 ? 0:00 ora_pmon_DBA25
dba25 3035 3019 0 08:33:26 pts/17 0:00 -ksh
dba25 5909 5908 0 13:42:13 pts/17 0:00 ps -ef
dba25 5732 8843 0 13:40:16 ? 0:00 ora_arc1_DBA25
dba25 3845 3842 0 10:06:16 pts/19 0:00 -ksh
dba25 5730 8843 0 13:40:16 ? 0:00 ora_arc0_DBA25
dba25 5724 8843 0 13:40:15 ? 0:00 ora_ckpt_DBA25
dba25 5720 8843 0 13:40:15 ? 0:00 ora_dbw0_DBA25
dba25 4432 3035 0 11:38:39 pts/17 0:00 sqlplus /as sysdba
dba25 5728 8843 0 13:40:16 ? 0:00 ora_reco_DBA25
dba25 5722 8843 0 13:40:15 ? 0:00 ora_lgwr_DBA25
dba25 5752 4432 0 13:40:20 ? 0:00 oracleDBA25 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
SQL> alter system switch logfile;
System altered.
SQL> !ls $HOME/ORADATA/ARCHIVE1;
arch_99.arc
SQL> !ls $HOME/ORADATA/ARCHIVE2;
arch_99.arc
SQL> show parameter log_archive_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest string
log_archive_dest_1 string LOCATION=$ORACLE_HOME/ORADATA/
ARCHIVE1/ MANDATORY
log_archive_dest_10 string
log_archive_dest_2 string LOCATION=$ORACLE_HOME/ORADATA/
ARCHIVE2/ OPTIONAL
log_archive_dest_3 string
log_archive_dest_4 string
log_archive_dest_5 string
log_archive_dest_6 string
log_archive_dest_7 string
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_8 string
log_archive_dest_9 string
log_archive_dest_state_1 string enable
log_archive_dest_state_10 string enable
log_archive_dest_state_2 string enable
log_archive_dest_state_3 string enable
log_archive_dest_state_4 string enable
log_archive_dest_state_5 string enable
log_archive_dest_state_6 string enable
log_archive_dest_state_7 string enable
log_archive_dest_state_8 string enable
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_9 string enable
5. 일시 아카이브 생성 특정 위치에서 중지
SQL> alter system set log_archive_dest_state_1=defer;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> !ls $HOME/ORADATA/ARCHIVE1
arch_99.arc
SQL> !ls $HOME/ORADATA/ARCHIVE2
arch_100.arc arch_99.arc
현재 부터 생성되는 로그에 대해서 사용함.
SQL> alter system set log_archive_dest_state_1=enable;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> !ls $HOME/ORADATA/ARCHIVE1
arch_101.arc arch_99.arc
SQL> !ls $HOME/ORADATA/ARCHIVE2
arch_100.arc arch_101.arc arch_99.arc
6. arc0, arc1 프로세스 중단하여, DBA가 직접 archive log 를 실시하는 명령
SQL> alter system archive log stop;
System altered.
arc#프로세스가 없음을 확인한다.
SQL> !ps -ef|grep dba21
dba21 5755 8843 0 13:40:30 ? 0:00 ora_pmon_DBA21
dba21 3252 3249 0 08:43:14 pts/6 0:00 -ksh
dba21 5759 8843 0 13:40:30 ? 0:00 ora_lgwr_DBA21
dba21 5765 8843 0 13:40:30 ? 0:00 ora_reco_DBA21
dba21 4414 3252 0 11:38:30 pts/6 0:00 sqlplus /as sysdba
dba21 5761 8843 0 13:40:30 ? 0:00 ora_ckpt_DBA21
dba21 5763 8843 0 13:40:30 ? 0:00 ora_smon_DBA21
dba21 5757 8843 0 13:40:30 ? 0:00 ora_dbw0_DBA21
dba21 5771 4414 0 13:40:34 ? 0:00 oracleDBA21 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
dba25 6088 4432 0 13:50:23 pts/17 0:00 grep dba21
dba21 5767 8843 0 13:40:30 ? 0:00 ora_arc0_DBA21
dba21 5769 8843 0 13:40:30 ? 0:00 ora_arc1_DBA21
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
명령은 떨어졌으나 결과가 나오지 않는다. (hang)
기존에 썻던 로그 그룹이 아카이브 로그 복사본을 만들지 않았기 때문에 이런 결과가 나온다.
7. 다른 터미널을 열고 작업시작
SQL> select group#,archived from v$log;
GROUP# ARC
---------- ---
1 NO
2 NO
SQL> alter system archive log all;
System altered.
다른터미널에서 프롬프트가 나온 것을 확인해보자.
SQL> !ps -ef | grep dba25
dba25 5726 8843 0 13:40:15 ? 0:00 ora_smon_DBA25
dba25 5718 8843 0 13:40:15 ? 0:00 ora_pmon_DBA25
dba25 3035 3019 0 08:33:26 pts/17 0:00 -ksh
dba25 6266 6263 0 13:53:23 pts/19 0:00 -ksh
dba25 5724 8843 0 13:40:15 ? 0:00 ora_ckpt_DBA25
dba25 5720 8843 0 13:40:15 ? 0:00 ora_dbw0_DBA25
dba25 4432 3035 0 11:38:39 pts/17 0:00 sqlplus /as sysdba
dba25 5728 8843 0 13:40:16 ? 0:00 ora_reco_DBA25
dba25 5722 8843 0 13:40:15 ? 0:00 ora_lgwr_DBA25
dba25 5752 4432 0 13:40:20 ? 0:00 oracleDBA25 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
dba25 6326 6325 0 13:54:09 ? 0:00 oracleDBA25 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
dba25 6325 6266 0 13:54:09 pts/19 0:00 sqlplus /as sysdba
dba25 6406 6325 0 13:56:52 pts/19 0:00 grep dba25
dba25 6407 6406 0 13:56:52 pts/19 0:00 ps -ef
SQL> alter system archive log start;
System altered.
SQL> !ps -ef | grep dba25
dba25 5726 8843 0 13:40:15 ? 0:00 ora_smon_DBA25
dba25 5718 8843 0 13:40:15 ? 0:00 ora_pmon_DBA25
dba25 3035 3019 0 08:33:26 pts/17 0:00 -ksh
dba25 6266 6263 0 13:53:23 pts/19 0:00 -ksh
dba25 5724 8843 0 13:40:15 ? 0:00 ora_ckpt_DBA25
dba25 5720 8843 0 13:40:15 ? 0:00 ora_dbw0_DBA25
dba25 4432 3035 0 11:38:39 pts/17 0:00 sqlplus /as sysdba
dba25 5728 8843 0 13:40:16 ? 0:00 ora_reco_DBA25
dba25 5722 8843 0 13:40:15 ? 0:00 ora_lgwr_DBA25
dba25 5752 4432 0 13:40:20 ? 0:00 oracleDBA25 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
dba25 6326 6325 0 13:54:09 ? 0:00 oracleDBA25 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
dba25 6325 6266 0 13:54:09 pts/19 0:00 sqlplus /as sysdba
dba25 6434 6325 0 13:57:42 pts/19 0:00 grep dba25
dba25 6415 8843 0 13:57:25 ? 0:00 ora_arc0_DBA25
dba25 6417 8843 0 13:57:25 ? 0:00 ora_arc1_DBA25
dba25 6435 6434 0 13:57:42 pts/19 0:00 ps -ef
아카이브 로그 background process 를 시작하려면
i) log_archive_start=true 설정하여 DB재시작
ii) 운영중 arc0, arc1기동하려면, alter system archive log start 명령 사용
SQL>
i) alter system archive log next;
현재 아카이빙 되지 않은 다음 로그를 디스크에 쓴다.
ii) alter system archive log all;
아카이빙 되지 않은 모든 로그를 디스크에 쓴다.
iii) alter system archive log current;
현재 아카이빙 되지 않은 모든 로그와 현재 로그를 디스크에 쓰고, log switch 를 일으킨다.
LOG_ARCHIVE_MAX_PROCESSES 매개변수
기본 아카이브 로그 프로세스의 개수를 지정한다.
전체 데이터 베이스 복구 시나리오
1.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/dba/dba25/ORADATA/ARCHIVE2/
Oldest online log sequence 104
Next log sequence to archive 105
Current log sequence 105
SQL> alter system archive log stop;
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /oracle/dba/dba25/ORADATA/ARCHIVE2/
아키이브 로그와 무관하게 현재 가장 오래된 온라인 로그의 번호
Oldest online log sequence 104
다음으로 아카이빙 되어야할 로그의 번호
Next log sequence to archive 105
현재 쓰고 있는 아카이브 로그의 번호
Current log sequence 105
Next log sequence to archive, Current log sequence의 번호차이는 아카이브 로깅의 속도를 말한다고 할 수 있다.
2. 정상종료후 아카이브 로그 모드에서의 백업
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> !cp $HOME/dbs/*.* $HOME/BACKUP/.
3.
SQL> startup
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted.
Database opened.
SQL> create user scott identified by tiger default tablespace sample;
User created.
SQL> grant dba to scott;
Grant succeeded.
SQL> conn scott/tiger
Connected.
해당 파일의 내용을 그대로 행단위 실행한다. ?는 오라클의 홈디렉토리임.
SQL> @ ?/sqlplus/demo/demobld
Building demonstration tables. Please wait.
Demonstration table build is complete.
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
dba25@sun02-zone:/oracle/dba/dba25/dbs]
4.
dba25@sun02-zone:/oracle/dba/dba25/dbs] sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Nov 5 14:55:43 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> insert into scott.dept select * from scott.dept;
4 rows created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> /
/
System altered.
System altered.
SQL> select count(*) from scott.dept;
COUNT(*)
----------
8
5. 장애 상황 만들기
SQL> select file_name from dba_data_files where tablespace_name in (select tablespace_name from dba_tables where table_name='DEPT');
FILE_NAME
--------------------------------------------------------------------------------
/oracle/dba/dba25/dbs/sample01.dbf
SQL> !rm /oracle/dba/dba25/dbs/sample01.dbf
SQL> shutdown abort;
ORACLE instance shut down.
6.
SQL> startup
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/oracle/dba/dba25/dbs/sample01.dbf'
7. 복구 과정
SQL> !cp $HOME/BACKUP/sample01.dbf $HOME/dbs/.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
현재 존재하는 다른 데이터 파일과 시점이 맞지 않아서 스타트를 할 수 없다.
ORA-01110: data file 5: '/oracle/dba/dba25/dbs/sample01.dbf'
8. 아카이브 redo logfile 적용
SQL> recover database;
ORA-00279: change 195128 generated at 11/05/2008 14:37:04 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc
ORA-00280: change 195128 for thread 1 is in sequence #105
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 195357 generated at 11/05/2008 14:56:12 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc
ORA-00280: change 195357 for thread 1 is in sequence #106
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
Log applied.
Media recovery complete.
SQL> alter database open;
Database altered.
SQL> select count(*) from scott.dept;
COUNT(*)
----------
8
SQL>
백업 / 복구 용어
1. Closed Backup (=Cold, Offline)
-> DB종료후 백업
-> 운영모드 상관 X (nonarchiving, archiving)
2. Open Backup (=Hot, Online)
-> DB 운영중 백업 수행
-> Archivinglog 모드로 운영시에만 가능
3. Restore
-> 복원 : 장애난 file을 백업 > 원위치로 복사
4. Recover
-> 복구 : 장애난 파일의 백업본 시점 변경
5. 완전 복구 : commit 된 데이터 손실 X
MOUNT 상태 : system 테이블 스페이스 장애
마운트 상태의 작업은 모든 사용자의 접속을 불허하기 때문에 주의가 필요함.
recover database 라는 명령어의 경우 모든 DB의
OPEN 상태 : 현재 DB 상태에서도 가능
불완전 복구 : commit된 데이터 손실 O
(아카이브 로그 모드에서만...)
복구라는 것은 i) 깨진 파일을 백업본에서 복사하고 ii) 해당 파일의 시점을 맞춰주는 단계로 진행된다.
한 개 데이터 파일 장애시 복구 시나리오
1. t2 테이블 만들기
SQL> create table t2 tablespace users as select * from scott.dept;
Table created.
SQL> alter system switch logfile;
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/dba/dba25/ORADATA/ARCHIVE2/
Oldest online log sequence 109
Next log sequence to archive 110
Current log sequence 110
2. 장애 만들기
SQL> !rm $HOME/dbs/sample01.dbf
SQL> shutdown abort;
ORACLE instance shut down.
3. 장애 복구하기
SQL> startup
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/oracle/dba/dba25/dbs/sample01.dbf'
SQL> alter database datafile 5 offline;
장애난 파일만 오프라인 상태로 변경하여서 기동시 확인을 하지 않게 한다.
Database altered.
SQL> alter database open;
Database altered.
SQL> select * from t2;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
8 rows selected.
SQL> insert into t2 select * from t2;
8 rows created.
SQL> commit;
Commit complete.
SQL> select * from scott.dept;
select * from scott.dept
*
ERROR at line 1:
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5: '/oracle/dba/dba25/dbs/sample01.dbf'
장애가 생긴 파일에 저장된 영역에만 접근이 불가함.(장애 최소화)
SQL> !cp $HOME/BACKUP/sample01.dbf $HOME/dbs/.
SQL> alter database datafile 5 online;
alter database datafile 5 online
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/oracle/dba/dba25/dbs/sample01.dbf'
SQL> recover database;
ORA-00283: recovery session canceled due to errors
ORA-01124: cannot recover data file 1 - file is in use or recovery
ORA-01110: data file 1: '/oracle/dba/dba25/dbs/system01.dbf'
해당 명령어는 전체 시스템을 복구하는 명령어이기 때문에 MOUNT상태에서만 실행 가능함.
SQL> recover datafile 5;
데이터 파일 번호를 써도 무방하며, 직접 파일 패스를 주어도 무방하다.
ORA-00279: change 195128 generated at 11/05/2008 14:37:04 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc
ORA-00280: change 195128 for thread 1 is in sequence #105
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 195357 generated at 11/05/2008 14:56:12 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc
ORA-00280: change 195357 for thread 1 is in sequence #106
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 195362 generated at 11/05/2008 14:56:21 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc
ORA-00280: change 195362 for thread 1 is in sequence #107
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 195364 generated at 11/05/2008 14:56:26 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc
ORA-00280: change 195364 for thread 1 is in sequence #108
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 215430 generated at 11/05/2008 15:06:17 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc
ORA-00280: change 215430 for thread 1 is in sequence #109
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc' no longer
needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
Log applied.
Media recovery complete.
SQL> alter database datafile 5 online;
열외되었던 데이터 파일을 다시 온라인 모드로 변경 시킨다.
Database altered.
SQL> select * from scott.dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
8 rows selected.
SQL>
다수 데이터 베이스 파일 장애시 복구 시나리오
1. 장애난 파일 존재 유무 확인
SQL> select * from v$recover_file;
no rows selected
2. 다수 파일의 장애상황 유도
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> !rm $HOME/dbs/sample01.dbf
SQL> !rm $HOME/dbs/user01.dbf
/oracle/dba/dba25/dbs/user01.dbf: No such file or directory
SQL> !rm $HOME/dbs/users01.dbf
SQL> !rm $HOME/dbs/indx01.dbf
SQL> shutdown abort;
ORACLE instance shut down.
3. DB 시작시 에러 메시지 확인
SQL> startup
ORACLE instance started.
Total System Global Area 22630360 bytes
Fixed Size 454616 bytes
Variable Size 16777216 bytes
Database Buffers 4194304 bytes
Redo Buffers 1204224 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
ORA-01110: data file 3: '/oracle/dba/dba25/dbs/users01.dbf'
오라클의 경우에는 설사 여러개의 파일의 장애를 확인했다고 하더라도, 메시지로 알려주는 파일의 수는 한개뿐이다. 따라서 아래의 명령어를 이용해서 장애난 파일을 반드시 확인해야한다.
SQL> col name format a50
SQL> select file#, name from v$datafile;
FILE# NAME
---------- --------------------------------------------------
1 /oracle/dba/dba25/dbs/system01.dbf
2 /oracle/dba/dba25/dbs/undotbs.dbf
3 /oracle/dba/dba25/dbs/users01.dbf
4 /oracle/dba/dba25/dbs/indx01.dbf
5 /oracle/dba/dba25/dbs/sample01.dbf
6 /oracle/dba/dba25/dbs/querydata01.dbf
6 rows selected.
SQL> select * from v$recover_file;
FILE# ONLINE ONLINE_
---------- ------- -------
ERROR CHANGE#
----------------------------------------------------------------- ----------
TIME
---------
3 ONLINE ONLINE
FILE NOT FOUND 0
4 ONLINE ONLINE
FILE NOT FOUND 0
FILE# ONLINE ONLINE_
---------- ------- -------
ERROR CHANGE#
----------------------------------------------------------------- ----------
TIME
---------
5 ONLINE ONLINE
FILE NOT FOUND 0
SQL> select name from v$datafile a, v$recover_file b where a.file#=b.file#;
NAME
--------------------------------------------------
/oracle/dba/dba25/dbs/users01.dbf
/oracle/dba/dba25/dbs/indx01.dbf
/oracle/dba/dba25/dbs/sample01.dbf
4. 복구 시나리오 실행
SQL> !cp $HOME/BACKUP/users01.dbf $HOME/dbs/.
SQL> !cp $HOME/BACKUP/indx01.dbf $HOME/dbs/.
SQL> !cp $HOME/BACKUP/sample01.dbf $HOME/dbs/.
SQL> recover datafile 3;
ORA-00279: change 195128 generated at 11/05/2008 14:37:04 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc
ORA-00280: change 195128 for thread 1 is in sequence #105
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00279: change 195357 generated at 11/05/2008 14:56:12 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc
ORA-00280: change 195357 for thread 1 is in sequence #106
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc' no longer
needed for this recovery
ORA-00279: change 195362 generated at 11/05/2008 14:56:21 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc
ORA-00280: change 195362 for thread 1 is in sequence #107
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc' no longer
needed for this recovery
ORA-00279: change 195364 generated at 11/05/2008 14:56:26 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc
ORA-00280: change 195364 for thread 1 is in sequence #108
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc' no longer
needed for this recovery
ORA-00279: change 215430 generated at 11/05/2008 15:06:17 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc
ORA-00280: change 215430 for thread 1 is in sequence #109
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc' no longer
needed for this recovery
ORA-00279: change 216232 generated at 11/05/2008 15:37:41 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_110.arc
ORA-00280: change 216232 for thread 1 is in sequence #110
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc' no longer
needed for this recovery
ORA-00279: change 236234 generated at 11/05/2008 15:41:16 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_111.arc
ORA-00280: change 236234 for thread 1 is in sequence #111
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_110.arc' no longer
needed for this recovery
Log applied.
Media recovery complete.
SQL> recover datafile 4;
ORA-00279: change 195128 generated at 11/05/2008 14:37:04 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc
ORA-00280: change 195128 for thread 1 is in sequence #105
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00279: change 195357 generated at 11/05/2008 14:56:12 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc
ORA-00280: change 195357 for thread 1 is in sequence #106
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc' no longer
needed for this recovery
ORA-00279: change 195362 generated at 11/05/2008 14:56:21 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc
ORA-00280: change 195362 for thread 1 is in sequence #107
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc' no longer
needed for this recovery
ORA-00279: change 195364 generated at 11/05/2008 14:56:26 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc
ORA-00280: change 195364 for thread 1 is in sequence #108
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc' no longer
needed for this recovery
ORA-00279: change 215430 generated at 11/05/2008 15:06:17 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc
ORA-00280: change 215430 for thread 1 is in sequence #109
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc' no longer
needed for this recovery
ORA-00279: change 216232 generated at 11/05/2008 15:37:41 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_110.arc
ORA-00280: change 216232 for thread 1 is in sequence #110
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc' no longer
needed for this recovery
ORA-00279: change 236234 generated at 11/05/2008 15:41:16 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_111.arc
ORA-00280: change 236234 for thread 1 is in sequence #111
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_110.arc' no longer
needed for this recovery
Log applied.
Media recovery complete.
SQL> recover datafile 5;
ORA-00279: change 195128 generated at 11/05/2008 14:37:04 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc
ORA-00280: change 195128 for thread 1 is in sequence #105
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00279: change 195357 generated at 11/05/2008 14:56:12 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc
ORA-00280: change 195357 for thread 1 is in sequence #106
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc' no longer
needed for this recovery
ORA-00279: change 195362 generated at 11/05/2008 14:56:21 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc
ORA-00280: change 195362 for thread 1 is in sequence #107
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc' no longer
needed for this recovery
ORA-00279: change 195364 generated at 11/05/2008 14:56:26 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc
ORA-00280: change 195364 for thread 1 is in sequence #108
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc' no longer
needed for this recovery
ORA-00279: change 215430 generated at 11/05/2008 15:06:17 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc
ORA-00280: change 215430 for thread 1 is in sequence #109
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc' no longer
needed for this recovery
ORA-00279: change 216232 generated at 11/05/2008 15:37:41 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_110.arc
ORA-00280: change 216232 for thread 1 is in sequence #110
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc' no longer
needed for this recovery
ORA-00279: change 236234 generated at 11/05/2008 15:41:16 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_111.arc
ORA-00280: change 236234 for thread 1 is in sequence #111
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_110.arc' no longer
needed for this recovery
Log applied.
Media recovery complete.
만약 로그 자체를 보여주고 싶지 않은 경우에는 recover automatic * 식으로 명령어를 주면 된다.
SQL> alter database open;
Database altered.
5.
SQL> select count(*) from scott.dept;
COUNT(*)
----------
8
6. DB 운영중에 발생하는 다양한 경고 메시지를 보여준다. 중요한 정보를 많이 담고 있다.
-> alertDB*.log 파일에는 장애 메세지, 복구 진행 과정 확인 가능.
SQL> show parameter background_dump_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
background_dump_dest string $ORACLE_HOME/ADMIN/BDUMP
SQL> !vi $HOME/ADMIN/BDUMP/a*.log
.
.
.
ALTER DATABASE RECOVER CONTINUE DEFAULT
Wed Nov 5 11:45:17 2008
Media Recovery Log /oracle/dba/dba25/dbs/arch1_99.dbf
Errors with log /oracle/dba/dba25/dbs/arch1_99.dbf.
ORA-308 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Wed Nov 5 11:45:17 2008
ALTER DATABASE RECOVER CANCEL
Media Recovery Cancelled
Completed: ALTER DATABASE RECOVER CANCEL
Wed Nov 5 11:49:33 2008
Shutting down instance (abort)
License high water mark = 1
Instance terminated by USER, pid = 4844
Wed Nov 5 11:51:51 2008
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
.
.
.
테이블 스페이스 온라인 복구
1.
SQL> select * from v$recover_file;
no rows selected
SQL> select * from scott.dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
8 rows selected.
SQL>
2. 파일 장애 생성후 테이블 생성 여부 확인
SQL> !rm $HOME/dbs/users01.dbf
SQL> create table t3 tablespace users as select * from scott.dept;
create table t3 tablespace users as select * from scott.dept
*
ERROR at line 1:
ORA-01116: error in opening database file 3
ORA-01110: data file 3: '/oracle/dba/dba25/dbs/users01.dbf'
ORA-27041: unable to open file
SVR4 Error: 2: No such file or directory
Additional information: 3
3. DB 단계 확인
SQL> select status from v$instance;
STATUS
------------
OPEN
4. 장애난 파일/테이블 스페이스만 offline 으로
SQL> alter tablespace users offline immediate;
Tablespace altered.
5. 데이터 베이스 파일 복구
SQL> !cp $HOME/BACKUP/users01.dbf $HOME/dbs/.
SQL> recover tablespace users;
ORA-00279: change 195128 generated at 11/05/2008 14:37:04 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc
ORA-00280: change 195128 for thread 1 is in sequence #105
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00279: change 195357 generated at 11/05/2008 14:56:12 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc
ORA-00280: change 195357 for thread 1 is in sequence #106
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_105.arc' no longer
needed for this recovery
ORA-00279: change 195362 generated at 11/05/2008 14:56:21 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc
ORA-00280: change 195362 for thread 1 is in sequence #107
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_106.arc' no longer
needed for this recovery
ORA-00279: change 195364 generated at 11/05/2008 14:56:26 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc
ORA-00280: change 195364 for thread 1 is in sequence #108
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_107.arc' no longer
needed for this recovery
ORA-00279: change 215430 generated at 11/05/2008 15:06:17 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc
ORA-00280: change 215430 for thread 1 is in sequence #109
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_108.arc' no longer
needed for this recovery
ORA-00279: change 216232 generated at 11/05/2008 15:37:41 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_110.arc
ORA-00280: change 216232 for thread 1 is in sequence #110
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_109.arc' no longer
needed for this recovery
ORA-00279: change 236234 generated at 11/05/2008 15:41:16 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_111.arc
ORA-00280: change 236234 for thread 1 is in sequence #111
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_110.arc' no longer
needed for this recovery
ORA-00279: change 236676 generated at 11/05/2008 15:55:27 needed for thread 1
ORA-00289: suggestion : /oracle/dba/dba25/ORADATA/ARCHIVE2/arch_112.arc
ORA-00280: change 236676 for thread 1 is in sequence #112
ORA-00278: log file '/oracle/dba/dba25/ORADATA/ARCHIVE2/arch_111.arc' no longer
needed for this recovery
Log applied.
Media recovery complete.
SQL> alter tablespace users online;
Tablespace altered.
SQL> create table t3 tablespace users as select * from scott.dept;
Table created.
SQL>
완전 복구 수행단계
i) 문제 발생한 file restore
ii) 시점 동기화
recover database;
recover datafile 'filename';
recover tablespace tablespacename;