ORACLE/ADMIN2006. 9. 8. 20:46
반응형

로그 파일의 추가, 삭제, 이름변경, 전체 삭제

SQL> select * from v$log;

 

SQL> select * from v$log;

 

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TI

---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------

         1          1         34    1048576          1 NO  INACTIVE                548219 01/07/22

         2          1         35    1048576          1 NO  CURRENT                 568268 01/07/23

         3          1         33    1048576          1 NO  INACTIVE                528171 01/07/19

3개의 로그 파일이 있다..

상태를 보면 나의 경우2번째가 CURRENT이다. 이는 현재 상용 중이라는 소리고, 나머지는 대기중이란 뜻이다.

 

로그파일의 추가는 리두 로그 그룹에 로그 파일 멤버를 추가할 때 각 멤버 파일명의 유사성을 유지하면서 생성하는 것이 일반적이다.

로그 파일 생성시 주의할 점은 각 로그 그룹은 모두 동일한 수의 멤버 파일의 가져야 한다는 것이다.

로그 파일의 추가 명령은 ALTER DATABASE이다.

 

SQL> ALTER DATABASE yasiDB

  2  ADD LOGFILE MEMBER 'E:\ORACLE\ORADATA\YASIDB\REDO01_1' TO GROUP 1;

 

데이타베이스가 변경되었습니다.

 

SQL>ALTER DATABASE yasiDB

2         ADD LOGFILE MEMBER 'E:\ORACLE\ORADATA\YASIDB\REDO02_2' TO GROUP 2;

데이타베이스가 변경되었습니다

 

SQL>ALTER DATABASE yasiDB

  2   ADD LOGFILE MEMBER 'E:\ORACLE\ORADATA\YASIDB\REDO03_3' TO GROUP 3;

 

데이타베이스가 변경되었습니다.

 

 

확인해보자..

SQL> select * from v$logfile;

 

    GROUP# STATUS

---------- -------

MEMBER

--------------------------------------

         1 STALE

E:\ORACLE\ORADATA\YASIDB\REDO03.LOG

 

         2

E:\ORACLE\ORADATA\YASIDB\REDO02.LOG

 

         3 STALE

E:\ORACLE\ORADATA\YASIDB\REDO01.LOG

 

         1 INVALID

E:\ORACLE\ORADATA\YASIDB\REDO01_1

 

         2 INVALID

E:\ORACLE\ORADATA\YASIDB\REDO02_2

 

         3 INVALID

E:\ORACLE\ORADATA\YASIDB\REDO03_3

 

 

6 개의 행이 선택되었습니다.

 

 

로그 파일을 삭제 할때는

 

ALTER DATABASE database_name

DROP LOGFILE MEMBER ‘경로’ TO GROUP group_number;

을 한다

 

로그파일의 삭제는  실제적인물리적 파일까지는 지워지지가 않는다. 다만 오라클에서 논리적으로 지우는 것이다. 완전히 삭제하려면 운영체제상에서 물리적인 파일을 지워줘야 한다.

 

로그파일 이름 바꾸기

ALTER DATABASE database_name

RENAME FILE ‘바꿀로그파일경로’ TO ‘바꿀경로와 이름’;

 

로그파일의 전체 삭제

ALTER DABASE database_name

DROP LOGFILES GROUP 3;

반응형
Posted by [PineTree]
ORACLE/ADMIN2006. 7. 6. 22:18
반응형

XP에 설치된 원격지 오라클에 접속하면 "TNS-12535 TNS 작동이 중단입니다"

 

오라클이 설치된 XP에서는 TNSPING 또는 SQLPLUS 접속이 원활이 진행되나

다른 원격지 컴퓨터에서 오라클이 설치된 XP(방화벽)에 접속할경우

"TNS-12535 TNS 작동이 중단입니다" 라는 오류 메시지를 만나게 된다.

 

원격지에서 1521포트를 통해 접속하지만 DB에서는 프리포트를 생성해 클라이언트에 결과를

돌려주게 된다. 때문에 발생하는 오류인것 같다.

 

[해결방법]

 

환경 :

   XP SP2

   ORACLE 9

  

DB가 설치된 방화벽설정에 1521포트를 허용하도록 추가해준다.

레지스트리편집기를 열어 해당 경로 HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE

에서 새로만들기->확장가능한 문자열값 을 선택 USE_SHARED_SOCKET = TRUE 를 지정한다.

 

멀티홈이라면 오라클홈 ORACLE.KEY 에 홈을 확인해보고 USE_SHARED_SOCKET = TRUE 를

어디에 지정할지를 확인하고 지정한다.

예)C:\oracle\ora92\bin\oracle.key

 

적용했는데도 접속이 되지 않을경우 윈도우 서비스를 열어 오라클 관련 서비스를 재시작해준다.

반응형
Posted by [PineTree]
ORACLE/ADMIN2006. 6. 26. 19:51
반응형
아카이브 로그 보기 추가


#### 고려 사항

1. 백업 모드
  - Archive Mode 
  - Noarchive Mode
 
2. 저장 장치
  - Disk 사용
  - 백업 장치 사용
 
3. 백업 주기




#### Archive Mode
  - 데이터베이스가 아카이브 모드 상태에서 오픈되어 있는 경우에는
  온라인 백업이 가능한 상태이며 따라서 문제 발생시 처리중인 트랜잭션
  중 Commit 된 부분들은 전부 복구가 가능하다.
 


#### Archive 백업 순서
  - 데이터베이스의 아카이브 모드가 설정되어 있는지 해제되어 있는지를 확인한다.
  - 아카이브 모드를 설정한다.
  - 아카이브 관련 초기화 변수들이 정확한지 확인한다.
  - 아카이빙을 수행한다.
  - 아카이브 로그 파일들을 다른 저장 장치에 옮긴다.
  - 복구할 때에 편리하도록 아카이브 로그 파일들의 순서를 잘 관리한다.
 
#### Archive 모드 설정 상태 알아보기

  V$DATABASE 뷰의 "log_mode" 컬럼을 확인하면 된다.
 
  =====================================================
  SVRMGR> select log_mode from v$database;
LOG_MODE   
------------
NOARCHIVELOG
  =====================================================

  ▶ 아카이브 모드에서 관련 정보 보기
  > desc v$database
  > desc v$archive
 
  ▶ 로그 그룹별 아카이브 모드 상태
  > select group#, archived from v$log;
 
 
  SVRMGR> archive log list
데이터베이스 로그 모드         아카이브 모드가 아님
자동 아카이벌                  사용 불가능
아카이브 수신지                /ora/product/8.1.7/dbs/arch
가장 오래된 온라인 로그 순차   1078
현재 로그 순차                 1080

   현재 데이터베이스는 노아카이브 모드이다.
  - 자동 아카이브 모드는 설정되어 있지 않다.
  - 아카이브 파일들은 "$ORACLE_HOME/dbs/arch"에 저장된다.
  - 가장 오래 전에 사용된 리두 로그(redo log) 파일의 Sequence 번호는 1078 이다.
  - 현재 사용되고 있는 리두 로그(redo log) 파일의 Sequence 번호는 1080 이다.




#### 아카이브 모드 설정 및 해제

  ▶ 아카이브 모드 설정하기
  > ALTER DATABASE ARCHIVELOG;
 
  ▶ 아카이브 모드 해제하기
  > ALTER DATABASE NOARCHIVELOG;
 
  ▶ 아카이브 모드 설정하기
  ALTER DATABASE 명령어는 데이터베이스가 오픈되어 있지 않은 상태에서만 효력을 발생하므로
  다음과 같은 순서에 따라서 작업을 수행해야 한다.
 
    ■ 데이터베이스를 내린다.
      SVRMGR> SHUTDOWN;
     
    ■ 데이터베이스를 백업한다.
   
    데이터베이스를 백업할 때에는 데이터를 저장하고 있는 데이블스페이스는 물론
    로그 파일, 롤백 세그먼트 파일 등 데이터베이스를 구성하는 모든 파일들을
    오퍼레이팅 시스템이 제공하는 유틸리티를 사용해서 다른 디스크나 테이프
    저장 장치에 복사해 놓아야 한다.
   
   
    ■ 데이터베이스를 마운트한다.
      SVRMGR> CONNECT INTERNAL;
      Connected.
      SVRMGR> STARTUP MOUNT;
     
    오라클에서는 아무런 옵션 절 없이 "STARTUP" 명령어만을 사용하면, 오라클은 데이터베이스를
    마운트하고 이를 오픈하는 것까지를 수행한다. 아카이브 모드로 변경하기 위해서는
    반드시 데이터베이스를 오픈한지 않은 상태로 두어야 한다.
   
    ■ 아카이브 모드를 설정한다.
      SVRMGR> ALTER DATABASE ARCHIVELOG;
   
    ■ 데이터베이스를 오픈한다.
      SVRMGR> ALTER DATABASE OPEN;
     
     
  ▶ 아카이브 모드 해제하기     
  아카이브 모드를 해제하고자 하면 다음과 같은 순서로 한다.
 
    ■ 데이터베이스를 내린다.
      SVRMGR> shutdown;
     
    ■ 필요한 경우 백업을 수행한다.
    ■ 데이터베이스를 마운트한다.
      SVRMGR> STARTUP MOUNT;
         
    ■ 아카이브 모드를 해제한다.
      SVRMGR> ALTER DATABASE NOARCHIVELOG;
   
    ■ 데이터베이스를 오픈한다.
      SVRMGR> ALTER DATABASE OPEN;


    ■ 로그 싸이게함.. (이게 필요한가??)
      SVRMGR> alter system switch logfile; <--로그쌓이게 함
     

#### 아카이빙 수행

두가지 수행방법
  1. 오라클 초기화 변수 파일(init.ora)을 이용해서 리두 로그 파일이
    가득 차면 자동으로 수행
  2. 명령어를 사용해서 데이터베이스 관리자(DBA)가 수동으로 수행


  ▶ 자동 수행
  아카이빙을 자동으로 수행하기 위해서는 다음과 같이 "init.ora" 파일을 수정해야 한다.
  이 파일을 수정하고 나서는 반드시 데이터베이스를 내렸다가 다시 올려야 한다.
 
==================== /ora/product/8.1.7/dbs/init.ora ======================
# Uncommenting the line below will cause automatic archiving if archiving has
# been enabled using ALTER DATABASE ARCHIVELOG.
log_archive_start = true     
log_archive_dest = /ora/product/8.1.7/dbs/arch/log
log_archive_format = "%S.ARC"
==================== /ora/product/8.1.7/dbs/init.ora ======================

 
  ▶ 수동 수행
    > ALTER SYSTEM ARCHIVE LOG ALL;
   
    적절한 시간에 온라인 리두 로그 파일의 내용을 아카이브 파일로 저장하지 못하면
    데이터베이스 시스템에 문제가 생길 수 있다.

#### 아카이브 로그 파일의 장소와 이름 포맷 설정

  아카이브 로그 파일이 저장되는 장소는 "LOG_ARCHIVE_DEST" 변수로 결정되고,
  이름 형식은 "LOG_ARCHIVE_FORMAT" 초기화 변수로 설정된다.
 
  ▶ LOG_ARCHIVE_FORMAT 형식

    ■ %T 스레드 번호와 0을 삽입 arch0000000001
    ■ %t 스레드 번호 arch1
    ■ %S 로그 일련번호와 0을 삽입 arch0000000017
    ■ %s 로그 일련번호 arch17


#### 아카이브 로그 파일 옮기기

  아카이브 로그 파일들을 다른 저장 장치로 옮기로 지우는 것이 좋다.
 
  Ex) dd if=/oracle/dbs/arch/log1.src of=/dev/rmt/ctape1
 
 
 
  ▶ 데이터 파일 위치
 
/ora/oradata/ora1/system01.dbf
/ora/oradata/ora1/temp01.dbf
/ora/oradata/ora1/rbs01.dbf
/ora/oradata/ora1/indx01.dbf
/ora/oradata/ora1/users01.dbf
/ora/oradata/ora1/tools01.dbf
/ora/oradata/ora1/drsys01.dbf


#### 전체 데이터베이스 백업

  ▶ 사용 명령어들
    dd : http://man.kldp.org/man/man1/dd.1.html
volcopy :

  ▶ dd 를 이용해서 백업
dd if=/ora/oradata/ora1/system01.dbf of=/oradb/ora1_backup/system01.dbf bs=2048
dd if=/ora/oradata/ora1/temp01.dbf   of=/oradb/ora1_backup/temp01.dbf   bs=2048
dd if=/ora/oradata/ora1/rbs01.dbf    of=/oradb/ora1_backup/rbs01.dbf    bs=2048
dd if=/ora/oradata/ora1/indx01.dbf   of=/oradb/ora1_backup/index01.dbf  bs=2048
dd if=/ora/oradata/ora1/users01.dbf  of=/oradb/ora1_backup/users01.dbf  bs=2048
dd if=/ora/oradata/ora1/tools01.dbf  of=/oradb/ora1_backup/tools01.dbf  bs=2048
dd if=/ora/oradata/ora1/drsys01.dbf  of=/oradb/ora1_backup/drsys01.dbf  bs=2048
 

  ▶ 백업할 파일 찾기
   
    ■ Datafile          : 애플리케이션과 시스템에서 필요한 정보를 저장하는 파일
    ■ Redo Log File     : 데이터 변경 이력을 기록하는 파일
    ■ Coontrol File     : 데이터베이스 파일 목록 및 운영 정보를 저장하는 파일
    ■ Parameter File    : 데이터베이스 서버의 특성을 설정하는 데 사용되는
                          변수들을 저장하는 파일

    > select file_name from dba_data_files;

    > select value from v$parameter where name = 'control_files';
   
    > select member from v$logfile;

    > select value from v$parameter where name = 'log_archive_dest';
   
  ▶ OS 명령어 사용 전체 데이터베이스 백업 방법
 
    ■ 백업 받을 데이터 파일들의 이름과 실제 저장 위치를 알아낸다.
    ■ OS 명령어를 수행하기 위한 쉘 스크립트를 작성한다.
    ■ 데이터베이스 서버를 내린다.
    ■ 쉘 스크립트를 수행하여 원하는 데이터 파일들을 백업한다.
    ■ 원하는 파일들이 모두 안전하게 백업되었는지 확인한다.
    ■ 데이터베이스 서버를 다시 마운트하고 오픈한다.






#### 부분 백업
  ▶ Full Backup 은 Physical Backup 이고, Export Backup 은 Logical Backup 이다.

  ▶ 온라인 테이블스페이스, 데이터 파일 백업
     
    ■ 백업할 데이터 파일의 저장 우치를 알아낸다.
  : USERS 라는 테이블스페이스의 저장 위치
  > select tablespace_name, file_name
  from sys.dba_data_files
  wehre tablespace_name = 'USERS';

    ■ 백업 시작을 데이터베이스 서버에 알린다.
      > ALTER TABLESPACE users BEGIN BACKUP;
    ■ OS 명령어를 사용해서 데이터 파일을 백업한다.
      > !sh
      $dd if=/ora/oradata/ora1/users01.dbf  of=/oradb/ora1_backup/users01.dbf  bs=2048
      $exit
    ■ 백업 끝을 데이터베이스 서버에 알린다.
      > ALTER TABLESPACE users END BACKUP;

  ▶ 데이터 파일의 백업 상태 확인
 
    데이터 파일들의 백업 상태는 V$BACKUP 뷰를 통해서 알 수 있다.
   
    > SELECT file#, status FROM v$backup;
FILE#      STATUS           
---------- ------------------
         1 NOT ACTIVE       
         2 NOT ACTIVE       
         3 ACTIVE  
        
    "NOT ACTIVE" 는 백업 상태가 아님,
    "ACTIVE" 는 백업 상태임을 나타낸다.
   
  ▶ 오프라인 테이블스페이스 백업
 
    단, "SYSTEM" 테이블스페이스와 현재 사용중인 롤백 세그먼트는
    오프라인시킬 수 없다.
   
    ■ 백업하기를 원하는 테이블스페이스를 오프라인시킨다.
      > ALTER TABLESPACE users OFFLINE NORMAL;
    ■ 오프라인된 테이블스페이스를 백업한다.     
    ■ 백업이 끝난 테이블스페이스를 다시 온라인시킨다.
      > ALTER TABLESPACE users ONLINE;
   
  ▶ Control 파일 백업
 
    > ALTER DATABASE BACKUP CONTROLFILE TO 'filename' REUSE;
   
    "filename" 은 절대 위치("/" 루트부터 시작)를 입력하고,
    "REUSE" 옵션은 현재 있는 컴트롤 파일에 새로운 내용을 다시
    쓰는 것을 나타낸다.
   
    백업과 복구 목적으로 컨트롤 파일을 생성하는 스크립트를 만들 수 있다.
   
    > ALTER DATABASE BACKUP CONTROLFILE TO TRACE NORESETLOGS;
   
    이 SQL 명령어를 수행하면 사용자 덤프디렉토리($ORACLE_BASE/admin/oracle/udump)에
    "ora_<PID>.trc" 파일이 생긴다. 이 파일은 직접 수행되는 것은 아니고
    수행할 수 있는 스크립트 파일이다. 이 파일의 각 SQL 명령어에 도움말이 있고,
    백업과 복구에 필요하다고 생각되는 부분을 수정해서 사용하면 된다.
   


#### 복원(Restore)과 복구(Recover)
 
  복구 작업은 크게 복원 작업과 복구 작업으로 나눌 수 있는데 이를 모두 복구
  작업이라고도 한다.
  복원: 복구 작업의 준비 작업으로 데이터베이스에 문제가 발생하기 이전
      최신 데이터로 데이터베이스를 다시 구성하는 일
      ex) 문제가 발생하기 전에 OS 명령어를 사용해서 전체 데이터베이스를
      백업 받아 놓았다면 이를 다시 호스트에 내려서, 몇일 전 상태로 만든다.
  복구 : 이렇게 구성된 이전 데이터베이스를 가지고 문제가 발생한 시점의
      데이터로 변경하는 일
      전체 데이터베이스 백업 이후 아카이브 로그 파일들을 잘 맥업 받아
      놓았다면 문제 발생 시점까지의 데이터를 복구할 수 있다.   

  ▶ 복구 순서
 
  데이터베이스에 문제가 발생하기 이전
    ■ 백업과 복구에 대한 계획을 수립한다.
    ■ 백업을 주기적으로 수행한다.
    ■ 복원과 복구를 미리 연습한다.
    ■ 복구가 필요한 부분이 있나 찾아본다.

  데이터베이스에 문제가 발생한 이후
    ■ 문제 원인 분석
    ■ 복구 방법 결정
    ■ 복구 수행
    ■ 복구 결과 확인



#### 문제점 찾기

  > SELECT file#, "ONLINE", error FROM v$recover_file;





  ▶ xxxxx 사용자의 설정 찾기
 
    > select * from DBA_USERS where username like 'xxxxx%';
    > dd if=/ora/product/8.1.7/dbs/xxxxx of=/oradb/ora1_backup/2001.12.22_ts/xxxxx.1
   
    ■
    ■
    ■
    ■

    ■
    ■
    ■
    ■
    ■
    ■
    ■
    ■


###################
# 추가 내용
###################

#### Backup 종류

  ▶ DB는 Backup수행을 위해 얼마나 자주, 어느 정도의 시간동안 Offline될수 있는가?
    ■ Offline Full Backup을 수행하는데 필요한 시간이 여의치 않는 경우를 위해
      Oracle은 DB운영 중 Physical Backup을 실시할 수 있는 방법을 제공한다.
    ■ Online Backup은 SQL*DBA(SVRMGR) 명령어인
      ALTER TABLESPACE ... BEGIN BACKUP,
      ALTER TABLESPACE ... END BACKUP
      사이에 Tablespace에 속한 File을 Copy함으로써 수행된다.
    ■ Oracle이 제공하는 또 다른 방법은 Export Utility가 있다.
      Export를 이용한 Backup은 DB 에 속한 data의 논리적 표현으로 구성된다.
      Export를 이용한 Backup은 Physical Backup의 보조 수단으로 사용되어야 한다.
      예) Object level Recovery


#### 기본적인 Backup Rules

  ▶ Log file을 disk에 archive한  후,  나중에 tape에 copy한다. 
    단,  Archived log destination은 data file이나 online redo log file과는
    다른 disk이어야 한다.

  ▶ Data file의 backup은 실제 data file과는 다른 disk에 유지되어야 한다. 
    Disk에 data file을 backup하면 recovery 속도를 향상시킬 수 있다.
  ▶ Control file을 여러 개 유지해야 하고,  이들은 각각 다른 disk에 존재해야 한다.
  ▶ Online log는 group당 최소한 2개 이상의 member를 유지해야 하고,
    각각의 member는 서로 다른 disk에 존재해야 한다.
  ▶ Archive log의 복사본은 tape뿐만 아니라 disk에도 유지하는 것이 좋다
  ▶ Log file이나 Data file을 추가하거나 , rename하거나, 삭제하는 등
    Database 구조가 변경되었을 경우,  반드시 control file을 backup받아야 한다. 
    또한, 추가된 data file도 backup을 받아야 한다.

  ▶ Backup 전략의 예
    ■ 1. ARCHIVELOG mode로 운영한다.
    ■ 2. 24시간 * 7 일 무정지 시스템이 아니라면,
      일주일에 한 번씩의 Offline full backup과
      매일 Online backup 이 이루어져야 한다.
    ■ 3. 매주 한 번씩 RESTRICT mode에서 full database export를 수행한다. 
      24*7 시스템이라면, database access가 없거나 적을 때 full export를 수행한다.

#### 복구시간 예측

  ▶ 얼마나 빠른 복구를 필요로 하는가?
    ■ DB가 NOARCHIVELOG mode에서 운영될 때 복구를 위한 가장 빠른 방법은 DB를
      구성하는 모든 file을 Restore하는 것이다. 한편 DB가 ARCHIVELOG mode로
      운영된다면 Physical Backup이후의 Data변화를 복구하기 위해 SQL*DBA(SVRMGR)
      RECOVER DATABASE 명령어를 사용하여 Archived redo log file을 적용하여야 한다.

    ■ 따라서 복구시간은 적용하여야 할 Redo log file을 적게 가짐으로써 최소화할
     수 있고  이는 Backup의 주기에 따라 결정된다.

    ■ Backup은 고객이 기대하는 MTTR(Mean Time To Recover)을 목표로 전략을
     수립하여야 하며 이에는 Backup 장비, 방법, 주기를 어떻게 하느냐에 따라 결정된다.
     또한 MTTR산정시 Backup 장비 Error와 같은 잠재된 장애에 대한 복구지연 가능성도
     고려 하여야 한다.


#################
# 백업 시나리오
#################   

server1  : Oracle 서버
server2  : Backup 서버

일단. server1에서 Achive mode 를 이용해서 백업을 하드의 log partition에 한다.
백업 주기는 한루에 한번이나 두번정도 한다.

그리고, 내부에 백업 서버(server2)를 두어서 Achive 로 백업된 데이터를 이동한다.
rsync 를 이용하면 쉽게 이동할 수 있다.
이렇게 하면 나중에 server1 이 고장이 나도 바로 복구가 가능한다.
데이터 이동주기는 백업 주기에 맞추고, 시간은 요청이 가장 적은 시간에 한다.


내부에 문제가 있을 수도 있으니깐.
하루에 한번이나 일주일에 3번정도 외부에 백업을 한다.
데이터이동은 rsync 를 이용한다.

###################
# bacup 하기
###################

server1 : (오라클 서버)
/oradb/backup
  - cold : cold 백업한 데이터들
  - arch : archive log 데이터
 
server2 : (백업 서버)

1. archive mode
2. 1주일에 한번 cold backup 을 한다.
3. server1 의 cold backup 한 것을 server2 의 cold backup 에 가져간다.
  server1 에서 backup 후 server2 에서 가져간다.
  server2 에서 계속 저장한다. cold bacup 후 arhive log 는 server1 backup 에 저정한다.
 
4. Arhive log 는 매일 2~3번 sync 한다.
  -> 속도 Test 를 해볼것
  -> insert, update 시 log size가 변하는가?
 
   



## 7일 이전의 로그 지우는 명령(Unix)
find ./아카이브로그 풀경로 -mtime 7 -print | xargs rm
반응형
Posted by [PineTree]
ORACLE/ADMIN2006. 6. 9. 00:36
반응형

 Oracle 의 경우, 현재 열려진 총 Statement의 개수를 보는 방법이 있습니다.


 -------------------------------------------
select sid, count(*) cnt from v$open_cursor
where user_name = 'username'
group by sid
order by cnt desc
-------------------------------------------

반응형
Posted by [PineTree]
ORACLE/ADMIN2006. 5. 9. 03:12
반응형
do82ng http://cafe.naver.com/dbaclub/4 이 게시물의 주소를 복사합니다
 

ERROR:
ORA-00604: error occurred at recursive SQL level 2
ORA-04031: unable to allocate 4048 bytes of shared memory ("shared
pool","TRIGGER$SYS","sga heap","state objects")
ORA-00604: error occurred at recursive SQL level 1
ORA-04031: unable to allocate 4048 bytes of shared memory ("shared
pool","unknown object","sga heap","state objects")


DB를 관리하면서 다음과 같은 에러를 직면할때가 있느데 이럴 경우에는 신속하게
대처할 수 있는 방법
  1. 오래된 세션을 끊어서 shared pool 에 잡고 있는 메모리를 해제 시켜준다.
  2
. alter system flush shared_pool; 명령어를 통해 메모리 조각모임을 해준다.
장기적인 대책은 
  단편화 시키는 SQL를 찾아내고 바인딩 변수화 시킨다.


ORA-04031 의 경우 shared pool 내에 메모리 조각화에 따라서 연속된 parsing 공간을 제공하지 못하기 때문에 발생하는 에러입니다.
다시 말해서 parsing 에러가 발생하는 것입니다.

이를 해소 해주기 위한 방법으로
개체가 큰 자주 사용되는 프로시져등을 메모리에 pined 해주면 되며,
shared pool 사이즈를 늘려 주는것이 가장 좋으며,

상황이 여의치 않는 경우 단편화된 shared pool 의 조각화을 다시 flush 해주는 방법
등이 있습니다.


SQL> alter system flush shared_pool;

shared pool 의 hit 율을 잘 분석해 보시고 오라클의 권장사항에 따라서 튜닝 가이드 라인을 정하는게 중요합니다.

너무 크게 줘서 free size 가 너무 많이 남는 경우 즉 hit 율은 좋은데, free size 가 너무 큰 경우는 메모리 낭비를 하게 되며, 각각의 o/s 에 따라서  paging 이나 swap 이 발생할 가능성이 있으니, 튜닝후 적적할 모니터를 통해서 사이즈를 잡아 가는 것이 좋습니다.

SQL> select name, bytes/1024/1024 "Size in MB" from v$sgastat where name='free memory';

NAME                       Size in MB
-------------------------- ----------
free memory                451.496498
free memory                  .5859375
free memory                    .03125

즉 오라클의 동적 뷰들의 대부분은 current 한 내용이 아닌 축적용으로 평균치를 나타 내기 때문에 의미가 없습니다.

반응형

'ORACLE > ADMIN' 카테고리의 다른 글

아카이브 로그 관련정보  (0) 2006.06.26
open_cursor의 개수를 보는 방법  (0) 2006.06.09
[Oracle]오라클 어드민 팁  (0) 2006.03.17
Oracle 장애의 유형과 문제해결  (0) 2006.03.15
오라클 SID변경 작업  (0) 2006.03.09
Posted by [PineTree]
ORACLE/ADMIN2006. 3. 17. 07:45
반응형

[Oracle]오라클 어드민 팁  

Oracle Administration을 정리하다가 간단히 찾아고 조금이나마 도움이 되시라고 정리해서 올립니다.
너무 단시간에 두서없이 써서 보기도 좋지 않지만 필요하신 분들 심심할때 하나씩  
해보세요.(다들 아시는거지만~~)
아래 tips 는 하나의 database에서 작성한 것이 아니므로 각종 정보들(file들의 위치등)이  
tip마다 다를 수 있습니다. 각 tip은 개개의 것으로 생각하시고 응용하시기 바랍니다.
혹시 틀린 내용 발견되면 mail주세요. 바로 수정하겠습니다.
편집 이쁘게 못해서 죄송합니다.
나름대로 사연있는 글입니다.
정리하다가 날려먹어서 한 몇일 더 고생해서 작성한겁니다.^^;

님들도 좋은 정보 있으시면 공유하시죠.


================================================================================================  
1. DBMS = database(data file & control file & redo log file) +  
                                                   instance(memory & background processes)
================================================================================================  


2. Oracle Architecture Component

================================================================================================  

* Oracle Instance 확인 : v$instance

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
IBM

================================================================================================  

* datafile들의 경로 및 정보 : v$datafile
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oracle/ora_data/system/system01.dbf
/oracle/ora_data/data/tools01.dbf
/oracle/ora_data/data/rbs01.dbf
/oracle/ora_data/data/temp01.dbf
/oracle/ora_data/data/users01.dbf

================================================================================================  

* control file의 경로 및 정보 : v$controlfile;

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/oracle/ora_data/contr1/ora_control1
/oracle/ora_data/contr2/ora_control2

================================================================================================  

* logfile의 경로 및 정보 : v$logfile

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/oracle/ora_data/redolog_a/redo1a.log
/oracle/ora_data/redolog_b/redo1b.log
/oracle/ora_data/redolog_a/redo2a.log
/oracle/ora_data/redolog_b/redo2b.log
/oracle/ora_data/redolog_a/redo3a.log
/oracle/ora_data/redolog_b/redo3b.log

================================================================================================  

* System Global Area 내용을 조회

SQL> select * from v$sga;

NAME                      VALUE
-------------------- ----------
Fixed Size               108588
Variable Size          27631616
Database Buffers        2252800
Redo Buffers              77824

SQL> show sga

Total System Global Area   30070828 bytes
Fixed Size                   108588 bytes
Variable Size              27631616 bytes
Database Buffers            2252800 bytes
Redo Buffers                  77824 bytes

================================================================================================  

* 현재 수행중인 background process들을 확인

SQL> select paddr,name,description from v$bgprocess where paddr>'00';

PADDR            NAME  DESCRIPTION
---------------- ----- ----------------------------------------------------------------
070000000139ABC0 PMON  process cleanup
070000000139AFD0 DBW0  db writer process 0
070000000139B3E0 LGWR  Redo etc.
070000000139B7F0 CKPT  checkpoint
070000000139BC00 SMON  System Monitor Process
070000000139C010 RECO  distributed recovery

SQL> !ps -ef|grep ora|grep

 oracle 25148     1   0  19:25:34      -  0:00 ora_reco_IBM
 oracle 60576     1   0  19:25:34      -  0:00 ora_smon_IBM
 oracle 60782     1   0  19:25:34      -  0:00 ora_pmon_IBM
 oracle 70166     1   0  19:25:34      -  0:00 ora_lgwr_IBM
 oracle 72248     1   0  19:25:34      -  0:00 ora_ckpt_IBM
 oracle 84918     1   0  19:25:34      -  0:00 ora_dbw0_IBM
 
================================================================================================  

* 초기화 파라미터 파일 : init.ora

================================================================================================  

* database log 모드 확인

SQL> connect internal
Connected.

SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /oracle/app/oracle/product/8.1.6/dbs/arch
Oldest online log sequence     20
Current log sequence           22

SQL> select log_mode from v$database;

LOG_MODE
------------
NOARCHIVELOG

================================================================================================  


3. Managing an Oracle Instance

================================================================================================  

단계별 :
shutdown : oracle이 내려가 있는 상태
nomount : instance started(SGA, B.G process를 시작 init.ora에서 읽어서)
alert, trace file open
- 이 단계에서 할 수 있는 것은  
 a. db creation
- 이 상태에서도 볼수있는 view
 v$parameter
 v$dga
 v$option
 v$process
 v$session
 v$version
 v$instance

mount : control file opened for this instance
- 이 단계에서 할 수 있는 것은 control file의 내용을 변경하는것
 a. archivelog mode로 변환
 b. data file/redo log file rename시
 c. recovery시

- SQL>alter database open read only;
 로 하게되면 data file에 writing을 허용 안함.

open : control file에 기술된 모든 files open

================================================================================================  

* parameter 변경 종류

a. init.ora 에서 변경
b. alter session set ~
c. alter system set ~    => shutdown 될때까지 변경된것 유효
  alter system deffered set ~ => 현재 session에서만 변경된것 유효

================================================================================================  

* 특정 session 죽이기

SQL> select sid, serial#,username,status from v$session; => (특정 user는 where username='SCOTT'로)
      SID    SERIAL# USERNAME                       STATUS
---------- ---------- ------------------------------ --------
        1          1                                ACTIVE
        2          1                                ACTIVE
        3          1                                ACTIVE
        4          1                                ACTIVE
        5          1                                ACTIVE
        6          1                                ACTIVE
        7          1 SYS                            ACTIVE

SQL> alter system kill session '7,3'    -- 7은 sid, 3은 serial#

================================================================================================  

* alert file 과 trace file
- alert file은 꼭 1개, 중요한사건,시간순으로 (startup,shutdown,recovery)
- trace file은 여러개 가능, background process는 background_dump_dest에 생기고 server process는
 user_dump_dest에 생성된다.

================================================================================================  


4. Creating a Database

================================================================================================  

* Create a Database Manually

a. OS Environment setting

.profile에 ORACLE_HOME,ORACLE_SID,ORA_NLS33,PATH,(ORACLE_BASE) 등을 편집한다.

ex)
DISPLAY=swsvrctr:0.0
ORACLE_HOME=/oracle/app/oracle/product/8.1.7
PATH=$ORACLE_PATH/bin:/usr/ccs/bin:$PATH
NLS_LANG=AMERICAN_AMERICA.KO16KSC5601
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
ORACLE_SID=IBM

b. init.ora file을 copy하고 편집한다.
file
db_name=KYS
control_files = (/home/oracle/data02/control/control01.ctl,/home/oracle/data02/control/control02.ctl)
db_block_size = 8192

기본적으로 위 두개 parameter외에
rollback_segments=(rbs1,rbs2,..)  =>나중에 rollback segment생성후 DB start시 Online되는 rbs지정
background_dump_dest=/home/oracle/data02/bdump
user_dump_dest=/home/oracle/data02/udump
core_dump_dest=/home/oracle/data02/cdump

c. Starting the Instance

SQL> startup nomount
SQL> startup nomount pfile=initKYS.ora

SQL> create database KYS
 2     maxlogfiles 5
 3     maxlogmembers 5
 4     maxdatafiles 100
 5     maxloghistory 100
 6  logfile
 7     group 1 ('/home/oracle/data02/redolog/log1a.rdo','/home/oracle/data02/redolog2/log1b.rdo') size 1m,
 8     group 2 ('/home/oracle/data02/redolog/log2a.rdo','/home/oracle/data02/redolog2/log2b.rdo') size 1m
 9  datafile
10     '/home/oracle/data02/data/system01.dbf' size 50m autoextend on
11  character set "KO16KSC5601";

일단 여기까지 database는 생성이 되었다.
이후부터는 추가적인 작업이다.

d. 추가 system rollback segment 생성

SQL> create rollback segment r0 tablespace system
 2  storage (initial 16k next 16k minextents 2 maxextents 10);

 
e. rollback sement online

SQL> alter rollback segment r0 online;


f. rollback segment tablespace 생성 & datafile 저장위치, 크기 및 초기값 지정

SQL> create tablespace rbs
 2  datafile '/home/oracle/data02/data/rbs01.dbf' size 300m
 3  default storage(
 4  initial            4M
 5  next               4M
 6  pctincrease        0
 7  minextents         10
 8  maxextents         unlimited);

g. rollback segment 생성

SQL> create rollback segment r01 tablespace rbs
 2  storage (minextents 10 optimal 40M);
SQL> create rollback segment r02 tablespace rbs
 2  storage (minextents 10 optimal 40M);
SQL> create rollback segment r03 tablespace rbs
 2  storage (minextents 10 optimal 40M);
SQL> create rollback segment r04 tablespace rbs
 2  storage (minextents 10 optimal 40M);


h. rollback segment online

SQL> alter rollback segment r01 online;
SQL> alter rollback segment r02 online;
SQL> alter rollback segment r03 online;
SQL> alter rollback segment r04 online;


i. 추가 system rollback segment off-line 및 삭제  

SQL> alter rollback segment r0 offline;
SQL> drop rollback segment r0;

j. sorting 작업시 필요한 temporary tablespace 생성 & datafile 저장 위치, 크기 및 초기값 지정

SQL> create tablespace temp
 2  datafile '/home/oracle/data02/data/temp01.dbf' size 300 temporary
 3  default storage(
 4  initial            4M
 5  next               4M
 6  maxextents         unlimited
 7  pctincrease        0);
 
 
k. 추가 tablespace 생성 & data file 저장 위치 및 크기 지정

SQL> create tablespace tools
 2  datafile '/home/oracle/data02/data/tools.dbf' size 50m
 3  default storage(
 4  maxextents 505
 5  pctincrease 0);
 
SQL> create tablespace users
 2  datafile '/home/oracle/data02/data/user01.dbf' size 30M
 3  default storage(
 4  maxextents 505
 5  pctincrease 0);
 
l. 작업 환경에서 추가적으로 필요한 tablespace는 위의 방법으로 생성한다.


================================================================================================  


5. Data Dictionary and Standard Package

================================================================================================  

* database 생성후 돌려줘야 할 script

$ORACLE_HOME/rdbms/admin/catalog.sql ==> dictionary views, export utility views 생성
$ORACLE_HOME/rdbms/admin/catproc.sql ==> procedures, functions 생성
$ORACLE_HOME/rdbms/admin/catdbsyn.sql ==> synonyms 생성

================================================================================================  

* Dictionary list 확인

SQL> col table_name format a30
SQL> col comments format a45
SQL> set pages 800
SQL> spool dictionary.lst
SQL> select * from dictionary order by 1 ==> 전체 dictionary의 list를 볼 수 있다.
SQL> spool off
SQL> ed sictionary.lst
SQL> select * from dictionary where table_name like '%TABLE%'; ==> table 관련 dictionary  
SQL> select * from dictionary where table_name like '%INDEX%';  ==> index 관련 dictionary

================================================================================================  

* 유용한 dictionary  

TABLE_NAME                     COMMENTS
------------------------------ ---------------------------------------------
DBA_USERS                      Information about all users of the database
DBA_TABLESPACES                Description of all tablespaces
DBA_DATA_FILES                 Information about database data files
DBA_FREE_SPACE                 Free extents in all tablespaces
DBA_OBJECTS                    All objects in the database
DBA_SEGMENTS                   Storage allocated for all database segments
DBA_ROLLBACK_SEGS              Description of rollback segments
DBA_EXTENTS                    Extents comprising all segments in the database
DBA_TABLES                     Description of all relational tables in the d
                              atabase
DBA_INDEXES                    Description for all indexes in the database
DBA_VIEWS                      Description of all views in the database
DBA_TRIGGERS                   All triggers in the database
DBA_SOURCE                     Source of all stored objects in the database

================================================================================================  

* sample Query

SQL> select username,default_tablespace,temporary_tablespace from dba_users;
SQL> select tablespace_name,bytes,file_name from dba_data_files;
SQL> select tablespace_name,count(*),sum(bytes) from dba_free_space
 2  group by tablespace_name;
 
================================================================================================  


6. Maintiaining the Contorol File

================================================================================================  

* Control File 리스트 조회

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/home/oracle/data01/oradata/IBM/control01.ctl
/home/oracle/data01/oradata/IBM/control02.ctl
/home/oracle/data01/oradata/IBM/control03.ctl

================================================================================================  

* Control File 을 하나 추가해보자

a. database shutdown
SQL> shutdown immediate

b. control file 복사(os상 물리적인 복사)
/home/oracle/data01/oradata/IBM> cp control03.ctl control04.ctl ==> 실제는 다른 disk로 복사해야함
   문제발생을 대비해 분리하는것임.

c. Parameter File 편집
control_files = ("/home/oracle/data01/oradata/IBM/control01.ctl",  
"/home/oracle/data01/oradata/IBM/control02.ctl",  
"/home/oracle/data01/oradata/IBM/control03.ctl",  
"/home/oracle/data01/oradata/IBM/control04,ctl")

d. database startup & 확인
SQL> startup
SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/home/oracle/data01/oradata/IBM/control01.ctl
/home/oracle/data01/oradata/IBM/control02.ctl
/home/oracle/data01/oradata/IBM/control03.ctl
/home/oracle/data01/oradata/IBM/control04.ctl ==> 하나 더 추가되었지요...(실제는 다른disk로)

================================================================================================  


7. Multiplexing Redo Log Files

================================================================================================  

* Redo Log File 리스트 조회

SQL> select group#,sequence#,bytes,members,status from v$log;

   GROUP#  SEQUENCE#      BYTES    MEMBERS STATUS
---------- ---------- ---------- ---------- --------------------------------
        1        862     512000          1 CURRENT
        2        860     512000          1 INACTIVE
        3        861     512000          1 INACTIVE

SQL> select * from v$logfile;

   GROUP# STATUS         MEMBER
---------- -------------- --------------------------------------------------
        1                /home/oracle/data01/oradata/IBM/redo03.log
        2                /home/oracle/data01/oradata/IBM/redo02.log
        3                /home/oracle/data01/oradata/IBM/redo01.log          

================================================================================================  

* Log Group 추가(기존 로그 파일과 동일한 사이즈로)

SQL> alter database add logfile
 2  '/home/oracle/data01/oradata/IBM/redo04.log' size 200k;

SQL> select group#,sequence#,bytes,members,status from v$log;

   GROUP#  SEQUENCE#      BYTES    MEMBERS STATUS
---------- ---------- ---------- ---------- --------------------------------
        1        862     512000          1 CURRENT
        2        860     512000          1 INACTIVE
        3        861     512000          1 INACTIVE
        4          0     204800          1 UNUSED

SQL> select * from v$logfile;

   GROUP# STATUS         MEMBER
---------- -------------- --------------------------------------------------
        1                /home/oracle/data01/oradata/IBM/redo03.log
        2                /home/oracle/data01/oradata/IBM/redo02.log
        3                /home/oracle/data01/oradata/IBM/redo01.log
        4                /home/oracle/data01/oradata/IBM/redo04.log

================================================================================================  

* Log Group 별 멤버 파일 추가    ==> backup 시 risk줄이기 위해 실제는 다른 disk에 해야함.

SQL> alter database add logfile member
 2  '/home/oracle/data01/oradata/IBM/redo01b.log' to group 1,
 3  '/home/oracle/data01/oradata/IBM/redo02b.log' to group 2,
 4  '/home/oracle/data01/oradata/IBM/redo03b.log' to group 3,
 5  '/home/oracle/data01/oradata/IBM/redo04b.log' to group 4;

================================================================================================  

* 확인

SQL> !ls /home/oracle/data01/oradata/IBM/*.log
/home/oracle/data01/oradata/IBM/redo01.log   /home/oracle/data01/oradata/IBM/redo03.log
/home/oracle/data01/oradata/IBM/redo01b.log  /home/oracle/data01/oradata/IBM/redo03b.log
/home/oracle/data01/oradata/IBM/redo02.log   /home/oracle/data01/oradata/IBM/redo04.log
/home/oracle/data01/oradata/IBM/redo02b.log  /home/oracle/data01/oradata/IBM/redo04b.log

SQL> select group#,sequence#,bytes,members,status from v$log;

   GROUP#  SEQUENCE#      BYTES    MEMBERS STATUS
---------- ---------- ---------- ---------- --------------------------------
        1        862     512000          2 CURRENT
        2        860     512000          2 INACTIVE
        3        861     512000          2 INACTIVE
        4          0     204800          2 UNUSED ==> 아직 한번도 사용되지 않음

SQL> select * from v$logfile;

   GROUP# STATUS         MEMBER
---------- -------------- --------------------------------------------------
        1                /home/oracle/data01/oradata/IBM/redo03.log
        2                /home/oracle/data01/oradata/IBM/redo02.log
        3                /home/oracle/data01/oradata/IBM/redo01.log
        4                /home/oracle/data01/oradata/IBM/redo04.log
        1 INVALID        /home/oracle/data01/oradata/IBM/redo01b.log
        2 INVALID        /home/oracle/data01/oradata/IBM/redo02b.log
        3 INVALID        /home/oracle/data01/oradata/IBM/redo03b.log
        4 INVALID        /home/oracle/data01/oradata/IBM/redo04b.log


==> 현재 사용되고 있는 log group 은 group 1이고 나중에 추가한 member들은 invalid 한 상태이다.
강제로 log switch를 일으켜서 valid하게 바꾸자.

SQL> alter system switch logfile;

SQL> select group#,sequence#,bytes,members,status from v$log;

   GROUP#  SEQUENCE#      BYTES    MEMBERS STATUS
---------- ---------- ---------- ---------- --------------------------------
        1        862     512000          2 ACTIVE
        2        860     512000          2 INACTIVE
        3        861     512000          2 INACTIVE
        4        863     204800          2 CURRENT ==> unused에서 바뀜.

SQL> select * from v$logfile;

   GROUP# STATUS         MEMBER
---------- -------------- --------------------------------------------------
        1                /home/oracle/data01/oradata/IBM/redo03.log
        2                /home/oracle/data01/oradata/IBM/redo02.log
        3                /home/oracle/data01/oradata/IBM/redo01.log
        4                /home/oracle/data01/oradata/IBM/redo04.log
        1 INVALID        /home/oracle/data01/oradata/IBM/redo01b.log
        2 INVALID        /home/oracle/data01/oradata/IBM/redo02b.log
        3 INVALID        /home/oracle/data01/oradata/IBM/redo03b.log
        4                /home/oracle/data01/oradata/IBM/redo04b.log ==> valid하게 바뀜
         
================================================================================================  


Log Miner

================================================================================================  

* Parameter File 의 utl_file_dir 편집

a. 확인

SQL> select name,value from v$parameter
 2  where name='utl_file_dir';
 
NAME                 VALUE
-------------------- ------------------------------
utl_file_dir

SQL> !mkdir $ORACLE_HOME/LOG

b. LogMiner사용을 위해 init.ora file 편집
utl_file_dir=/oracle/app/oracle/product/8.1.7/LOG

c. restart

SQL> shutdown immediate
SQL> startup

확인
SQL> select name,value from v$parameter
 2  where name='utl_file_dir';
 
NAME                 VALUE
-------------------- ------------------------------
utl_file_dir         /oracle/app/oracle/product/8.1.7/LOG ==> LogMiner 준비를 위한 parameter set

d. LogMiner setting - 반드시 트랜잭션의 첫번째 명령이어야 함

SQL> commit;
SQL> exec dbms_logmnr_d.build('v817dict.ora','/oracle/app/oracle/product/8.1.7/LOG');
BEGIN dbms_logmnr_d.build('v817dict.ora','/oracle/app/oracle/product/8.1.7/LOG'); END;

*
ERROR at line 1:
ORA-06532: Subscript outside of limit
ORA-06512: at "SYS.DBMS_LOGMNR_D", line 793
ORA-06512: at line 1

SQL> !ls $ORACLE_HOME/LOG

SQL> exec dbms_logmnr.add_logfile('/home/oracle/data01/oradata/IBM/redo01.log',DBMS_LOGMNR.NEW);
SQL> exec dbms_logmnr.add_logfile('/home/oracle/data01/oradata/IBM/redo02.log',DBMS_LOGMNR.ADDFILE);
SQL> exec dbms_logmnr.add_logfile('/home/oracle/data01/oradata/IBM/redo03.log',DBMS_LOGMNR.ADDFILE);
SQL> exec dbms_logmnr.add_logfile('/home/oracle/data01/oradata/IBM/redo04.log',DBMS_LOGMNR.ADDFILE);
SQL> exec dbms_logmnr.start_logmnr('/oracle/app/oracle/product/8.1.7/LOG/v817dict.ora');


e. 트랜잭션 수행

SQL> descc scott.dept
SQL> select * from scott.dept;
SQL> insert into scott.dept values(99,'test','test');
SQL> update scott.dept set loc='TEST' where deptno=99;
SQL> commit;

f. log miner 정보 분석
SQL> select timestamp,username,sql_redo from v$logmnr_contents
 2  where seg_name='DEPT';

g. 로그마이닝 종료

SQL> exec dbms_logmnr.end_logmnr;

================================================================================================  


8. Managing TableSpace and Data Files

================================================================================================  

* tablespace와 datafile 조회

SQL> col tablespace_name format a15
SQL> col file_name format a45
SQL> select tablespace_name,status,contents from dba_tablespaces;

TABLESPACE_NAME STATUS             CONTENTS
--------------- ------------------ ------------------
SYSTEM          ONLINE             PERMANENT
TOOLS           ONLINE             PERMANENT
RBS             ONLINE             PERMANENT
TEMP            ONLINE             TEMPORARY
USERS           ONLINE             PERMANENT
INDX            ONLINE             PERMANENT
DRSYS           ONLINE             PERMANENT

SQL> select tablespace_name,bytes,file_name from dba_data_files;

TABLESPACE_NAME      BYTES FILE_NAME
--------------- ---------- ---------------------------------------------
TOOLS             10485760 /home/oracle/data01/oradata/IBM/tools01.dbf
DRSYS             20971520 /home/oracle/data01/oradata/IBM/drsys01.dbf
USERS             20971520 /home/oracle/data01/oradata/IBM/users01.dbf
INDX              20971520 /home/oracle/data01/oradata/IBM/indx01.dbf
RBS               52428800 /home/oracle/data01/oradata/IBM/rbs01.dbf
TEMP              20971520 /home/oracle/data01/oradata/IBM/temp01.dbf
SYSTEM           283115520 /home/oracle/data01/oradata/IBM/system01.dbf

================================================================================================  

* tablespace 생성 및 사이즈 변경

SQL> create tablespace data05
 2  datafile '/home/oracle/data01/oradata/IBM/data05_01.dbf' size 1m;

Tablespace created.

1m 짜리 datafile 하나를 가진 tablespace data05를 추가하였다. 확인.

SQL> select tablespace_name,bytes,file_name from dba_data_files
 2  where tablespace_name='DATA05';

TABLESPACE_NAME      BYTES FILE_NAME
--------------- ---------- ---------------------------------------------
DATA05             1048576 /home/oracle/data01/oradata/IBM/data05_01.dbf

tablespace가 부족할때 늘리는 방법은 두가지가 있다.  
하나는 datafile을 추가하는 방법이고 다른하나는 datafile의 size를 늘리는 방법이다.

a. datafile을 하나 추가해보자.

SQL> alter tablespace data05
 2  add datafile '/home/oracle/data01/oradata/IBM/data05_02.dbf' size 1m;
 
SQL> select tablespace_name,bytes,file_name from dba_data_files
 2  where tablespace_name='DATA05';

TABLESPACE_NAME      BYTES FILE_NAME
--------------- ---------- ---------------------------------------------
DATA05             1048576 /home/oracle/data01/oradata/IBM/data05_01.dbf
DATA05             1048576 /home/oracle/data01/oradata/IBM/data05_02.dbf

제대로 추가되었다.


b. 그렇다면 하나의 사이즈를 변경해보자.

SQL> alter database datafile
 2  '/home/oracle/data01/oradata/IBM/data05_02.dbf' resize 2m;
 
SQL> select tablespace_name,bytes,file_name from dba_data_files
 2  where tablespace_name='DATA05';

TABLESPACE_NAME      BYTES FILE_NAME
--------------- ---------- ---------------------------------------------
DATA05             1048576 /home/oracle/data01/oradata/IBM/data05_01.dbf
DATA05             2097152 /home/oracle/data01/oradata/IBM/data05_02.dbf

2m로 제대로 변경이 되었다.

다시 원상복구
SQL> alter database datafile
 2  '/home/oracle/data01/oradata/IBM/data05_02.dbf' resize 1m;

전체를 다시 확인해보자

SQL> select tablespace_name,bytes,file_name from dba_data_files;

TABLESPACE_NAME      BYTES FILE_NAME
--------------- ---------- ---------------------------------------------
TOOLS             10485760 /home/oracle/data01/oradata/IBM/tools01.dbf
DRSYS             20971520 /home/oracle/data01/oradata/IBM/drsys01.dbf
USERS             20971520 /home/oracle/data01/oradata/IBM/users01.dbf
INDX              20971520 /home/oracle/data01/oradata/IBM/indx01.dbf
RBS               52428800 /home/oracle/data01/oradata/IBM/rbs01.dbf
TEMP              20971520 /home/oracle/data01/oradata/IBM/temp01.dbf
SYSTEM           283115520 /home/oracle/data01/oradata/IBM/system01.dbf
DATA05             1048576 /home/oracle/data01/oradata/IBM/data05_01.dbf
DATA05             1048576 /home/oracle/data01/oradata/IBM/data05_02.dbf

================================================================================================  

* tablespace 삭제 : Dictionary에서만 삭제되는것으로 실제 물리적으로 파일은 os command로 삭제해야한다.


SQL> select tablespace_name from dba_tablespaces
 2  where tablespace_name like 'DATA%'
 3  minus
 4  select distinct tablespace_name from dba_segments;

TABLESPACE_NAME
---------------
DATA05

SQL> drop tablespace data05;
SQL> select tablespace_name,bytes,file_name from dba_data_files;

TABLESPACE_NAME      BYTES FILE_NAME
--------------- ---------- ---------------------------------------------
TOOLS             10485760 /home/oracle/data01/oradata/IBM/tools01.dbf
DRSYS             20971520 /home/oracle/data01/oradata/IBM/drsys01.dbf
USERS             20971520 /home/oracle/data01/oradata/IBM/users01.dbf
INDX              20971520 /home/oracle/data01/oradata/IBM/indx01.dbf
RBS               52428800 /home/oracle/data01/oradata/IBM/rbs01.dbf
TEMP              20971520 /home/oracle/data01/oradata/IBM/temp01.dbf
SYSTEM           283115520 /home/oracle/data01/oradata/IBM/system01.dbf

SQL> !ls //home/oracle/data01/oradata/IBM/*.dbf
//home/oracle/data01/oradata/IBM/data05_01.dbf  //home/oracle/data01/oradata/IBM/system01.dbf
//home/oracle/data01/oradata/IBM/data05_02.dbf  //home/oracle/data01/oradata/IBM/temp01.dbf
//home/oracle/data01/oradata/IBM/drsys01.dbf    //home/oracle/data01/oradata/IBM/tools01.dbf
//home/oracle/data01/oradata/IBM/indx01.dbf     //home/oracle/data01/oradata/IBM/users01.dbf
//home/oracle/data01/oradata/IBM/rbs01.dbf

dictionary에서는 삭제되었으나 여전히 물리적인 file은 존재한다. 삭제하면 된다.
(tablespace생성시에는 file이 그냥 생성되나 삭제시는 dictionary삭제후 강제로 삭제해줘야 한다.)

SQL> !rm /home/oracle/data01/oradata/IBM/data05*

================================================================================================  

* tablespace 의 online/offline, read only/read write

SQL> select tablespace_name, status from dba_tablespaces;

TABLESPACE_NAME                                              STATUS
------------------------------------------------------------ ------------------
SYSTEM                                                       ONLINE
TOOLS                                                        ONLINE
RBS                                                          ONLINE
TEMP                                                         ONLINE
USERS                                                        ONLINE
INDX                                                         ONLINE
DRSYS                                                        ONLINE

7 rows selected.

SQL> select tablespace_name from dba_tables
 2  where table_name ='DEPT' and owner='SCOTT';

TABLESPACE_NAME
------------------------------------------------------------
SYSTEM

default로 생성시 scott user의 data가 system tablespace에 생성되었으나 이렇게 쓰면 안된다.
하나 생성해볼까?

SQL> create tablespace data01
 2  datafile '/home/oracle/data01/oradata/IBM/data01.dbf' size 1m;

Tablespace created.

SQL> connect scott/tiger
Connected.

SQL> create table dept_tmp tablespace data01
 2  as select * from dept;
 
SQL> connect internal
Connected.
SQL> select tablespace_name from dba_tables
 2  where table_name ='DEPT_TMP' and owner='SCOTT';

TABLESPACE_NAME
------------------------------------------------------------
DATA01

SQL> select * from scott.dept_tmp;

   DEPTNO DNAME                        LOC
---------- ---------------------------- --------------------------
       10 ACCOUNTING                   NEW YORK
       20 RESEARCH                     DALLAS
       30 SALES                        CHICAGO
       40 OPERATIONS                   BOSTON
       
제대로 된다. 그렇다면 tablespace를 offline으로...

SQL> alter tablespace data01 offline;
SQL> select tablespace_name, status from dba_tablespaces
 2  where tablespace_name='DATA01';

TABLESPACE_NAME                                              STATUS
------------------------------------------------------------ ------------------
DATA01                                                       OFFLINE

SQL> select * from scott.dept_tmp;
select * from scott.dept_tmp
                   *
ERROR at line 1:
ORA-00376: file 8 cannot be read at this time
ORA-01110: data file 8: '/home/oracle/data01/oradata/IBM/data01.dbf'

위와 같이 error가 발생한다.
다시 online으로 해두자.
SQL> alter tablespace data01 online;

이번엔 read only로 변경
SQL> alter tablespace data01 read only;

SQL> select tablespace_name, status from dba_tablespaces
 2  where tablespace_name='DATA01';

TABLESPACE_NAME                                              STATUS
------------------------------------------------------------ ------------------
DATA01                                                       READ ONLY

변경되었다.

SQL> insert into scott.dept_tmp values(80,'new_dept','new_loc');
insert into scott.dept_tmp values(80,'new_dept','new_loc')
                 *
ERROR at line 1:
ORA-00372: file 8 cannot be modified at this time
ORA-01110: data file 8: '/home/oracle/data01/oradata/IBM/data01.dbf'

insert같은 DML(write성) 수행시 위와 같은 error 발생

원상복구
SQL> alter tablespace data01 read write;
SQL> insert into scott.dept_tmp values(80,'test','test');

제대로 된다.
================================================================================================  


9. Storage Structure and Relationships

================================================================================================  

* Extent 정보 조회 : 다음과 같이 각종 extent,segment 등의 정보를 조회해 볼 수 있다.

SQL> col owner format a10
SQL> col segment_type format a12
SQL> col segment_name format a12
SQL> col tablespace_name format a10

SQL> select owner,segment_name,segment_type, tablespace_name,max_extents,extents,pct_increase
 2  from dba_segments
 3  where max_extents - extents <= 10 and owner !='SYS';

no rows selected

SQL> select owner,segment_name,segment_type, tablespace_name,max_extents,extents,pct_increase
 2  from dba_segments
 3  where owner='SCOTT';

OWNER      SEGMENT_NAME SEGMENT_TYPE TABLESPACE MAX_EXTENTS    EXTENTS PCT_INCREASE
---------- ------------ ------------ ---------- ----------- ---------- ------------
SCOTT      DEPT_TMP     TABLE        DATA01             505          1           50
SCOTT      DEPT         TABLE        SYSTEM      2147483645          1           50
SCOTT      EMP          TABLE        SYSTEM      2147483645          1           50
SCOTT      BONUS        TABLE        SYSTEM      2147483645          1           50
SCOTT      SALGRADE     TABLE        SYSTEM      2147483645          1           50
SCOTT      PK_DEPT      INDEX        SYSTEM      2147483645          1           50
SCOTT      PK_EMP       INDEX        SYSTEM      2147483645          1           50


SQL> select segment_name,extents, initial_extent, next_extent,pct_increase
 2  from dba_segments
 3  where owner='SCOTT' and segment_name='EMP';

SEGMENT_NAME    EXTENTS INITIAL_EXTENT NEXT_EXTENT PCT_INCREASE
------------ ---------- -------------- ----------- ------------
EMP                   1          65536       65536           50


SQL> select segment_name,extent_id,block_id,bytes,blocks
 2  from dba_extents
 3  where owner='SCOTT' and segment_name='EMP';
 4  order by 2,3;
 
SEGMENT_NAME  EXTENT_ID   BLOCK_ID      BYTES     BLOCKS
------------ ---------- ---------- ---------- ----------
EMP                   0      33945      65536          8

================================================================================================  

* Free space 관리

tablespace내에 free space를 먼저 확인해본다.
SQL> select * from dba_free_space
 2  where tablespace_name ='DATA01' order by 1,2,3;

TABLESPACE    FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
---------- ---------- ---------- ---------- ---------- ------------
DATA01              8          7     999424        122            8

테이블을 여러개 생성해보자.
SQL> create table scott.dept2 tablespace data01 as select * from scott.dept;
SQL> create table scott.dept3 tablespace data01 as select * from scott.dept;
SQL> create table scott.dept4 tablespace data01 as select * from scott.dept;
SQL> create table scott.dept5 tablespace data01 as select * from scott.dept;
SQL> create table scott.dept6 tablespace data01 as select * from scott.dept;

SQL> select * from dba_free_space
 2  where tablespace_name ='DATA01' order by 1,2,3;

TABLESPACE    FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
---------- ---------- ---------- ---------- ---------- ------------
DATA01              8         32     794624         97            8

사용함에 따라 tablespace내 free space 가 줄어듦을 알 수 있다.

SQL> drop table scott.dept2;
drop table dept2
          *
ERROR at line 1:
ORA-04098: trigger 'SYS.JIS$ROLE_TRIGGER$' is invalid and failed re-validation
이건 또 뭐야 ? trigger가 걸려있네요...  
table drop 을 위해
SQL> alter trigger SYS.JIS$ROLE_TRIGGER$ disable;
drop table scott.dept3; ==> dept4 만 빼고 전부 drop
drop table scott.dept5;
drop table scott.dept6;

SQL> select * from dba_free_space
 2  where tablespace_name ='DATA01' order by 1,2,3;

TABLESPACE    FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
---------- ---------- ---------- ---------- ---------- ------------
DATA01              8          7      40960          5            8
DATA01              8         32     794624         97            8

tablespace의 free space가 늘긴 했는데 쪼개졌네요..
빈공간을 병합하자
SQL> alter tablespace data01 coalesce;

SQL> select * from dba_free_space
 2  where tablespace_name ='DATA01' order by 1,2,3;

TABLESPACE    FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
---------- ---------- ---------- ---------- ---------- ------------
DATA01              8          7      40960          5            8
DATA01              8         32     794624         97            8

그래도 두개로 쪼개져 있는 이유는? 중간에 dept4 가 사용하는 space가 coalesce 되지 않았기 때문

SQL> drop table scott.dept4;
SQL> alter tablespace data01 coalesce;

완전히 병합되었다.

================================================================================================  



10. Managing Rollback Segments

================================================================================================  

* rollback segment의 정보 조회

SQL> col owner format a10
SQL> col segment_name format a12
SQL> col segment_type format a12
SQL> col tablespace_name format a10
SQL> col status format a7

SQL> select segment_name,tablespace_name,status,initial_extent,next_extent,min_extents
 2  from dba_rollback_segs;

SEGMENT_NAME TABLESPACE STATUS  INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS
------------ ---------- ------- -------------- ----------- -----------
SYSTEM       SYSTEM     ONLINE           57344       57344           2
RBS0         RBS        ONLINE          524288      524288           8
RBS1         RBS        ONLINE          524288      524288           8
RBS2         RBS        ONLINE          524288      524288           8
RBS3         RBS        ONLINE          524288      524288           8
RBS4         RBS        ONLINE          524288      524288           8
RBS5         RBS        ONLINE          524288      524288           8
RBS6         RBS        ONLINE          524288      524288           8

================================================================================================  

* rollback segment 생성

SQL> create rollback segment rbs99
 2  tablespace rbs
 3  storage(initial 20k next 20k minextents 2 optimal 80k);

Rollback segment created.

SQL> select segment_name,tablespace_name,status,initial_extent,next_extent,min_extents
 2  from dba_rollback_segs;

SEGMENT_NAME TABLESPACE STATUS  INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS
------------ ---------- ------- -------------- ----------- -----------
SYSTEM       SYSTEM     ONLINE           57344       57344           2
RBS0         RBS        ONLINE          524288      524288           8
RBS1         RBS        ONLINE          524288      524288           8
RBS2         RBS        ONLINE          524288      524288           8
RBS3         RBS        ONLINE          524288      524288           8
RBS4         RBS        ONLINE          524288      524288           8
RBS5         RBS        ONLINE          524288      524288           8
RBS6         RBS        ONLINE          524288      524288           8
RBS99        RBS        OFFLINE          24576       32768           2

추가되었다. online으로 전환하자.

SQL> alter rollback segment rbs99 online;


SQL> create table emp2 as select * from emp;


SQL> select name,extents,xacts,shrinks,optsize
 2  from v$rollname n, v$rollstat s
 3  where n.usn = s.usn;

NAME                      EXTENTS      XACTS    SHRINKS    OPTSIZE
---------------------  ----------- ---------- ---------- ----------
SYSTEM                          9          0          0
RBS0                            8          0          0    4194304
RBS1                            8          0          0    4194304
RBS2                            8          0          0    4194304
RBS3                            8          0          0    4194304
RBS4                            8          0          0    4194304
RBS5                            8          0          0    4194304
RBS6                            8          0          0    4194304
RBS99                           2          0          0      81920   ==> extents,xacts의 변화 관찰


SQL> set transaction use rollback segment rbs99;
SQL> update emp2 set hiredate=sysdate;


SQL> select name,extents,xacts,shrinks,optsize
 2  from v$rollname n, v$rollstat s
 3  where n.usn = s.usn;

NAME               EXTENTS      XACTS    SHRINKS    OPTSIZE
--------------- ---------- ---------- ---------- ----------
SYSTEM                   9          0          0
RBS0                     8          0          0    4194304
RBS1                     8          0          0    4194304
RBS2                     8          0          0    4194304
RBS3                     8          0          0    4194304
RBS4                     8          0          0    4194304
RBS5                     8          0          0    4194304
RBS6                     8          0          0    4194304
RBS99                    2          1          0      81920 ==> transaction이 시작됨


SQL> update emp2 set hiredate=sysdate-1;  
sql> insert into emp2 select * from emp2; ==> 엄청 많이 수행 하자.


SQL> select name,extents,xacts,shrinks,optsize
 2  from v$rollname n, v$rollstat s
 3  where n.usn = s.usn;

NAME               EXTENTS      XACTS    SHRINKS    OPTSIZE
--------------- ---------- ---------- ---------- ----------
SYSTEM                   9          0          0
RBS0                     8          0          0    4194304
RBS1                     8          0          0    4194304
RBS2                     8          0          0    4194304
RBS3                     8          0          0    4194304
RBS4                     8          0          0    4194304
RBS5                     8          0          0    4194304
RBS6                     8          0          0    4194304
RBS99                    3          1          0      81920 ==> extents 증가


SQL> rollback;
SQL> set transaction use rollback segment rbs99;
SQL> update emp2 set sal=1000;


SQL> select name,extents,xacts,shrinks,optsize
 2  from v$rollname n, v$rollstat s
 3  where n.usn = s.usn;

NAME               EXTENTS      XACTS    SHRINKS    OPTSIZE
--------------- ---------- ---------- ---------- ----------
SYSTEM                   9          0          0
RBS0                     8          0          0    4194304
RBS1                     8          0          0    4194304
RBS2                     8          0          0    4194304
RBS3                     8          0          0    4194304
RBS4                     8          0          0    4194304
RBS5                     8          0          0    4194304
RBS6                     8          0          0    4194304
RBS99                    3          1          0      81920   ==> automatic 하게 shrink되었는지 확인

이전 tranx은 종료되었고 새로운 tranx가 시작됨

================================================================================================  

* rollback segment 삭제



SQL> rollback;


SQL> select name,extents,xacts,shrinks,optsize
 2  from v$rollname n, v$rollstat s
 3  where n.usn = s.usn; ==> xacts 가 '0' 인지 먼저 확인
 
SQL> alter rollback segment rbs99 offline;
SQL> drop rollback segment rbs99;
SQL> select segment_name,tablespace_name,status,initial_extent,next_extent,min_extents
 2  from dba_rollback_segs;

SEGMENT_NAME TABLESPACE STATUS  INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS
------------ ---------- ------- -------------- ----------- -----------
SYSTEM       SYSTEM     ONLINE           57344       57344           2
RBS0         RBS        ONLINE          524288      524288           8
RBS1         RBS        ONLINE          524288      524288           8
RBS2         RBS        ONLINE          524288      524288           8
RBS3         RBS        ONLINE          524288      524288           8
RBS4         RBS        ONLINE          524288      524288           8
RBS5         RBS        ONLINE          524288      524288           8
RBS6         RBS        ONLINE          524288      524288           8
 
확인해보니 삭제되었다.

================================================================================================  


11.Managing Tables

================================================================================================  

* Temporary Table

a. on commit perserve rows : session내에서 생성한 temp table에 대해서 지속적.
  새로운 session 연결 되면 data 지워짐

Example : Creating a Session-Specific Temporary Table
CREATE GLOBAL TEMPORARY TABLE ...
    [ON COMMIT PRESERVE ROWS ]

b. on commit delete rows : tansaction이 끝나면 temp table 내의 data가 지워짐(commit,rollback등)

Example : Creating a Transaction-Specific Temporary Table
CREATE GLOBAL TEMPORARY TABLE ...
    [ON COMMIT DELETE ROWS ]

================================================================================================  

* Using Temporary Tables to Improve Performance

You can use temporary tables to improve performance when you run complex queries.  
Running multiple such queries is relatively slow because the tables are accessed multiple times  
for each returned row. It is faster to cache the values from a complex query in a temporary table,  
then run the queries against the temporary table.  

For example, even with a view like this defined to simplify further queries,  
the queries against the view may be slow because the contents of the view are recalculated each time:  

CREATE OR REPLACE VIEW Profile_values_view AS
SELECT d.Profile_option_name, d.Profile_option_id, Profile_option_value,
      u.User_name, Level_id, Level_code
 FROM Profile_definitions d, Profile_values v, Profile_users u
WHERE d.Profile_option_id = v.Profile_option_id
  AND ((Level_code = 'USER' AND Level_id = U.User_id) OR
       (Level_code = 'DEPARTMENT' AND Level_id = U.Department_id) OR
       (Level_code = 'SITE'))
  AND NOT EXISTS (SELECT 1 FROM PROFILE_VALUES P
                   WHERE P.PROFILE_OPTION_ID = V.PROFILE_OPTION_ID
                     AND ((Level_code = 'USER' AND
                           level_id = u.User_id) OR
                          (Level_code = 'DEPARTMENT' AND
                           level_id = u.Department_id) OR
                          (Level_code = 'SITE'))
                     AND INSTR('USERDEPARTMENTSITE', v.Level_code) >
                         INSTR('USERDEPARTMENTSITE', p.Level_code));


A temporary table allows us to run the computation once,  
and cache the result in later SQL queries and joins:  

CREATE GLOBAL TEMPORARY TABLE Profile_values_temp
        (
            Profile_option_name   VARCHAR(60)   NOT NULL,
            Profile_option_id     NUMBER(4)     NOT NULL,
            Profile_option_value  VARCHAR2(20)  NOT NULL,
            Level_code            VARCHAR2(10)          ,
            Level_id              NUMBER(4)             ,
            CONSTRAINT Profile_values_temp_pk
               PRIMARY KEY (Profile_option_id)
        ) ON COMMIT PRESERVE ROWS ORGANIZATION INDEX;

INSERT INTO Profile_values_temp
      (Profile_option_name, Profile_option_id, Profile_option_value,
       Level_code, Level_id)
SELECT Profile_option_name, Profile_option_id, Profile_option_value,
       Level_code, Level_id
 FROM Profile_values_view;
COMMIT;


Now the temporary table can be used to speed up queries,  
and the results cached in the temporary table are freed automatically by the database  
when the session ends.  

================================================================================================  

* Row Migration Test

scott/tiger로 접속해서

SQL> create table chain_test(col1 varchar2(100));

Table created.

SQL> insert into chain_test values('a');

1 row created.

SQL> insert into chain_test select * from chain_test;   <====== 1 row created.
SQL> / <====== 2 rows created.
SQL> / <====== 4 rows created.
SQL> / <====== 8 rows created.
SQL> / <====== 16 rows created.
SQL> / <====== 32 rows created.
SQL> / <====== 64 rows created.
SQL> / <====== 128 rows created.
SQL> / <====== 256 rows created.
SQL> / <====== 512 rows created.
SQL> commit;

SQL> @$ORACLE_HOME/rdbms/admin/utlchain                 <====== chanined_rows table생성

Table created.

SQL> desc chained_rows
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
OWNER_NAME                                         VARCHAR2(30)
TABLE_NAME                                         VARCHAR2(30)
CLUSTER_NAME                                       VARCHAR2(30)
PARTITION_NAME                                     VARCHAR2(30)
SUBPARTITION_NAME                                  VARCHAR2(30)
HEAD_ROWID                                         ROWID
ANALYZE_TIMESTAMP                                  DATE

SQL> analyze table chain_test list chained rows;

Table analyzed.

SQL> select count(*) from chained_rows;

 COUNT(*)
----------
        0                             ======> 아직까지는 chaining이 하나도 없지...
         
SQL> update chain_test
 2  set col1 = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';

1024 rows updated.

SQL> analyze table chain_test list chained rows;

Table analyzed.

SQL> select count(*) from chained_rows;

 COUNT(*)
----------
      995                       ==============> row migration이 다량 발생


row migration이 일어나면 여러 block에서 읽어야 하므로 그만큼 performance가 떨어진다.
이를 해결하기 위해 주기적으로 analyze하여 확인해보고 insert를 다시 해주면 된다.
chaining이 일어난 row들의 rowid로 찾아서 임시table을 생성하고 원래 table에서 chaining이 일어난
data를 삭제하고 다시 insert하면 된다.


SQL> create table chain_tmp as select * from chain_test
 2  where rowid in (select head_rowid from chained_rows where table_name='CHAIN_TEST');

SQL> delete from chain_test
 2  where rowid in(select head_rowid from chained_rows where table_name='CHAIN_TEST');

SQL> insert into chain_test select *  from chain_tmp;

SQL> commit;

다시 cahined_rows table 을 삭제하고 analyze해보자.
SQL> truncate table chained_rows;

Table truncated.

SQL> analyze table chain_test list chained rows;

Table analyzed.

SQL> select * from chained_rows; <====== no rows selected

chaining이 없어졌다.

================================================================================================  


12. Managing Indexes

================================================================================================  

1. B*Tree Index 생성, 확인

SQL> col table_name format a10
SQL> col index_name format a20
SQL> col index_type format a10
SQL> col column_name format a12
SQL> create index scott.dept_dname_ind on scott.dept(dname);

Index created.

SQL> create unique index scott.dept_deptno_uind on scott.dept(deptno);
create unique index scott.dept_deptno_uind on scott.dept(deptno)
                                                        *
ERROR at line 1:
ORA-01408: such column list already indexed

error가 난 이유는 column이 pk로 지정될때는 unique index가 자동으로 생성되기 때문.

user_constraints, user_cons_columns 등에서 확인해보면 알수있다.

SQL> select table_name,index_name,index_type,uniqueness
 2  from dba_indexes
 3  where owner='SCOTT';

TABLE_NAME INDEX_NAME           INDEX_TYPE UNIQUENESS
---------- -------------------- ---------- ------------------
DEPT       DEPT_DNAME_IND       NORMAL     NONUNIQUE ====> 생성한 index
AUDIT_ACTI I_AUDIT_ACTIONS      NORMAL     UNIQUE
ONS

DEPT       PK_DEPT              NORMAL     UNIQUE
EMP        PK_EMP               NORMAL     UNIQUE
DBMS_LOCK_ SYS_C001456          NORMAL     UNIQUE
ALLOCATED

DBMS_ALERT SYS_C001457          NORMAL     UNIQUE
_INFO


SQL> select table_name,index_name,column_position,column_name
 2  from dba_ind_columns
 3  where index_owner='SCOTT';

TABLE_NAME INDEX_NAME           COLUMN_POSITION COLUMN_NAME
---------- -------------------- --------------- ------------
DEPT       DEPT_DNAME_IND                     1 DNAME               ====> index가 걸린 column
AUDIT_ACTI I_AUDIT_ACTIONS                    1 ACTION
ONS

AUDIT_ACTI I_AUDIT_ACTIONS                    2 NAME
ONS

DEPT       PK_DEPT                            1 DEPTNO
EMP        PK_EMP                             1 EMPNO
DBMS_LOCK_ SYS_C001456                        1 NAME
ALLOCATED

DBMS_ALERT SYS_C001457                        1 NAME
_INFO

DBMS_ALERT SYS_C001457                        2 SID
_INFO

================================================================================================  

* Bitmap Index 생성, 확인

SQL> select count(*) from scott.emp;
SQL> select distinct job from scott.emp;

JOB
------------------
ANALYST
CLERK
MANAGER
PRESIDENT
SALESMAN

SQL> create bitmap index scott.emp_job_bind on scott.emp(job);

SQL> select table_name,index_name,index_type,uniqueness
 2  from dba_indexes
 3  where owner='SCOTT';

TABLE_NAME INDEX_NAME           INDEX_TYPE UNIQUENESS
---------- -------------------- ---------- ------------------
DEPT       DEPT_DNAME_IND       NORMAL     NONUNIQUE
EMP        EMP_JOB_BIND         BITMAP     NONUNIQUE =====>
AUDIT_ACTI I_AUDIT_ACTIONS      NORMAL     UNIQUE
...

SQL> select table_name,index_name,column_position,column_name
 2  from dba_ind_columns
 3  where index_owner='SCOTT';

TABLE_NAME INDEX_NAME           COLUMN_POSITION COLUMN_NAME
---------- -------------------- --------------- ------------
DEPT       DEPT_DNAME_IND                     1 DNAME
EMP        EMP_JOB_BIND                       1 JOB =====>
AUDIT_ACTI I_AUDIT_ACTIONS                    1 ACTION
ONS

================================================================================================  

* Reverse Key Index 생성, 확인

SQL> create index scott.emp_hiredate_rind on scott.emp(hiredate) reverse;

SQL> select table_name,index_name,index_type,uniqueness
 2  from dba_indexes
 3  where owner='SCOTT';

TABLE_NAME INDEX_NAME           INDEX_TYPE UNIQUENESS
---------- -------------------- ---------- ------------------
DEPT       DEPT_DNAME_IND       NORMAL     NONUNIQUE
EMP        EMP_HIREDATE_RIND    NORMAL/REV NONUNIQUE ==>
EMP        EMP_JOB_BIND         BITMAP     NONUNIQUE
....

SQL> select table_name,index_name,column_position,column_name
 2  from dba_ind_columns
 3  where index_owner='SCOTT';

TABLE_NAME INDEX_NAME           COLUMN_POSITION COLUMN_NAME
---------- -------------------- --------------- ------------
DEPT       DEPT_DNAME_IND                     1 DNAME
EMP        EMP_HIREDATE_RIND                  1 HIREDATE ==>
EMP        EMP_JOB_BIND                       1 JOB
....

================================================================================================  

* Funtion-Based Index 생성, 확인 <===== Query Rewrite권한 필요

SQL> create index scott.emp_sal_find on scott.emp(sal * 1.1);


SQL> select table_name,index_name,index_type,uniqueness
 2  from dba_indexes
 3  where owner='SCOTT';

TABLE_NAME INDEX_NAME           INDEX_TYPE UNIQUENESS
---------- -------------------- ---------- ------------------
DEPT       DEPT_DNAME_IND       NORMAL     NONUNIQUE
EMP        EMP_HIREDATE_RIND    NORMAL/REV NONUNIQUE
EMP        EMP_JOB_BIND         BITMAP     NONUNIQUE
EMP        EMP_SAL_FIND         FUNCTION-B NONUNIQUE ==>
                               ASED NORMA
                               L
....

SQL> select table_name,index_name,column_position,column_name
 2  from dba_ind_columns
 3  where index_owner='SCOTT';

TABLE_NAME INDEX_NAME           COLUMN_POSITION COLUMN_NAME
---------- -------------------- --------------- ------------
DEPT       DEPT_DNAME_IND                     1 DNAME
EMP        EMP_HIREDATE_RIND                  1 HIREDATE
EMP        EMP_JOB_BIND                       1 JOB
EMP        EMP_SAL_FIND                       1 SYS_NC00009$   ====> column name이 내부적으로 바뀐다.

....

================================================================================================  

* Index drop

SQL> drop index scott.dept_dname_ind;
SQL> drop index scott.emp_hiredate_rind;
SQL> drop index scott.emp_job_bind;
SQL> drop index scott.emp_sal_find;

================================================================================================  


13.Maintaining Data Integrity

================================================================================================  

* PK/UK 와 Unique Index

SQL> desc scott.dept
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
DEPTNO                                    NOT NULL NUMBER(2)
DNAME                                              VARCHAR2(14)
LOC                                                VARCHAR2(13)

PK생성은 다음과 같이 할 수 있다.

SQL> alter table scott.dept
 2  add constraint dept_deptno_pk primary key(deptno);
add constraint dept_deptno_pk primary key(deptno)
                             *
ERROR at line 2:
ORA-02260: table can have only one primary key

이미 pk가 설정이 되어있어서 한테이블에 두개의 pk를 설정할 수 없다는 error.

SQL> alter table scott.dept
 2  add constraint dept_dname_uk unique (dname);

Table altered.

SQL> select table_name,constraint_name,constraint_type, status
 2  from dba_constraints
 3  where owner='SCOTT';

TABLE_NAME           CONSTRAINT_NAME CO STATUS
-------------------- --------------- -- ----------------
DEPT                 DEPT_DNAME_UK   U  ENABLED <=== 새로 생성한 UK
EMP                  FK_DEPTNO       R  ENABLED
DEPT                 PK_DEPT         P  ENABLED
EMP                  PK_EMP          P  ENABLED
AUDIT_ACTIONS        SYS_C001454     C  ENABLED
AUDIT_ACTIONS        SYS_C001455     C  ENABLED
DBMS_LOCK_ALLOCATED  SYS_C001456     P  ENABLED
DBMS_ALERT_INFO      SYS_C001457     P  ENABLED


SQL> select table_name,index_name,index_type,uniqueness
 2  from dba_indexes
 3  where owner='SCOTT';

TABLE_NAME INDEX_NAME           INDEX_TYPE UNIQUENESS
---------- -------------------- ---------- ------------------
DEPT       DEPT_DNAME_UK        NORMAL     UNIQUE <==
AUDIT_ACTI I_AUDIT_ACTIONS      NORMAL     UNIQUE
ONS

SQL> select table_name,index_name,column_position,column_name
 2  from dba_ind_columns
 3  where index_owner='SCOTT';

TABLE_NAME INDEX_NAME           COLUMN_POSITION COLUMN_NAME
---------- -------------------- --------------- ------------
DEPT       DEPT_DNAME_UK                      1 DNAME  <==  
AUDIT_ACTI I_AUDIT_ACTIONS                    1 ACTION
ONS

================================================================================================  

* Constraint Check

SQL> insert into scott.dept values(50,'HR','SEOUL');

1 row created.

SQL> commit;

Commit complete.

SQL> insert into scott.dept values(50,'HR Dept','SEOUL');
insert into scott.dept values(50,'HR Dept','SEOUL')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.PK_DEPT) violated

UK 값에 같은 값 insert하려다가 error가 난다.

================================================================================================  

* Constriaint 비활성화/활성화


SQL> alter table scott.dept
 2  disable constraint dept_dname_uk;

SQL> alter table scott.dept
 2  enable constraint dept_dname_uk;

================================================================================================  

* Deferred Constraint(?) ==> 자료좀 찾아보자..

================================================================================================  

* Constraint 삭제

alter table <테이블명> drop constraint

================================================================================================  


14. Loading Data

================================================================================================  

* 사용법

Usage: SQLLOAD keyword=value [,keyword=value,...]

Valid Keywords:

   userid -- ORACLE username/password
  control -- Control file name
      log -- Log file name
      bad -- Bad file name
     data -- Data file name
  discard -- Discard file name
discardmax -- Number of discards to allow          (Default all)
     skip -- Number of logical records to skip    (Default 0)
     load -- Number of logical records to load    (Default all)
   errors -- Number of errors to allow            (Default 50)
     rows -- Number of rows in conventional path bind array or between direct path data saves
              (Default: Conventional path 64, Direct path all)
 bindsize -- Size of conventional path bind array in bytes  (Default 65536)
   silent -- Suppress messages during run (header,feedback,errors,discards,partitions)
   direct -- use direct path                      (Default FALSE)
  parfile -- parameter file: name of file that contains parameter specifications
 parallel -- do parallel load                     (Default FALSE)
     file -- File to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions  (Default FALSE)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable  (Default FALSE)
commit_discontinued -- commit loaded rows when load is discontinued  (Default FALSE)
 readsize -- Size of Read buffer                  (Default 1048576)

PLEASE NOTE: Command-line parameters may be specified either by
position or by keywords.  An example of the former case is 'sqlload
scott/tiger foo'; an example of the latter is 'sqlload control=foo
userid=scott/tiger'.  One may specify parameters by position before
but not after parameters specified by keywords.  For example,
'sqlload scott/tiger control=foo logfile=log' is allowed, but
'sqlload scott/tiger control=foo log' is not, even though the
position of the parameter 'log' is correct.

================================================================================================  
* case 별로 sqlldr을 사용하는법은  
http://technet.oracle.com/doc/server.815/a67792/ch04.htm#1364
에 자세히 나와있다. 그중 두가지 정도의 case만 기본적으로 다루어보자.

================================================================================================  

* case1 : data를 control file에 직접 입력하여 load하기

a. data 입력될 table 있어야함 (dept_tmp 라는 table을 생성하여 입력해보자)

SQL> create table dept_tmp as select * from dept;

Table created.

SQL> truncate table dept_tmp;

Table truncated.

b. control file을 구성한다.


load data
infile * ==> data 가 ctl file 끝에 있다는 의미
replace                   ==> 이게 없으면 빈테이블일때만 load된다.
into table dept_tmp
fileds terminated by ',' optionally enclosed by '"' ==> field 구분자와 "가 들어가면 빼고 입력된다.
(deptno,dname,loc)
begindata
12,research,"saratoga"
10,"accounting",cleveland
11,"art","salem"
13,finance,boston

c. 다음과 같이 sqlldr을 실행
oracle@swsvrctr:/home/oracle> sqlldr scott/tiger control=test.ctl log=test.log bad=test.bad
error가 생기면 log가 남고 loading 되지 않은 data만 bad file에 남는다.

================================================================================================  

* case 2 : Fixed-format records의 Loading

a. data 입력될 table 있어야함 (dept_tmp 라는 table을 생성하여 입력해보자)
SQL> create table emp_tmp as select * from emp;

Table created.

b. data file의 내용을 보고 그에 맞게 control file을 구성한다.

data file은 다음과 같다고 하자.

1111    joo     Manager         1111    19191.00        10
2222    hwang   salesman        2222    294974.50       20
3333    test    test            3333    4984.00         40
4444    kwon    engineer        4444    49.90           50

control file을 만들어보자.

load data
infile '/home/oracle/test.dat'
replace
into table emp_tmp

(empno position(01:04) integer external, ==> position을 일일이 맞추어 준다.
ename position(09:14) char,
job position(17:24) char,
mgr position(33:36) integer external,
sal position(41:49) decimal external,
comm position(51:54) decimal external,
deptno position(57:58) integer external)

주의 : data file의 data가 공백이 아닌 tab 으로 되어있으면 position에서 한칸으로 인식되니까 주의

c. 다음과 같이 sqlldr을 실행
home/oracle> sqlldr scott/tiger control=test.ctl data=test.dat log=test.log bad=test.bad

================================================================================================  


15. Reorganizing Data

================================================================================================  

* 오래 사용한 table 주로 DML성 문장이 자주 일어나 performance에 영향을 미치므로 주기적으로
 Reorganize 를 해주는것이 좋다.
 
 Export => table drop => import 순으로 한다.
 
 export 는 user 별로 table별로 받을 수 있다.
 
 a. Export

oracle@swsvrctr:/home/oracle> exp scott/tiger tables='dept,emp' file=test.dmp

Export: Release 8.1.6.0.0 - Production on Wed Jul 4 14:32:21 2001

(c) Copyright 1999 Oracle Corporation.  All rights reserved.


Connected to: Oracle8i Enterprise Edition Release 8.1.6.0.0, 64 bit - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
Export done in KO16KSC5601 character set and WE8ISO8859P1 NCHAR character set
server uses WE8ISO8859P1 character set (possible charset conversion)

About to export specified tables via Conventional Path ...
. . exporting table                           DEPT          7 rows exported
. . exporting table                            EMP         14 rows exported
Export terminated successfully without warnings.

 b. drop table
 
oracle@swsvrctr:/home/oracle> sqlplus scott/tiger

SQL> drop table emp;
SQL> drop table dept;

 c. Import
 
oracle@swsvrctr:/home/oracle> imp scott/tiger tables='dept,emp' file=test.dmp

Import: Release 8.1.6.0.0 - Production on Wed Jul 4 14:34:25 2001

(c) Copyright 1999 Oracle Corporation.  All rights reserved.


Connected to: Oracle8i Enterprise Edition Release 8.1.6.0.0, 64 bit - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

Export file created by EXPORT:V08.01.06 via conventional path
import done in KO16KSC5601 character set and WE8ISO8859P1 NCHAR character set
import server uses WE8ISO8859P1 character set (possible charset conversion)
. importing SCOTT's objects into SCOTT
. . importing table                         "DEPT"          7 rows imported
. . importing table                          "EMP"         14 rows imported
About to enable constraints...
Import terminated successfully without warnings.


 d. 제대로 되었나 조회

SQL> select * from dept;
SQL> select * from emp;

================================================================================================  


16. Managing Password Security and Resources

================================================================================================  


* verify_function 생성을 위해 돌려줘야 할 script : $ORACLE_HOME/rdbms/admin/utlpwdmg.sql

  NAME
    utlpwdmg.sql - script for Default Password Resource Limits

  DESCRIPTION
    This is a script for enabling the password management features
    by setting the default password resource limits.

  NOTES
    This file contains a function for minimum checking of password
    complexity. This is more of a sample function that the customer
    can use to develop the function for actual complexity checks that the
    customer wants to make on the new password.

  MODIFIED   (MM/DD/YY)
  asurpur     04/17/97 - Fix for bug479763
  asurpur     12/12/96 - Changing the name of password_verify_function
  asurpur     05/30/96 - New script for default password management
  asurpur     05/30/96 - Created

================================================================================================  

* verify_function 생성 및 패스워드 관리기능 활성화

SQL> @$ORACLE_HOME/rdbms/admin/utlpwdmg

Function created.


Profile altered.

================================================================================================  

* 사용자 생성

utlpwdmg.sql script를 돌려 verify_function을 생성후 user를 생성할때는 몇가지를 check하여 좀더  
password 관리를 할 수 있도록 해준다.  
다음과 같이 user/passwd를 같게 하면 error가 나서 생성되지 않는다.

SQL> create user myuser identified by myuser
 2  default tablespace TS_USER1
 3  temporary tablespace TEMP;
create user myuser identified by myuser
*
ERROR at line 1:
ORA-28003: password verification for the specified password failed
ORA-20001: Password same as user

다시 시도
SQL> create user myuser identified by mypasswd9$
 2  default tablespace ts_user1
 3  temporary tablespace temp;

User created.

SQL> grant connect,resource to myuser;

확인
SQL> connect myuser/mypasswd9$

================================================================================================  

* 패스워드 관리/ expire 시키기

SQL> alter user myuser password expire;

User altered.

admin이 강제로 expire시켰기 때문에 다음과 같이 password변경을 뭍는다.
SQL> connect myuser/mypassword9$
Changing password for test
New password:
Retype new password:
Password changed
Connected.

password를 또 규칙에 맞지 않게 넣으면 다음과 같은 error가 발생한다.

ERROR:
ORA-00988: missing or invalid password(s)

================================================================================================  

* dictionary 조회

SQL> select resource_name,limit from dba_profiles  
 2  where profile='DEFAULT' and resource_type='PASSWORD';

RESOURCE_NAME        LIMIT
-------------------- ---------------
FAILED_LOGIN_ATTEMPT 3
S

PASSWORD_LIFE_TIME   60
PASSWORD_REUSE_TIME  1800
PASSWORD_REUSE_MAX   UNLIMITED
PASSWORD_VERIFY_FUNC VERIFY_FUNCTION
TION

PASSWORD_LOCK_TIME   .0006
PASSWORD_GRACE_TIME  10

RESOURCE_NAME        LIMIT
-------------------- ---------------
FAILED_LOGIN_ATTEMPT 3
S

PASSWORD_LIFE_TIME   60
PASSWORD_REUSE_TIME  1800
PASSWORD_REUSE_MAX   UNLIMITED
PASSWORD_VERIFY_FUNC VERIFY_FUNCTION
TION

PASSWORD_LOCK_TIME   .0006
PASSWORD_GRACE_TIME  10

================================================================================================  


17. Managing Users

================================================================================================  

* OS 인증 : os에 login 한 id/passwd로 oracle의 id/passwd로 함께 사용하기 위한방법

a. user를 생성하는데 identified externally로 생성한다.

oracle@swsvrctr:/home/oracle> sqlplus internal
SQL> create user oracle identified externally
 2  default tablespace ts_user1
 3  temporary tablespace temp;

User created.

SQL> grant connect,resource to oracle;
SQL> revoke unlimited tablespace from oracle;
SQL> shutdown immediate

b. init.ora 에서 다음을 편집한다.(추가)
os_authent_prefix=""

c. startup하고 확인해본다.

SQL> startup
SQL> exit
oracle@swsvrctr:/home/oracle> sqlplus / ==> id/passwd를 넣을 필요없이 접속

SQL> select user from dual;

USER
------------------------------------------------------------
ORACLE

제대로 접속이 된다.

================================================================================================  

* tablespace 사용량 통제

SQL> connect internal
Connected.
SQL> col tablespacename format a10
SQL> col username format a10
SQL> alter user oracle quota 20k on ts_user1;  ==> oracle user는 ts_user1에 20k 만 사용 가능하다.

User altered.

SQL> select * from dba_ts_quotas;

TABLESPACE_NAME                                              USERNAME
------------------------------------------------------------ ----------
    BYTES  MAX_BYTES     BLOCKS MAX_BLOCKS
---------- ---------- ---------- ----------
TS_USER1                                                     ORACLE
        0      20480          0          5

SQL> connect /
Connected.
SQL> select user from dual;

USER
------------------------------------------------------------
ORACLE

SQL> create table test
 2  (id number(10))
 3  (tablespace ts_user1
 4  storage(initial 20k)
 
까지는 생성이 되나 다음과 같이 늘리려고 하면 error가 난다.

SQL> alter table test allocate extent(size 4k); ==> error

================================================================================================  


18. Managing Privileges

================================================================================================  

* with grant option과 with admin option  

(둘다 실행 권한을 받은 user가 다시 실행 권한을 다른 user에게 줄 수 있게 해주는 option이다.)
-- 차이는 with admin option으로 권한을 받은 user1이 다른 user2에게 권한을 부여한 후 user1으로부터
  권한을 revoke하면 user1의 권한만 revoke되나
  with grant option으로 부여하면 user1에게 revoke 될 시 user2의 권한도 cascade로 revoke된다.


oracle@swsvrctr:/home/oracle> sqlplus internal

SQL> col grantor format a10
SQL> col grantee format a10
SQL> col table_name format a10
SQL> col table_schema format a10
SQL> col privilege format a25
SQL> grant create user to scott with admin option; ==> with admin option으로 권한 부여후
SQL> connect scott/tiger
SQL> grant create user to oracle; ==> 다시 oracle 에게 같은 권한 부여후
SQL> connect internal
SQL> select * from dba_sys_privs
 2  where grantee in ('SCOTT','ORACLE');

GRANTEE    PRIVILEGE                 ADMIN_
---------- ------------------------- ------
ORACLE     CREATE USER               NO
SCOTT      CREATE USER               YES
SCOTT      UNLIMITED TABLESPACE      NO

SQL> revoke create user from scott; ==> scott의 권한을 revoke
SQL> select * from dba_sys_privs
 2  where grantee in ('SCOTT','ORACLE');

GRANTEE    PRIVILEGE                 ADMIN_
---------- ------------------------- ------
ORACLE     CREATE USER               NO ==> scott의 create user 권한만 revoke되었다.  
SCOTT      UNLIMITED TABLESPACE      NO     oracle권한은 그대로

SQL> grant select on dept to oracle with grant option; ==> with grant option 으로 권한 부여후
SQL> connect /
SQL> create user myuser identified by myuser1$
 2  default tablespace ts_user1
 3  temporary tablespace temp;

SQL> grant select on scott.dept to myuser; ==> 다시 같은 권한을 다른 myuser에게 부여

Grant succeeded.

SQL> select * from all_tab_privs
 2  where table_name='DEPT';

GRANTOR    GRANTEE    TABLE_SCHE TABLE_NAME PRIVILEGE                 GRANTA
---------- ---------- ---------- ---------- ------------------------- ------
SCOTT      ORACLE     SCOTT      DEPT       SELECT                    YES
ORACLE     MYUSER     SCOTT      DEPT       SELECT                    NO

SQL> revoke select on dept from oracle; ==> oracle의 권한을 revoke

Revoke succeeded.

SQL> select * from all_tab_privs           ==> with grant option으로 생성된 이하 myuser의 권한도
 2  where table_name='DEPT';      revoke 되었다.

no rows selected


================================================================================================  

* Database Auditing : user 사용 시간정보 확인, 동시사용자측정 등 여러가지에 필요

SQL> connect internal
SQL> shutdown immediate

init.ora file에서 편집
audit_trail = true            # if you want auditing ==> 주석기호(#) 삭제

SQL> startup

SQL> show parameter audit_trail
NAME                                 TYPE     VALUE                          
------------------------------------ -------------- ------------------------------
audit_trail                          string         TRUE

SQL> audit connect;
SQL> select * from dba_stmt_audit_opts;
USER_NAME            PROXY_NAME           AUDIT_OPTION    SUCCESS    FAILURE
-------------------- -------------------- --------------- ---------- ----------
                                         CREATE SESSION  BY ACCESS  BY ACCESS
                                         
SQL> connect scott/tiger
SQL> connect scott/fail
SQL> connect internal
SQL> select username,timestamp,action_name,logoff_time,returncode
 2  from dba_audit_session;

USERNAME   TIMESTAMP ACTION_NAME     LOGOFF_TI RETURNCODE
---------- --------- --------------- --------- ----------
SCOTT      05-JUL-01 LOGOFF          05-JUL-01          0 ==> login 성공하면 0 return
SCOTT      05-JUL-01 LOGON                           1017 ==> login 실패한 returncode

SQL> shutdown

파라미터 이전대로 돌려두자(#audit_trail=true : 주석처리)

SQL> startup 하고
SQL> show parameter audit_trail
NAME                                 TYPE     VALUE                          
------------------------------------ -------------- ------------------------------
audit_trail                          string         NONE

================================================================================================  


19. Managing Roles

================================================================================================  

* Role

resource role에 포함된 권한을 살펴보자
SQL> select  * from dba_sys_privs
 2  where grantee='RESOURCE';
 

GRANTEE    PRIVILEGE            ADMIN_
---------- -------------------- ------
RESOURCE   CREATE CLUSTER       NO
RESOURCE   CREATE INDEXTYPE     NO
RESOURCE   CREATE OPERATOR      NO
RESOURCE   CREATE PROCEDURE     NO
RESOURCE   CREATE SEQUENCE      NO
RESOURCE   CREATE TABLE         NO
RESOURCE   CREATE TRIGGER       NO
RESOURCE   CREATE TYPE          NO

8 rows selected.

다음은 dev라는 role을 만들어서
SQL> create role dev;
SQL> grant create table,create view to dev;
SQL> grant select on emp to dev;
SQL> connect internal

oracle이라는 user에게 dev,resource role, create session권한 부여
SQL> connect internal
SQL> grant dev to oracle;
SQL> grant resource to oracle;
SQL> grant create session to oracle;
SQL> alter user oracle default role resource;            ==> session의 연결 끊김에 상관없이 지속적으로
SQL> grant select_catalog_role to oracle;                logon 후 resource role이 enable되게 함
                                                            (set 할 필요 없이)
SQL> select segment_name,status from  dba_rollback_segs; ==> 현재 session에서 select_catalog_role이  
select segment_name,status from  dba_rollback_segs           disabled됨
                                *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> set role select_catalog_role; ==> set은 현재session에서 role을 사용가능하게 해줌.
   이를 위해 이 role은 이미 user에게 grant 되어있어야함.
SQL> select segment_name,status from  dba_rollback_segs;

--------------- --------------------------------
SEGMENT_NAME    STATUS
SYSTEM          ONLINE
RBS1            ONLINE
RBS2            ONLINE

================================================================================================  


20. Using National Language Support

================================================================================================  

* sysdate format 변경

SQL> connect internal
SQL> select sysdate from dual;

SYSDATE
---------
05-JUL-01

SQL> alter session set nls_date_format='YY/MM/DD:HH24:MI:SS';
SQL> select sysdate from dual;

SYSDATE
-----------------
01/07/05:12:25:37

================================================================================================  

* Character set 변경하고 한글명 table 만들기
-- 가급적 한글명 table은 만들지 않는것이 좋으나 만들수 없는것은 아니다.

SQL> create table scott.부서 as select scott.dept;
create table scott.부서 as select scott.dept
                  *
ERROR at line 1:
ORA-00911: invalid character ==> 테이블명이 한글이어서 error난다.


* Database Characterset을 변경해 보자. ==> 매우 조심스러운 작업
    (DATA 보존 못할 위험성 있다.backup 필요)

SQL> select * from nls_database_parameters ==> nls_database_parameters 에서 현재 DB의  
 2  where parameter like '%CHARACTERSET%';     characterset관련을 parameter를 확인
 
PARAMETER                 VALUE
------------------------- --------------------
NLS_CHARACTERSET          WE8ISO8859P1
NLS_NCHAR_CHARACTERSET    WE8ISO8859P1

SQL> select value from v$nls_valid_values ==> 234건의 data가 있다.
 2  where parameter like '%CHARACTERSET';

-- warning : character set을 변경 할수는 있지만 기존에 들어가있는 데이타에 대해서는 책임 못짐.

a.  
SQL> shutdown immediate
SQL> connect internal
SQL> startup mount exclusive;
SQL> alter system enable restricted session;
SQL> alter database open;

b.  
SQL> alter database character set ko16ksc5601;
SQL> alter database national chartacter charcter set ko16ksc5601;
-- 확인
SQL> select * from nls_database_parameters ==> nls_database_parameters 에서 현재 DB의  
 2  where parameter like '%CHARACTERSET%';     characterset관련을 parameter를 확인

shutdown immediate;

c. .profile edit
NLS_LANG=Amerian_America.us7ascii; export NLS_LANG을
NLS_LANG=korean_korea.ko16ksc5601; export NLS_LANG로 변경

d. Database startup

출처 : http://www.xguru.pe.kr/techbrd/read.cgi?board=ksko&y_number=6

반응형
Posted by [PineTree]
ORACLE/ADMIN2006. 3. 15. 23:30
반응형

장애의 유형과 문제해결

※ SCENARIO 0 : Tablespace의 조작
※ SCENARIO 1 : Online Redo Log의 Mirroring
※ SCENARIO 2 : Full Offline Backup 수행
※ SCENARIO 3 : Recovery - Temporary Tablespace의 유실
※ SCENARIO 4 : Noarchive Log Mode Recovery - Disk의 유실
※ SCENARIO 5 : Read Only Tablespace의 Backup & Recovery
※ SCENARIO 6 : DATABASE의 BACKUP - Control File Mirroring & Archive log mode
※ SCENARIO 7 : Complete Recovery(Archive) - User의 DATA FILE 유실
※ SCENARIO 8 : Complete Recovery(ARchive) - Tablespace Recovery
※ SCENARIO 9 : Complete Recovery(ARchive) - Datafile Recovery
※ SCENARIO 10 : Parallel Recovery(Archive)
※ SCENARIO 11 : Complete Recovery - Shutdown 하지 않고 Data File만 Recovery
※ SCENARIO 12 : Online Backup (Hot Backup)
※ SCENARIO 13 : Online Backup 실패 후 Recovery - Online Backup 도중에 정전
※ SCENARIO 14 : Incomplete Recovery(Noarchive) - 실수로 Drop한 Table의 복구
※ SCENARIO 15 : Inactive Online Redo Log Group의 유실
※ SCENARIO 16 : Current Online Redo Log Group의 유실
※ SCENARIO 17 : 모든 Online Redo Log Group의 유실
※ SCENARIO 18 : 모든 Redo Log & Data File 유실
※ SCENARIO 19 : Control File Recreate
※ SCENARIO 20 : 모든 Control File 유실
※ SCENARIO 21 : Control File과 Data File 동시에 유실
※ SCENARIO 22 : Read Only Tablespace의 상태변경에 따른 Recovery -1
※ SCENARIO 23 : Read Only Tablespace의 상태변경에 따른 Recovery -2
※ SCENARIO 24 : Read Only Tablespace의 상태변경에 따른 Recovery -3
※ SCENARIO 25 : Recovery from Online Backup - Data File, Control File 유실
※ SCENARIO 26 : Recovery from Online Backup - File들 모두가 사라졌다. 
                          게다가, Archived Redo Log File의 일부가 없고,
                          Data File Backup도 일부 없다.
※ SCENARIO 27 : Recover with No Backup
※ SCENARIO 28 : Incremental export 와 direct path
※ SCENARIO 29 : standby database 생성
※ SCENARIO 30 : Catalog DB를 이용한 복구 Oracle8

 

 
<SCENARIO 0 : Tablespace의 조작>


① 새로운 Tablespace Create
  [/DBA3/DBA/dba숫자]svrmgrl

  SVRMGR> connect internal
  SVRMGR> startup
  SVRMGR> create tablespace test
       2> datafile '/DBA3/DBA/dba숫자/u01/test_01.dbf'
       3> size 10k;
  SVRMGR> select tablespace_name, bytes, file_name from dba_data_files;

② Table Create

  SVRMGR> create table test(name char(30))
       2> tablespace test
       3> storage(initial 4k);

③ Table에 Row들을 Insert

  SVRMGR> @?/labs/test100
          Statement processed.

  SVRMGR> @?/labs/test100
          ORA-01653: unable to extend table SYS.TEST by 5 in tablespace TEST
          ORA-06512: at line 6

④ Tablespace를 늘인다

  SVRMGR> alter tablespace test
       2> add datafile '/DBA3/DBA/dba숫자/u01/test_02.dbf' size 30k;
          Statement processed.

  SVRMGR> @?/labs/test100
          Statement processed.

  SVRMGR> select tablespace_name, bytes, file_name from dba_data_files;

  SVRMGR> !ls -la $ORACLE_HOME/u01  --> "test_02.dbf" file 크기 확인

          total 22563
          drwxrwxr-x   2 dbamgr     dba          512 Feb 24 13:08 .
          drwxrwxr-x  43 dba숫자    dba         1024 Feb 20 23:21 ..
          -rw-rw----   1 dba숫자    dba       514048 Feb 24 13:05 index_01.dbf
          -rw-rw----   1 dba숫자    dba       155648 Feb 24 13:05 log1a.rdo
          -rw-rw----   1 dba숫자    dba       155648 Feb 24 13:09 log2a.rdo
          -rw-rw----   1 dba숫자    dba       155648 Feb 24 12:55 log3a.rdo
          -rw-rw----   1 dba숫자    dba     10487808 Feb 24 13:09 system.dbf
          -rw-rw----   1 dba숫자    dba        12288 Feb 24 13:09 test_01.dbf
          -rw-rw----   1 dba숫자    dba        32768 Feb 24 13:09 test_02.dbf

⑤ Datafile의 크기를 늘인다

  SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u01/test_02.dbf'  resize 50k;
          Statement processed.

  SVRMGR> select tablespace_name, bytes, file_name from dba_data_files;
  SVRMGR> !ls -la $ORACLE_HOME/u01

⑥ Test가 끝나면 Drop

  SVRMGR> drop tablespace test;
          drop tablespace test
          *
          ORA-01549: tablespace not empty, use INCLUDING CONTENTS option
  SVRMGR> drop tablespace test including contents;
          Statement processed.
  SVRMGR> select tablespace_name, bytes, file_name from dba_data_files;
  SVRMGR> !ls -la $ORACLE_HOME/u01
          total 22611
          drwxrwxr-x   2 dbamgr   dba          512 Feb 24 13:08 .
          drwxrwxr-x  43 dba35    dba         1024 Feb 20 23:21 ..
          -rw-rw----   1 dba35    dba       514048 Feb 24 13:05 index_01.dbf
          -rw-rw----   1 dba35    dba       155648 Feb 24 13:05 log1a.rdo
          -rw-rw----   1 dba35    dba       155648 Feb 24 13:18 log2a.rdo
          -rw-rw----   1 dba35    dba       155648 Feb 24 12:55 log3a.rdo
          -rw-rw----   1 dba35    dba     10487808 Feb 24 13:18 system.dbf
          -rw-rw----   1 dba35    dba        12288 Feb 24 13:18 test_01.dbf
          -rw-rw----   1 dba35    dba        53248 Feb 24 13:18 test_02.dbf

⑦ Datafile도 삭제

  SVRMGR> !rm $ORACLE_HOME/u01/test_0*
  SVRMGR> !ls -la $ORACLE_HOME/u01
  SVRMGR> shutdown immediate
          Database closed.
          Database dismounted.
          ORACLE instance shut down.
  SVRMGR> exit

          Server Manager complete.

 

 
<SCENARIO 1 : Online Redo Log의 Mirroring>


  SVRMGR> select * from v$log;
  SVRMGR> select * from v$logfile;
  SVRMGR> alter database add logfile member
          '/DBA3/DBA/dba숫자/u02//log그룹번호b.rdo’to 그룹번호;
          -> 각 그룹마다 멤버의 수를 갖게 미러링한다.

  SVRMGR> select * from v$logfile;

 

 
<SCENARIO 2 : Full Offline Backup 수행>


① database를 shutdown한 상태에서 init/control/data file을 backup 폴더에 copy

① Database를 Startup
  [/DBA3/DBA/dba숫자]svrmgrl
  SVRMGR> connect internal
  SVRMGR> startup

② Tablespace 정보를 확인(DBA_DATA_FILES, V$DATAFILE)
  SVRMGR> select TABLESPACE_NAME, FILE_NAME
       2> from dba_data_files;  --> memo

③ Log File 정보를 확인(V$LOGFILE)
  SVRMGR> select GROUP#, MEMBER
       2> from v$logfile;       --> memo

④ Control File의 정보를 확인
   (V$CONTROLFILE, V$PARAMETER, init<SID>.ora, SHOW PARAMETER command)

⑤ Control File의 이름은 $ORACLE_HOME/dbs에서 Parameter File로 확인
  SVRMGR> host more $ORACLE_HOME/dbs/initDBA숫자.ora  --> memo

⑥ System이 정상인지 확인 (Row들을 Insert)
  SVRMGR> ! more $ORACLE_HOME/labs/more_emp.sql
  SVRMGR> @?/labs/more_emp

* Full Offline Backup 수행

⑦ Database Shutdown
  SVRMGR> shutdown immediate
  SVRMGR> exit

⑧ File들을 Backup
  [/DBA3/DBA/dba숫자] cp -rp u0* backup
  [/DBA3/DBA/dba숫자] cp dbs/initDBA*.ora backup
  [/DBA3/DBA/dba숫자] cp dbs/cntrlDBA*.ctl backup

⑨ backup에 가서 확인
  [/DBA3/DBA/dba숫자] cd backup
  [/DBA3/DBA/dba숫자] ls -la

 


 
<SCENARIO 3 : Recovery - Temporary Tablespace의 유실>


1) 정상적인 업무를 수행

- Database를 기동

  SVRMGR> connect internal
  SVRMGR> startup
  SVRMGR> select tablespace_name, file_name from dba_data_files;
          --> Temporary Tablespace의 Data File 경로명을 확인
  SVRMGR> !ls -la /DBA3/DBA/dba숫자/u04/temp_01.dbf      --> 크기 확인

2) Failure를 만든다.

   SVRMGR> shutdown abort          --> Failure를 상상
   SVRMGR> exit
   [/DBA3/DBA/dba숫자]cd $ORACLE_HOME/u04
   [/DBA3/DBA/dba숫자/u04]mv temp_01.dbf temp_01.org    --> Temporary Tablespace의 유실

   SVRMGR> connect internal
   SVRMGR> startup mount
   SVRMGR> alter database open;
           alter database open
                    *
           ORA-01157: cannot identify data file 4 - file not found
           ORA-01110: data file 4: '/DBA3/DBA/dba숫자/u04/temp_01.dbf'

3) Recovery 수행

- Temporary Tablespace라면 Drop하고 새로 만들면 될껄?

   SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u04/temp_01.dbf' offline drop;
           Statement processed.         --> Temporary Tablespace를 포기하고 Startup
   SVRMGR> alter database open;
           Stateent processed.
   SVRMGR> select * from dba_tablespaces;
           --> "Temp" Tablespace는 그래도 존재
           --> 왜냐면 Temp Tablespace의 구성 File 중 하나를 Drop한 것 뿐이니까.
               (여기선 우연히 하나였다)
   SVRMGR> drop tablespace temp including contents;     --> 이젠 새로 만들면 끝
   SVRMGR> create tablespace temp
        2> datafile '/DBA3/DBA/dba숫자/u04/temp_01.dbf' size 1M;
   SVRMGR> shutdown immediate               --> Shutdown과 Startup을 해봐서 잘 되는지 확인
   SVRMGR> startup
   SVRMGR> shutdown immediate
   SVRMGR> exit

   [/DBA3/DBA/dba숫자/u04]rm temp_01.org    --> 필요 없는 File을 삭제
   [/DBA3/DBA/dba숫자/u04]cd

 

 
<SCENARIO 4 : Noarchive Log Mode Recovery - Disk의 유실>


1) Failure를 가정하고 Recovery 수행

- 모든 File들을 Restore하려는 데, "users_01.dbf"를 원래 위치에 Restore 할 수가 없다.
  따라서, 할 수 없이 $ORACLE_HOME에 Restore 한다.
  [/DBA3/DBA/dba숫자] cd backup
  [/DBA3/DBA/dba숫자/backup] ls
      cntrlDBA숫자.ctl  u01 &nbsp;         u03
      initDBA숫자.ora   u02 &nbsp;         u04

  [/DBA3/DBA/dba숫자/backup] cp -rp u0* $ORACLE_HOME
  [/DBA3/DBA/dba숫자/backup] cp initDBA숫자.ora $ORACLE_HOME/dbs
  [/DBA3/DBA/dba숫자/backup] cp cntrlDBA숫자.ctl $ORACLE_HOME/dbs
  [/DBA3/DBA/dba숫자/backup] cd $ORACLE_HOME/u03
  [/DBA3/DBA/dba숫자/u03]ls
      query_01.dbf  rbs_01.dbf    users_01.dbf

  [/DBA3/DBA/dba숫자/u03] mv users_01.dbf $ORACLE_HOME
                          --> users_01.dbf 이 다른 곳으로 이사 갔다.

  [/DBA3/DBA/dba숫자/u03] cd
  [/DBA3/DBA/dba숫자] ls -la users*

2) Startup 시도

  SVRMGR> connect internal
  SVRMGR> startup mount
  SVRMGR> alter database open;
          alter database open
              *
          ORA-01157: cannot identify data file 3 - file not found
          ORA-01110: data file 3: '/DBA3/DBA/dba숫자/u03/users_01.dbf'
  SVRMGR> select name from v$datafile;

                      NAME
          ----------------------------------------------------------
          /DBA3/DBA/dba숫자/u01/system.dbf
          /DBA3/DBA/dba숫자/u03/rbs_01.dbf
          /DBA3/DBA/dba숫자/u03/users_01.dbf
          /DBA3/DBA/dba숫자/u04/temp_01.dbf
          /DBA3/DBA/dba숫자/u03/query_01.dbf
          /DBA3/DBA/dba숫자/u01/index_01.dbf
          6 rows selected.

          --> Oracle Server는 File이 다른 곳($ORACLE_HOME)에 있다는 것을 모르네.

3) 그럼 내가 가르쳐 주지.

  SVRMGR> alter database rename file '/DBA3/DBA/dba숫자/u03/users_01.dbf'
       2> to '/DBA3/DBA/dba숫자/users_01.dbf';

4) 다시 Open 시도

  SVRMGR> alter database open;   --> 성공!!!
  SVRMGR> shutdown immediate
  SVRMGR> startup                --> 한번 더 확인

5) 원래 상태로 만들자.

  SVRMGR> shutdown immediate
  SVRMGR> exit

  [/DBA3/DBA/dba숫자]rm users_01.dbf
  [/DBA3/DBA/dba숫자]cd backup
  [/DBA3/DBA/dba숫자/backup]cp -rp u0* $ORACLE_HOME
  [/DBA3/DBA/dba숫자/backup]cp initDBA숫자.ora $ORACLE_HOME/dbs
  [/DBA3/DBA/dba숫자/backup]cp cntrlDBA숫자.ctl $ORACLE_HOME/dbs
  [/DBA3/DBA/dba숫자/backup]cd
  [/DBA3/DBA/dba숫자]svrmgrl

  SVRMGR> connect internal
  SVRMGR> startup                --> 괜히 확인
  SVRMGR> shutdown
  SVRMGR> exit

 

 
<SCENARIO 5 : Read Only Tablespace의 Backup & Recovery>


1) 정상적인 업무를 수행

   SVRMGR> connect internal
   SVRMGR> startup
   SVRMGR> @?/labs/more_emp

2) Read Only Tablespace의 Backup
   - Online/Offline 상태, 즉 DB가 사용중이던지 사용중이 아니던지 관계없이 Copy

   SVRMGR> !cp  u03/query_01.dbf  $ORACLE_HOME

3) Failure를 만든다
   - 업무 수행 중에 query_01.dbf  File이 삭제되었다

   SVRMGR> @?/labs/more_emp
   SVRMGR> !rm  u03/query_01.dbf
   SVRMGR> select * from scott.new_dept;
           ORA-01116: error in opening database file 5
           ORA-01110: data file 5: '/DBA3/DBA/dba숫자/u03/query_01.dbf'
           ORA-07368: sfofi: open error, unable to open database file.
           SVR4 Error: 2: No such file or directory

4) Recovery 시작
   - Online/Offline 상태, 즉 DB가 사용중이던지 사용중이 아니던지 관계없이 Copy

   SVRMGR> !cp  $ORACLE_HOME/query_01.dbf  u03
   SVRMGR> select * from scott.new_dept;   --> 이게 Recovery 전부...
   SVRMGR> shutdown
   SVRMGR> exit

 

 
< SCENARIO 6 :DATABASE의 BACKUP - Control File Mirroring & Archive log mode >


1) Control File을 Mirroring하여 Database를 StartUp

  - parameter File을 보고 현재의 "control_files=?????"를 확인
    [/DBA3/DBA/dba숫자] more dbs/initDBA숫자.ora

  - Control File을 복사
    [/DBA3/DBA/dba숫자] cp dbs/cntrlDBA숫자.ctl u01
    [/DBA3/DBA/dba숫자] cp dbs/cntrlDBA숫자.ctl u02

  - 추가된 Control File들을 init<SID>.ora File에 등록
    [/DBA3/DBA/dba숫자] vi dbs/initDBA숫자.ora
    (수정) control_files=($ORACLE_HOME/dbs/cntrlDBA숫자.ctl,
                          $ORACLE_HOME/u01/cntrlDBA숫자.ctl,
                          $ORACLE_HOME/u02/cntrlDBA숫자.ctl)
     :wq

  - Database를 Startup
    SVRMGR> connect internal
    SVRMGR> startup

2) Database를 Archive Log Mode로 운영

  - 현재 Archive Log Mode를 확인
    SVRMGR> select * from v$logfile;       --> On-Line Redo Log File들 확인
    SVRMGR> archive log list               --> No Archive Mode 확인

  - Archive Log Mode로 전환 & Parameter 수정
    SVRMGR>shutdown immediate
    SVRMGR>host
    [/DBA3/DBA/dba숫자]vi dbs/initDBA숫자.ora
    (수정) log_archive_start  = true
           log_archive_dest   = $ORACLE_HOME/arch
           log_archive_format = _%s.arc
     :wq

    [/DBA3/DBA/dba숫자]exit
    SVRMGR>startup mount                    --> 반드시 Mount로 StartUp 해야 함
    SVRMGR>alter database archivelog;       --> Mode 변경
    SVRMGR>archive log list                 --> Archive Mode 확인,
                                            --> Current Log 번호 기억
    SVRMGR>alter database open;             --> 현재 Mount이므로

3) Documentation을 위한 정보 탐색

  - Tablespace 정보
    SVRMGR> select  TABLESPACE_NAME, FILE_NAME, v$datafile.STATUS, ENABLED
         2>   from  dba_data_files, v$datafile
         3>  where  FILE_ID = FILE#;

  - Log File 정보
    SVRMGR> select  v$logfile.MEMBER, v$logfile.GROUP#, v$log.STATUS, BYTES
         2>   from  v$logfile, v$log
         3>  where  v$logfile.GROUP# = v$log.GROUP#;

  - Control File 정보
    SVRMGR> select * from v$controlfile;

  - 각종 Parameter 정보
    SVRMGR> show parameter log
    SVRMGR> show parameter db_block
    SVRMGR> show parameter dump

4) System이 정상인지 확인

  - Row들을 Insert
    SVRMGR> host more $ORACLE_HOME/labs/more_emp.sql
    SVRMGR> @?/labs/more_emp

  - Archived Log File이 만들어 지는 지 확인
    SVRMGR> host ls -la $ORACLE_HOME/*.arc      --> Log File 존재 확인
    SVRMGR> archive log list                    --> Current Log 번호 증가 확인

5) Full Offline Backup 수행

  - Database Shutdown
    SVRMGR> shutdown immediate
    SVRMGR> exit

  - File들을 Backup (만일을 위해서 두 번 Backup)
    [/DBA3/DBA/dba숫자] cp -rp u0* dontouch
    [/DBA3/DBA/dba숫자] cp dbs/init*.ora dontouch
    [/DBA3/DBA/dba숫자] cp dbs/cntrl*.ctl dontouch
    [/DBA3/DBA/dba숫자] cp -rp u0* backup
    [/DBA3/DBA/dba숫자] cp dbs/init*.ora backup
    [/DBA3/DBA/dba숫자] cp dbs/cntrl*.ctl backup

  - 확인
    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> shutdown immediate
    SVRMGR> exit

 

 
<SCENARIO 7 : Complete Recovery - User의 DATA FILE 유실>


1) 정상적인 업무를 수행

  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup

  - 업무 수행 & Archived Log File 확인
    SVRMGR> !ls -la *.arc                --> 현재의 Archived Log File 확인
    SVRMGR> !more labs/more_emp.sql      --> "scott" user의 "s_emp" table에 Row를 Insert/Update 하는 Script
    SVRMGR> @?/labs/more_emp
    SVRMGR> exit
   [/DBA3/DBA/dba숫자] ls -la *.arc      --> Archived Log File 생성 확인

2) Failure를 만든다.

    [/DBA3/DBA/dba숫자] ls u03           --> "USERS" Tablespace를 구성하는 File 확인
    [/DBA3/DBA/dba숫자] rm u03/users_01.dbf   --> FIle 삭제
    [/DBA3/DBA/dba숫자] ls u03

    SVRMGR> connect internal
    SVRMGR> shutdown immediate           --> Error 발생 & 실패
    SVRMGR> shutdown abort
    SVRMGR> exit

3) Recovery 시작

① 예전에 받은 Full Backup으로부터 손상된 Data File을 Restore
    [/DBA3/DBA/dba숫자] cd backup/u03
    [/DBA3/DBA/dba숫자/backup/u03] ls -la
    [/DBA3/DBA/dba숫자/backup/u03] cp users_01.dbf $ORACLE_HOME/u03

  - Recovery를 수행

② SVRMGR> startup
    --> Error와 함께 Mount까지만 수행
    --> Recovery를 위해선 " Startup Mount " 하는게 정상
    Database mounted.
    ORA-01113: file 3 needs media recovery
    ORA-01110: data file 3: '/DBA3/DBA/dba숫자/u03/users_01.dbf'

③ SVRMGR> recover database
    ORA-00279: Change 7474 generated at 04/24/97 22:52:31 needed for thread 1
    ORA-00289: Suggestion : /DBA3/DBA/dba27/arch_256.arc
    ORA-00280: Change 7474 for thread 1 is in sequence #256
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}  --> 여러번 "Enter"를 눌러야 함
    Media recovery complete.

④ SVRMGR> alter database open;
    --> 현재가 "Mount" 상태이므로

4) System이 정상적으로 복구 되었는지 확인
   SVRMGR> select count(*) from scott.s_emp; --> 정상적으로 수행 됨
   SVRMGR> shutdown immediate                --> 정상적으로 수행 됨
   SVRMGR> exit

 

 
<SCENARIO 8 : Complete Recovery - Tablespace Recovery>


1) 정상적인 업무를 수행

  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup

  - 업무 수행 & Archived Log File 확인
    SVRMGR> !ls -la *.arc                    --> 현재의 Archived Log File 확인
    SVRMGL> @?/labs/more_emp
    SVRMGR> exit
    [/DBA3/DBA/dba숫자]ls -la *.arc          --> Archived Log File 생성 확인

2) Failure를 만든다.

    [/DBA3/DBA/dba숫자] ls $ORACLE_HOME/u03                  --> "USERS" Tablespace를 구성하는 File 확인
    [/DBA3/DBA/dba숫자] rm $ORACLE_HOME/u03/users_01.dbf     --> FIle 삭제
    [/DBA3/DBA/dba숫자] ls $ORACLE_HOME/u03

    SVRMGR> connect internal
    SVRMGR> shutdown immediate               --> Error 발생 & 실패
    SVRMGR> shutdown abort
    SVRMGR> exit

3) Recovery 시작

  - 예전에 받은 Full Backup으로부터 손상된 Data File을 Restore
    [/DBA3/DBA/dba숫자] cd backup/u03
    [/DBA3/DBA/dba숫자/backup/u03] ls -la
    [/DBA3/DBA/dba숫자/backup/u03] cp users_01.dbf $ORACLE_HOME/u03

  - Recovery를 수행
    SVRMGR> connect internal
    SVRMGR> startup mount
    SVRMGR> alter database open;                       --> Error
          ORA-01113: file 3 needs media recovery
          ORA-01110: data file 3: '/DBA3/DBA/dba숫자/u03/users_01.dbf'
    SVRMGR> select FILE#, STATUS, NAME from v$datafile;
    SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u03/users_01.dbf' offline;
    SVRMGR> select FILE#, STATUS, NAME from v$datafile;
    SVRMGR> alter database open;
    SVRMGR> select TABLESPACE_NAME, STATUS from dba_tablespaces;
    SVRMGR> alter tablespace user_data offline immediate;
    SVRMGR> select TABLESPACE_NAME, STATUS from dba_tablespaces;
    SVRMGR> recover tablespace user_data
          ORA-00279: Change 7220 generated at 02/24/97 23:51:30 needed for thread 1
          ORA-00289: Suggestion : /DBA3/DBA/dba숫자/arch_219.arc
          ORA-00280: Change 7220 for thread 1 is in sequence #219
          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
          auto        -                               --> 입력하자

    SVRMGR> alter tablespace user_data online;
    SVRMGR> select count(*) from scott.s_emp;           --> 정상적으로 수행 됨
    SVRMGR> shutdown immediate
    SVRMGR> exit

 

 
<SCENARIO 9 : Complete Recovery - Datafile Recovery>


1) 정상적인 업무를 수행

  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup

  - 업무 수행 & Archived Log File 확인
    SVRMGR> !ls -la *.arc                --> 현재의 Archived Log File 확인
    SVRMGR> @?/labs/more_emp
    SVRMGR> exit
    [/DBA3/DBA/dba숫자]ls -la *.arc      --> Archived Log File 생성 확인

2) Failure를 만든다.
    [/DBA3/DBA/dba숫자] ls $ORACLE_HOME/u03       --> "USERS" Tablespace를 구성하는 File 확인
    [/DBA3/DBA/dba숫자] rm $ORACLE_HOME/u03/users_01.dbf     --> FIle 삭제
    [/DBA3/DBA/dba숫자] ls $ORACLE_HOME/u03

    SVRMGR> connect  internal
    SVRMGR> shutdown immediate           --> Error 발생 & 실패
    SVRMGR> shutdown abort
    SVRMGR> exit

3) Recovery 시작


① 예전에 받은 Full Backup으로부터 손상된 Data File을 Restore
    [/DBA3/DBA/dba숫자] cd backup/u03
    [/DBA3/DBA/dba숫자/backup/u03] ls -la
    [/DBA3/DBA/dba숫자/backup/u03] cp users_01.dbf $ORACLE_HOME/u03

  - Recovery를 수행
    SVRMGR> connect internal

② startup mount

③ SVRMGR> alter database open;
     ORA-01113: file 3 needs media recovery
     ORA-01110: data file 3: '/DBA3/DBA/dba숫자/u03/users_01.dbf'

④ SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u03/users_01.dbf' offline;
⑤ SVRMGR> alter database open;
⑥ SVRMGR> recover datafile '/DBA3/DBA/dba숫자/u03/users_01.dbf'
     ORA-00279: Change 7220 generated at 02/24/97 23:51:30 needed for thread 1
     ORA-00289: Suggestion : /DBA3/DBA/dba숫자/arch_219.arc
     ORA-00280: Change 7220 for thread 1 is in sequence #219
     Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
     "Return key"를 여러번 누르거나, "auto"를 입력하자

⑦ SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u03/users_01.dbf' online;
    SVRMGR> select count(*) from scott.s_emp;       --> 정상적으로 수행 됨
    SVRMGR> shutdown immediate
    SVRMGR> exit

 

 
<SCENARIO 10 : Parallel Recovery>


1) Parallel 환경 setup
  - parameter file을 수정하여 parallel 환경을 만든다.
    Parallel_min_servers = 2
    Parallel_max_servers = 4
    Recovery_parallelism = 4

  - DB를 다시 기동한 후 background process들 (p000, p001) 을 확인한다.
    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> host ps -ef | grep <SID>
    SVRMGR> select count(*) from scott.s_emp;
    SVRMGR> shutdown immediate

2) user_data tablespace를 backup받고 DB 기동후, 정상적인 업무를 수행
    [/DBA3/DBA/dba숫자]cp u03/users_01.dbf u03/users_01.bak

    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> @?/labs/more_emp  -----> row들을 insert

3) Failure를 만든다.

    SVRMGR> shutdown immediate
    SVRMGR> host rm $ORACLE_HOME/u03/users_01.dbf

4) DB 복구 작업

  - backup 받은 file을 restore 시킨 후, Database를 mount 시킨다.
    SVRMGR> !mv u03/users_01.bak u03/users_01.dbf
    SVRMGR> startup mount
    SVRMGR> alter database open
           ORA-01113: file 3 needs media recovery
           ORA-01110: data file 3: '/DBA3/DBA/dba숫자/u03/users_01.dbf'

  - DB parallel recovery 후 DB open
    SVRMGR> set autorecovery on
    SVRMGR> recover database parallel (degree 4)
            ......
            Media recovery complete.
    SVRMGR> alter database open

5) System이 정상인지 확인

    SVRMGR> select count(*) from scott.s_emp;
    SVRMGR> !ps -ef | grep <SID>    ---->  p002, p003 확인 (<- degree 4)

- 5분 이상 경과 후, p002, p003이 존재하는지 확인한다.
    SVRMGR> !ps -ef | grep <SID>
    SVRMGR> shutdown immediate
    SVRMGR> exit
 


 
<SCENARIO 11 : Complete Recovery - Shutdown 하지 않고 Data File만 Recovery>


1) 정상적인 업무를 수행

  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup

  - 업무 수행 & Archived Log File 확인
    SVRMGR> !ls -la *.arc              --> 현재의 Archived Log File 확인
    SVRMGR> @?/labs/more_emp
    SVRMGR> exit
    [/DBA3/DBA/dba숫자] ls -la *.arc    --> Archived Log File 생성 확인

2) Failure를 만든다.
    [/DBA3/DBA/dba숫자] ls $ORACLE_HOME/u03               --> "USERS" Tablespace를 구성하는 File 확인
    [/DBA3/DBA/dba숫자] rm $ORACLE_HOME/u03/users_01.dbf  --> FIle 삭제
    [/DBA3/DBA/dba숫자] ls $ORACLE_HOME/u03

    SVRMGR> connect internal
    SVRMGR> select * from scott.s_dept;
                 ID               NAME           REGION_ID
            ---------- ------------------------- ----------
            ORA-01116: error in opening database file 3
            ORA-01110: data file 3: '/DBA3/DBA/dba숫자/u03/users_01.dbf'
            ORA-07368: sfofi: open error, unable to open database file.
            SVR4 Error: 2: No such file or directory

3) Recovery 시작


① 예전에 받은 Full Backup으로부터 손상된 Data File을 Restore
    [/DBA3/DBA/dba숫자] cd backup/u03
    [/DBA3/DBA/dba숫자/backup/u03] ls -la
    [/DBA3/DBA/dba숫자/backup/u03] cp users_01.dbf $ORACLE_HOME/u03

  - Recovery를 수행
    SVRMGR> connect internal
    SVRMGR> alter database datafile  '/DBA3/DBA/dba숫자/u03/users_01.dbf' offline;

    SVRMGR> recover datafile '/DBA3/DBA/dba숫자/u03/users_01.dbf'
        ORA-00279: Change 7220 generated at 02/24/97 23:51:30 needed for thread 1
        ORA-00289: Suggestion : /DBA3/DBA/dba숫자/arch_219.arc
        ORA-00280: Change 7220 for thread 1 is in sequence #219
        Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
        "Return key"를 여러번 누르거나, "auto"를 입력하자

    SVRMGR> alter database datafile  '/DBA3/DBA/dba숫자/u03/users_01.dbf' online;

    SVRMGR> select count(*) from scott.s_emp;      --> 정상적으로 수행 됨
    SVRMGR> select * from scott.s_dept;            --> 정상적으로 수행 됨

    SVRMGR> shutdown immediate
    SVRMGR> exit

 

 
<SCENARIO 12 : Online Backup (Hot Backup)>


1) 정상적인 업무를 수행
  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup

  - 업무 수행 & Archived Log File 확인
    SVRMGR> !ls -la *.arc          --> 현재의 Archived Log File 확인
    SVRMGR> @?/labs/more_emp
    SVRMGR> !ls -la *.arc          --> Archived Log File 생성 확인

2) Online Backup

 ① Data File들의 Online Backup : datafile별로 backup받는다.
    SVRMGR> select tablespace_name, file_name from dba_data_files;
    SVRMGR> select status, enabled, name from v$datafile;
             --> enabled가 "READ ONLY" Tablespace는 Online Backup시에 제외
    SVRMGR> !mkdir $ORACLE_HOME/online_backup

SVRMGR> alter tablespace system begin backup;
SVRMGR> !cp u01/system.dbf online_backup
SVRMGR> alter tablespace system end backup;
    SVRMGR> alter tablespace rbs begin backup;
    SVRMGR> !cp  u03/rbs_01.dbf  online_backup
    SVRMGR> alter tablespace rbs end backup;

    SVRMGR> alter tablespace user_data begin backup;
    SVRMGR> !cp  u03/users_01.dbf  online_backup
    SVRMGR> alter tablespace user_data end backup;

    SVRMGR> alter tablespace temp begin backup;
    SVRMGR> !cp  u04/temp_01.dbf  online_backup
    SVRMGR> alter tablespace temp end backup;

    SVRMGR> alter tablespace user_index begin backup;
    SVRMGR> !cp  u01/index_01.dbf  online_backup
    SVRMGR> alter tablespace user_index end backup;

SVRMGR> alter system switch logfile;
 ② Read-only Tablespace Backup
    Read-only Tablespace는 예전 Backup에 이미 Copy되어 있으므로 다시 수행할 필요가 없다.
    그래도 꼭 하겠다면 "alter tablespace ...begin/end backup" 없이 수행
    에이, 말 나온 김에 한번 해보자......
    SVRMGR> !cp  u03/query_01.dbf  online_backup

 ③ Control File의 Online Backup

SVRMGR> alter database backup controlfile to
 '$ORACLE_HOME/online_backup/backup_control.ctl' reuse;
SVRMGR> alter database backup controlfile to trace;
 ④ Parameter File의 Backup
    SVRMGR> !cp  dbs/initDBA숫자.ora  online_backup
    SVRMGR> shutdown immediate
    SVRMGR> exit

 

 
<SCENARIO 13 : Online Backup 실패후 Recovery - Online Backup 도중에 정전>


1) 정상적인 업무를 수행
  - Database를 기동 & 업무 수행
    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> @?/labs/more_emp

2) Online Backup
  - Data File들의 Online Backup
    SVRMGR> alter tablespace user_data begin backup;
    SVRMGR> !cp  u03/users_01.dbf  online_backup
    SVRMGR> shutdown abort       --> 정전 사태 발생
    SVRMGR> exit

    [/DBA3/DBA/dba숫자] svrmgrl  --> 다시 전원이 들어와서 DB를 살리려고 시도
    SVRMGR> connect internal
    SVRMGR> startup
          ORA-01113: file 3 needs media recovery
          ORA-01110: data file 3: '/DBA3/DBA/dba숫자/u03/users_01.dbf'
                     --> 어?  이상하다....아하!  이것쯤이야..

    SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u03/users_01.dbf' end backup;
    SVRMGR> alter database open;
    SVRMGR> --> Online Backup을 다시 받으면 된다
    SVRMGR> shutdown immediate
    SVRMGR> exit

 

 
<SCENARIO 14 : Incomplete Recovery - 실수로 Drop한 Table의 복구>


1) 정상적인 업무를 수행

  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> @?/labs/more_emp

2) Failure를 만든다.
    SVRMGR> !date                                       --> 현재의 시간을 기억해야 함
    SVRMGR> drop table scott.s_emp cascade constraints; --> 실수로 Drop 하였다고 가정
    SVRMGR> select * from scott.s_emp;
            select * from scott.s_emp
                   *
          ERROR at line 1:
          ORA-00942: table or view does not exist  --> 이제와서 후회

3) Recovery 수행

  - 예전에 받은 Full Backup으로부터 Data File들을 Restore
    SVRMGR> shutdown immediate
    SVRMGR> exit

    [/DBA3/DBA/dba숫자] cd backup
    [/DBA3/DBA/dba숫자/backup] ls
    [/DBA3/DBA/dba숫자/backup] cp u01/*.dbf $ORACLE_HOME/u01
    [/DBA3/DBA/dba숫자/backup] cp u03/*.dbf $ORACLE_HOME/u03
    [/DBA3/DBA/dba숫자/backup] cp u04/*.dbf $ORACLE_HOME/u04

  - Incomplete Recovery 수행
    SVRMGR> connect internal
    SVRMGR> startup mount

① SVRMGR> set autorecovery on
② SVRMGR> recover database until time '1997-01-23:16:44:47'
--> 앞에서 기억한 시간이어야 함
③ SVRMGR> alter database open resetlogs; --> Incomplete Recovery 이니까 "resetlogs"로 Open
④ SVRMGR> archive log list --> Log Sequence 번호가 Reset되었음
    SVRMGR> select * from scott.s_emp;     --> Drop 되었던 "s_emp" Table이 다시 살아났다.
    SVRMGR> shutdown immediate
    SVRMGR> exit

 ⑤ Log Sequence 번호가 Reset 되었으니까 Off-Line Full Backup 수행
    [/DBA3/DBA/dba숫자/backup] cd $ORACLE_HOME
    [/DBA3/DBA/dba숫자] cp -rp u0* backup
    [/DBA3/DBA/dba숫자] cp dbs/cntrl*.ctl backup
    [/DBA3/DBA/dba숫자] cp dbs/init*.ora backup

  - 더 이상 필요 없는 File들을 삭제
    [/DBA3/DBA/dba숫자] rm *.arc
    [/DBA3/DBA/dba숫자] ls

 

 
<SCENARIO 15 : Inactive Online Redo Log Group의 유실>


1) 정상적인 업무를 수행
  SVRMGR> connect / as sysdba   --> connect internal과 같음
  SVRMGR> startup
  SVRMGR> @?/labs/more_emp

2) Failure를 만든다.

  - Inactive Online Redo Log Group을 유실
    SVRMGR> select v$logfile.member from v$logfile where group# =
            ( select min(v$log.group#) from v$log where status = 'INACTIVE');

                                   MEMBER
           ------------------------------------------------------------
              /DBA3/DBA/dba숫자/u01/log2a.rdo    --> 예를 들어서...라면
              /DBA3/DBA/dba숫자/u02/log2b.rdo
              2 rows selected.

    SVRMGR> !ls u01 u02
    SVRMGR> !rm /DBA3/DBA/dba숫자/u01/log2a.rdo
    SVRMGR> !rm /DBA3/DBA/dba숫자/u02/log2b.rdo
    SVRMGR> !ls u01 u02

  - Database가 비정상적으로 수행됨을 확인
    SVRMGR> connect / as sysdba
    SVRMGR> @more_emp            --> Online Redo Log FIle의 유실로 인해 Error 발생
    SVRMGR> shutdown immediate   --> shutdown 실패 (Server Process가 죽었다)
    SVRMGR> exit                 --> exit 했다가 다시 들어가자.

3) Recovery 시작

    SVRMGR> connect / as sysdba
    SVRMGR> shutdown abort
    SVRMGR> startup                                     --> Mount까지만 수행됨
    SVRMGR> select * from v$logfile;                    --> Log FIle의 유실이 반영되지 않았음을 확인
    SVRMGR> alter database backup controlfile to trace; --> 그냥 습관적으로
    SVRMGR> alter database drop logfile group 그룹번호; --> Log FIle의 유실을 반영
    SVRMGR> select * from v$logfile;                    --> Log FIle의 유실이 반영되었음을 확인
    SVRMGR> alter database add logfile group 그룹번호
         2>  '/DBA3/DBA/dba숫자/u01/log그룹번호a.rdo' size 150k;
             --> 유실된 Online Redo Log Group의 첫번째 Member를 생성

    SVRMGR> alter database add logfile member '/DBA3/DBA/dba숫자/u02/log그룹번호b.rdo' to group 그룹번호;
            --> 복구된 Online Redo Log Group의 두번째 Member를 생성
    SVRMGR> select * from v$logfile;                     --> Log File들이 생성되었는지 확인
                                                         --> Invalid는 나중에 없어지니까 놀라지 마세요.
    SVRMGR> alter database open;                         --> Database를 Open

4) System이 정상적으로 복구 되었는지 확인

    SVRMGR> @more_emp
    SVRMGR> select * from v$logfile;   --> 음, Invalid가 없어졌구나.
    SVRMGR> shutdown immediate
    SVRMGR> startup                    --> startup도 제대로 되는구나.
    SVRMGR> shutdown immediate
    SVRMGR> exit
    [/DBA3/DBA/dba26/labs] cd

 

 
<SCENARIO 16 : Current Online Redo Log Group의 유실>


1) 정상적인 업무를 수행
  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> @?/labs/more_emp
    SVRMGR> !ls -la *.arc

2) Failure를 만든다.
  - Current Online Redo Log Group을 유실
    SVRMGR> select v$logfile.member from v$logfile where group# =
            ( select min(v$log.group#) from v$log where status = 'CURRENT');
                   MEMBER
           ----------------------------------------------------------------
            /DBA3/DBA/dba숫자/u01/log1a.rdo           --> 예를 들어 ...라면
            /DBA3/DBA/dba숫자/u02/log1b.rdo
              2 rows selected.

    SVRMGR> !ls u01 u02
    SVRMGR> !rm /DBA3/DBA/dba숫자/u01/log1a.rdo
    SVRMGR> !rm /DBA3/DBA/dba숫자/u02/log1b.rdo
    SVRMGR> !ls u01 u02

  - Database가 비정상적으로 수행됨을 확인
    SVRMGR> @?/labs/more_emp       --> Online Redo Log FIle의 유실로 인해 Error 발생
                                   --> 무한정 대기하게 된다. Why?
                                   --> "Ctrl-C"를 두번 눌러서 강제 종료
    SVRMGR> shutdown immediate

3) Recovery 시작

  - 유실된 Redo Log Group을 제거하고 재생성함으로써 해결할려고 시도
    SVRMGR> startup     --> Redo Log Group이 유실 되었음을 알리며 Error 발생
                        --> Log Group 번호 확인할 것
                        --> Mount까지만 수행된다

    SVRMGR> alter database drop logfile group 그룹번호;
                        --> 유실된 Redo Log Group을 제거 시도
                        --> Archive되지 않은 Current Log이므로 Error와 함께 실패
                        --> (참고) ORA-00350: log 그룹번호 of thread 1 needs to be archived

  SVRMGR> shutdown immediate
  SVRMGR> exit

  - Alert File, Trace File 확인
    [/DBA3/DBA/dba숫자/labs] cd $ORACLE_HOME/trace
    [/DBA3/DBA/dba숫자/trace] ls
    [/DBA3/DBA/dba숫자/trace] vi alert_DBA숫자.log
                                 --> Archiving을 실패한 기록과 Sequence 번호 확인

    [/DBA3/DBA/dba숫자/trace] more arch_번호.trc
                                 --> 기록되지 않은 Log File의 Sequence 번호 확인
                                 --> (예)ORA-00255: error archiving log 1 of thread 1, sequence # 15
                                 --> Incomplete Recovery 방법으로 복구
                                 --> 예를 들어 sequence # 15번이라면 Incomplete Recovery시
                                     15번 에서 "Cancel" 을 입력할거다.

  - 예전에 받은 Full Backup으로부터 Data File들을 Restore
    [/DBA3/DBA/dba숫자/trace]cd $ORACLE_HOME/backup
    [/DBA3/DBA/dba숫자/backup]cp u01/*.dbf $ORACLE_HOME/u01
    [/DBA3/DBA/dba숫자/backup]cp u03/*.dbf $ORACLE_HOME/u03
    [/DBA3/DBA/dba숫자/backup]cp u04/*.dbf $ORACLE_HOME/u04

  - Incomplete Recovery 수행
    SVRMGR> connect internal
    SVRMGR> startup mount
    SVRMGR> recover database until cancel
              "cancel" 입력
            --> 계속 "Enter"를 누르다가 15번 에서 "Cancel" 을 입력

    SVRMGR> alter database open resetlogs;
            --> Incomplete Recovery 이니까 "resetlogs"로 Open
            --> 이때 유실된 Log File이 자동으로 만들어 진다

    SVRMGR> archive log list     --> Log Sequence 번호가 Reset되었음
    SVRMGR> shutdown immediate
    SVRMGR> exit

  - Log Sequence 번호가 Reset 되었으니까 Off-Line Full Backup 수행
    [/DBA3/DBA/dba숫자/backup]cd $ORACLE_HOME
    [/DBA3/DBA/dba숫자] cp -rp u0* backup
    [/DBA3/DBA/dba숫자] cp dbs/cntrl*.ctl backup
    [/DBA3/DBA/dba숫자] cp dbs/init*.ora backup

  - 더 이상 필요 없는 File들을 삭제
    [/DBA3/DBA/dba숫자] cd trace
    [/DBA3/DBA/dba숫자/trace] rm *.trc        --> Trace File들 삭제
    [/DBA3/DBA/dba숫자/trace]rm alert*.log    --> Alert Log File 삭제
    [/DBA3/DBA/dba숫자/trace]cd $ORACLE_HOME
    [/DBA3/DBA/dba숫자]rm *.arc               --> Archived Redo Log File들 삭제
    [/DBA3/DBA/dba숫자]ls -la *.arc           --> File들 삭제 확인

4) System이 정상적으로 복구 되었는지 확인
    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> @?/labs/more_emp    --> 음, 잘 되는 군
    SVRMGR> !ls -la *.arc       --> 새로운 Archived Redo Log File들이 만들어 지는 지 확인
    SVRMGR> shutdown immediate
    SVRMGR> exit

 


 
<SCENARIO 17 : 모든 Online Redo Log Group의 유실>


1) 정상적인 업무를 수행
  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> @?/labs/more_emp
    SVRMGR> !ls -la *.arc

2) Failure를 만든다.

  - 모든 Online Redo Log Group을 유실
    SVRMGR> !ls u01 u02
    SVRMGR> !rm /DBA3/DBA/dba숫자/u01/log*.rdo
    SVRMGR> !rm /DBA3/DBA/dba숫자/u02/log*.rdo

  - Database가 비정상적으로 수행됨을 확인
    SVRMGR> @?/labs/more_emp                --> Online Redo Log FIle의 유실로 인해 Error 발생
    SVRMGR> !ps -ef|grep dba숫자|sort|more  --> Background Precess들과 Server Process들이 죽었다

3) Recovery 시작

  - 앞에서 배운 꽁수로 해결해 보자
    SVRMGR> shutdown immediate  --> shutdown 실패 (Process들이 죽었으니까)
    SVRMGR> shutdown abort      --> shutdown 실패 (Process들이 죽었으니까)
    SVRMGR> exit                --> exit 했다가 다시 들어가자.

    SVRMGR> connect internal
    SVRMGR> shutdown immediate
            ORA-01012: not logged on
    SVRMGR> shutdown abort
            ORACLE instance shut down.
    SVRMGR> startup
          ORA-00313: open failed for members of log group 3 of thread 1
          ORA-00312: online log 3 thread 1: '/DBA3/DBA/dba숫자/u02/log3a.rdo'
          ORA-07360: sfifi: stat error, unable to obtain information about file.
          .............
    SVRMGR> recover database until cancel;
          ORA-00279: Change 8064 generated at 01/20/98 13:02:09 needed for thread 1
          ORA-00289: Suggestion : /DBA3/DBA/dba숫자/arch_9.arc
          ORA-00280: Change 8064 for thread 1 is in sequence #9
          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
                  "cancel" 입력
          Media recovery cancelled.
    SVRMGR> alter database open resetlogs;
            alter database open resetlogs
                       *
          ORA-01194: file 1 needs more recovery to be consistent
          ORA-01110: data file 1: '/DBA3/DBA/dba숫자/u01/system.dbf'
          --> 앗! 어더레케 된거야? .....꽁수가 안 통하잖아?
              ??? 할 수 없다. 정식으로 한번 해 보자.
    SVRMGR> exit

  - 정상적인 Incomplete Recovery 수행
    [/DBA3/DBA/dba숫자] cd $ORACLE_HOME/backup
    [/DBA3/DBA/dba숫자/backup] cp u01/*.dbf $ORACLE_HOME/u01
    [/DBA3/DBA/dba숫자/backup] cp u03/*.dbf $ORACLE_HOME/u03
    [/DBA3/DBA/dba숫자/backup] cp u04/*.dbf $ORACLE_HOME/u04

    SVRMGR> connect internal
    SVRMGR> archive log list
          Database log mode              Archive Mode
          Automatic archival             Enabled
          Archive destination            /DBA3/DBA/dba숫자/arch
          Oldest online log sequence     4
          Next log sequence to archive   5
          Current log sequence           5
          --> 예를 들어 "Next log sequence to archive   5" 번이라면
          Incomplete Recovery 시 5번 에서 "Cancel" 을 입력할거다.

    SVRMGR> recover database until cancel
           "cancel" 입력          --> 계속 "Enter"를 누르다가 5번 에서 "Cancel" 을 입력
    SVRMGR> alter database open resetlogs;
    SVRMGR> archive log list

  - Log Sequence 번호가 Reset 되었으니까 Offline Full Backup 수행
    SVRMGR> shutdown immediate
    SVRMGR> exit
    [/DBA3/DBA/dba숫자/backup] cd $ORACLE_HOME
    [/DBA3/DBA/dba숫자] cp -rp u0* backup
    [/DBA3/DBA/dba숫자] cp -p dbs/cntrl*.ctl backup
    [/DBA3/DBA/dba숫자] cp -p dbs/init*.ora backup

  - 더 이상 필요 없는 File들을 삭제
    [/DBA3/DBA/dba숫자] rm *.arc   --> Archived Redo Log File들 삭제

4) System이 정상적으로 복구 되었는지 확인

    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> @?/labs/more_emp   --> 음, 잘 되는 군
    SVRMGR> !ls -la *.arc      --> 새로운 Archived Redo Log File들이 만들어 지는 지 확인
    SVRMGR> shutdown immediate
    SVRMGR> exit

 

 
<SCENARIO 18 : 모든 Redo Log & Data File 유실>


1) 정상적인 업무를 수행
  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> @?/labs/more_emp
    SVRMGR> !ls -la *.arc

2) Failure를 만든다.
  - 모든 Online Redo Log Group을 유실
    SVRMGR> !ls u01 u02
    SVRMGR> !rm /DBA3/DBA/dba숫자/u01/log*.rdo
    SVRMGR> !rm /DBA3/DBA/dba숫자/u02/log*.rdo

  - datafile을 유실
    SVRMGR> !rm /DBA3/DBA/dba숫자/u01/system.dbf
    SVRMGR> !rm /DBA3/DBA/dba숫자/u01/index_01.dbf

  - 정전까지 되었다고 가정
    SVRMGR> shutdown abort

3) Recovery 시작
  - Incomplete Recovery 수행
    SVRMGR> exit
    [/DBA3/DBA/dba숫자] cd $ORACLE_HOME/backup
    [/DBA3/DBA/dba숫자/backup] cp u01/*.dbf $ORACLE_HOME/u01
    [/DBA3/DBA/dba숫자/backup] cp u03/*.dbf $ORACLE_HOME/u03
    [/DBA3/DBA/dba숫자/backup] cp u04/*.dbf $ORACLE_HOME/u04

    SVRMGR> connect internal
    SVRMGR> startup mount
    SVRMGR> archive log list
            Database log mode              Archive Mode
            Automatic archival             Enabled
            Archive destination            /DBA3/DBA/dba숫자/arch
            Oldest online log sequence     3
            Next log sequence to archive   5
            Current log sequence           5
            --> 예를 들어 "Next log sequence to archive   5" 번이라면
            Incomplete Recovery 시 5번 에서 "Cancel" 을 입력할거다.
    SVRMGR> recover database until cancel
             "cancel" 입력          --> 계속 "Enter"를 누르다가 5번 에서 "Cancel" 을 입력
    SVRMGR> alter database open resetlogs;

  - Log Sequence 번호가 Reset 되었으니까 Offline Full Backup 수행
    SVRMGR> shutdown immediate
    SVRMGR> exit
    [/DBA3/DBA/dba숫자/backup] cd $ORACLE_HOME
    [/DBA3/DBA/dba숫자] cp -rp u0* backup
    [/DBA3/DBA/dba숫자] cp -p dbs/cntrl*.ctl backup
    [/DBA3/DBA/dba숫자] cp -p dbs/init*.ora backup

  - 더 이상 필요 없는 File들을 삭제
    [/DBA3/DBA/dba숫자] rm *.arc   --> Archived Redo Log File들 삭제

4) System이 정상적으로 복구 되었는지 확인
   SVRMGR> connect internal
   SVRMGR> startup
   SVRMGR> @?/labs/more_emp    --> 음, 잘 되는 군
   SVRMGR> !ls -la *.arc       --> 새로운 Archived Redo Log File들이 만들어 지는 지 확인
   SVRMGR> shutdown immediate
   SVRMGR> exit

 

 
<SCENARIO 19 : Control File Recreate>


1) 정상적인 업무 중 Control File Creation Script를 생성
  SVRMGR> connect internal
  SVRMGR> startup
  SVRMGR> !ps -ef|grep dba숫자|sort  --> 현재 Server Process의 번호 확인
  SVRMGR> alter database backup controlfile to trace;
  SVRMGR> !

  $ cd $ORACLE_HOME/trace
  $ ls
  $ cp ora_프로세서번호.trc control.sql

2) Control File들을 모두 삭제
   $ rm $ORACLE_HOME/dbs/cntrlDBA숫자.ctl
   $ rm $ORACLE_HOME/u01/cntrlDBA숫자.ctl
   $ rm $ORACLE_HOME/u02/cntrlDBA숫자.ctl
   $ exit

   SVRMGR> shutdown immediate
   SVRMGR> startup
          ORA-00205: error identifying controlfile '$ORACLE_HOME/dbs/cntrlDBA숫자.ctl'
          ORA-07360: sfifi: stat error, unable to obtain information about file.
   SVR4 Error: 2: No such file or directory
   SVRMGR> shutdown
   SVRMGR> exit

3) Control File을 새로 생성

   [/DBA3/DBA/dba숫자]cd trace
   [/DBA3/DBA/dba숫자/trace]ls
   [/DBA3/DBA/dba숫자/trace]vi control.sql  --> "STARTUP NOMOUNT" 앞까지 모두 삭제
                                            --> "RECOVER DATABASE" 삭제
   SVRMGR> connect internal
   SVRMGR> @control.sql
   SVRMGR> !ls $ORACLE_HOME/dbs
   SVRMGR> !ls $ORACLE_HOME/u01
   SVRMGR> !ls $ORACLE_HOME/u02

4) 정상인지 확인

   SVRMGR> @?/labs/more_emp
   SVRMGR> !ls $ORACLE_HOME
   SVRMGR> shutdown immediate
   SVRMGR> exit
   [/DBA3/DBA/dba숫자/trace] cd
   [/DBA3/DBA/dba숫자]


 
<SCENARIO 20 : 모든 Control File 유실>


* 이번의 시나리오는 Database의 Mode(Archive/Noarchive)에 관계 없이 모두 가능

1) 정상적인 업무를 수행
   SVRMGR> connect internal
   SVRMGR> startup
   SVRMGR> @?/labs/more_emp
   SVRMGR> !ls *.arc

2) Failure를 만든다.

- Control File을 모두 삭제
  SVRMGR> !rm dbs/*.ctl u01/*.ctl u02/*.ctl
  SVRMGR> shutdown abort     --> 꽥! (사망하시는 소리)
  SVRMGR> exit

3) Recovery 시작
  [/DBA3/DBA/dba숫자]cp backup/cntrlDBA숫자.ctl  dbs
  [/DBA3/DBA/dba숫자]cp backup/cntrlDBA숫자.ctl  u01
  [/DBA3/DBA/dba숫자]cp backup/cntrlDBA숫자.ctl  u02

  SVRMGR> connect internal
  SVRMGR> startup mount
  SVRMGR> recover database using backup controlfile
  ORA-00283: Recovery session canceled due to errors
  ORA-01233: file 5 is read only - cannot recover using backup controlfile
  ORA-01110: data file 5: '/DBA3/DBA/dba숫자/u03/query_01.dbf'
  --> read only File이 있으면 반드시 offline시켜야 한다

  SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u03/query_01.dbf' offline;
  SVRMGR> recover database using backup controlfile
  ORA-00279: Change 8050 generated at 01/20/98 15:22:26 needed for thread 1
  ORA-00289: Suggestion : /DBA3/DBA/dba숫자/arch_5.arc
  ORA-00280: Change 8050 for thread 1 is in sequence #5
  Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
  Online Redo Log File 명을 Full Path로 입력
  (예) /DBA3/DBA/dba숫자/u01/log1a.rdo  --> 입력
  그런데, 특별히 운이 좋지 않다면, 다음의 에러가 난다
  (에러 메시지)
  ORA-00310: archived log contains sequence 4; sequence 5 required
  ORA-00334: archived log: '/DBA3/DBA/dba숫자/u01/log1a.rdo'
  그렇다면, recover와 File명 입력을 다시 시도
  (예)
  SVRMGR> recover database using backup controlfile   --> 다시 수행
  /DBA3/DBA/dba숫자/u01/log2a.rdo     --> 다른 Redo Log File 명 입력
  다음의 메시지를 볼 때까지 다른 Redo Log File에도 수행
  (보여야 하는 메시지)
  Log applied.
  Media recovery complete.        --> 이 메시지가 보이면 성공한 것임

  SVRMGR> alter database open resetlogs;
  SVRMGR> select count(*) from scott.s_emp;   --> 성공이다
  SVRMGR> select * from scott.new_emp;
  ORA-00376: file 5 cannot be read at this time
  ORA-01110: data file 5: '/DBA3/DBA/dba숫자/u03/query_01.dbf'
                 --> 얼라리오? 이상하다?      아하! query_01.dbf이 Offline이지!

  SVRMGR> select * from v$datafile;
          --> 역시 "/DBA3/DBA/dba숫자/u03/query_01.dbf"이 Offline이다.

  SVRMGR> alter tablespace query_data online;
  SVRMGR> select * from v$datafile;
  SVRMGR> select * from scott.new_emp;
  SVRMGR> shutdown
  SVRMGR> exit

3) 반드시 Full Backup 수행

  [/DBA3/DBA/dba숫자]cp -rp u0* backup
  [/DBA3/DBA/dba숫자]cp -p dbs/cntrlDBA숫자.ctl backup
  [/DBA3/DBA/dba숫자]cp -p dbs/initDBA숫자.ora backup
  [/DBA3/DBA/dba숫자]rm *.arc

 

 
<SCENARIO 21 : Control File과 Data File 동시에 유실>


1) 정상적인 업무를 수행
  SVRMGR> connect internal
  SVRMGR> startup
  SVRMGR> @?/labs/more_emp
  SVRMGR> !ls *.arc --> 마지막 File의 번호를 기억
  SVRMGR> exit

2) Failure를 만든다.

  - Control File을 모두 삭제
    [/DBA3/DBA/dba숫자] rm dbs/*.ctl u01/*.ctl u02/*.ctl

  - Data File을 삭제
    [/DBA3/DBA/dba숫자] rm u03/users_01.dbf
    [/DBA3/DBA/dba숫자] svrmgrl
    SVRMGR> connect internal
    SVRMGR> shutdown immediate
           ORA-00210: cannot open control file '/DBA3/DBA/dba숫자/dbs/cntrlDBA숫자.ctl'
    SVRMGR> shutdown abort
    SVRMGR> exit

3) Recovery 시작
    [/DBA3/DBA/dba숫자] cp backup/cntrlDBA숫자.ctl dbs
    [/DBA3/DBA/dba숫자] cp backup/cntrlDBA숫자.ctl u01
    [/DBA3/DBA/dba숫자] cp backup/cntrlDBA숫자.ctl u02
    [/DBA3/DBA/dba숫자] cp backup/u03/users_01.dbf u03
    [/DBA3/DBA/dba숫자] svrmgrl

    SVRMGR> connect internal
    SVRMGR> startup mount
    SVRMGR> recover database using backup controlfile
          ORA-00283: Recovery session canceled due to errors
          ORA-01233: file 5 is read only - cannot recover using backup controlfile
          ORA-01110: data file 5: '/DBA3/DBA/dba숫자/u03/query_01.dbf'
                     --> read only File이 있으면 반드시 offline시켜야 한다.

    SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u03/query_01.dbf' offline;
    SVRMGR> recover database using backup controlfile
          ORA-00279: Change 8050 generated at 01/20/98 15:22:26 needed for thread 1
          ORA-00289: Suggestion : /DBA3/DBA/dba숫자/arch_5.arc
          ORA-00280: Change 8050 for thread 1 is in sequence #5
          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
          앞에서 기억한 마지막 번호까지 "Return" Key를 누르고,
          Online Redo Log File 명을 Full Path로 입력
          (예) /DBA3/DBA/dba숫자/u01/log1a.rdo --> 입력
              그런데, 특별히 운이 좋지 않다면, 다음의 에러가 난다
          (에러 메세지)
          ORA-00310: archived log contains sequence 4; sequence 5 required
          ORA-00334: archived log: '/DBA3/DBA/dba숫자/u01/log1a.rdo'
          그렇다면, recover와 File명 입력을 다시 시도
          (예)
    SVRMGR> recover database using backup controlfile    --> 다시 수행
            /DBA3/DBA/dba숫자/u01/log2a.rdo     --> 다른 offline File 명 입력
            다음의 메시지를 볼 때까지 다른 offline File에도 수행
            (보여야 하는 메시지)
            Log applied.
            Media recovery complete.   --> 이 메시지가 보이면 성공한 것임

    SVRMGR> alter database open resetlogs;
    SVRMGR> select count(*) from scott.s_emp;
    SVRMGR> select * from v$datafile;  --> /DBA3/DBA/dba숫자/u03/query_01.dbf이 Offline이다.
    SVRMGR> alter tablespace query_data online;
    SVRMGR> select * from v$datafile;
    SVRMGR> shutdown
    SVRMGR> startup
    SVRMGR> shutdown
    SVRMGR> exit

3) 반드시 Full Backup 수행
    [/DBA3/DBA/dba숫자] cp -rp u0* backup
    [/DBA3/DBA/dba숫자] cp -p dbs/cntrlDBA숫자.ctl backup
    [/DBA3/DBA/dba숫자] cp -p dbs/initDBA숫자.ora backup
    [/DBA3/DBA/dba숫자] rm *.arc

>


 
<SCENARIO 22 : Read Only Tablespace의 상태 변경에 따른 recovery - 1>


control file은 그대로 있고 R/O 가 R/W로 변경되고 그 때 데이터의 변동은 archiving되었다.

1) 정상적인 업무를 수행
  [/DBA3/DBA/dba숫자] svrmgrl
  SVRMGR> connect internal
  SVRMGR> startup

2) Read Only tablespace query_data를 Read Write로 바꾸고 scott가 data를 입력함.
   SVRMGR> alter tablespace query_data read write;
   SVRMGR> select tablespace_name, status from dba_tablespaces;
   SVRMGR> alter user scott quota 1 m on query_data;
   SVRMGR> connect scott/tiger;
   SVRMGR> create table query (id number) tablespace query_data;
   SVRMGR> insert into query select id from s_emp;
   SVRMGR> commit;
   SVRMGR> connect internal;
   SVRMGR> shutdown immediate

3) Failure를 만든다
  - 업무 수행 중에 query_01.dbf  File이 삭제되었다.
    [/DBA3/DBA/dba숫자] rm /DBA3/DBA/dba숫자/u03/query_01.dbf

    SVRMGR> connect internal
    SVRMGR> startup
    SVRMGR> select * from scott.new_dept;
            select * from scott.query
                   *
            ORA-01116: error in opening database file 6
         ORA-01110: data file 6: '/ DBA3/DBA/dba숫자 /u03/query_01.dbf'
         ORA-07368: sfofi: open error, unable to open database file.
         SVR4 Error: 2: No such file or directory
    SVRMGR> shutdown abort;
    SVRMGR> exit

4) Recovery 시작

    [/DBA3/DBA/dba숫자] cp backup/u03/query_01.dbf u03 --> restore backup file
    [/DBA3/DBA/dba숫자] svrmgrl
    SVRMGR> connect internal
    SVRMGR> startup
          ORA-01113: file 6 needs media recovery
          ORA-01110: data file 6: '/ DBA3/DBA/dba숫자 /u03/query_01.dbf'

    SVRMGR> set autorecovery on
    SVRMGR> recover database;
            --> control file에 query_data tablespace가 read write로 되어 있어서
                예전에 read only였던 사실은 중요하지 않다.

    SVRMGR> alter database open;
    SVRMGR> select tablespace_name, status from dba_tablespaces; --> read only 가 아니고 online
    SVRMGR> select * from scott.query;
    SVRMGR> shutdown
    SVRMGR> exit

 

 
<SCENARIO 23 : Read Only Tablespace의 상태 변경에 따른 recovery - 2>


control file은 그대로 있고 R/O 가 R/W로 변경되고 그 때 데이터의 변동은 archiving되었다.
또한 그 중간에 test라는 tablespace를 추가하였다.
Control file이 깨졌는데 R/W로 변화를 가한 후 backup을 받지 않아서 옛날 R/O시절의 control
file을 restore한다면?

1) 정상적인 업무를 수행
  [/DBA3/DBA/dba숫자] svrmgrl
  SVRMGR> connect internal
  SVRMGR> startup

2) 새로운 tablespace를 생성하고 data를 입력한다.
  SVRMGR> create tablespace test datafile '/tmp/t숫자.dbf' size 3 m; --> test tablespace 생성
  SVRMGR> alter user scott quota 1 m on test;
  SVRMGR> connect scott/tiger;
  SVRMGR> create table test (id number) tablespace test;
  SVRMGR> insert into test select id from s_emp;
  SVRMGR> insert into s_emp select * from s_emp; --> 기존에 있었던 tablespace에 작업을 한다.
  SVRMGR> commit;
  SVRMGR> connect internal;
  SVRMGR> select tablespace_name, status from dba_tablespaces;

3) Read Only tablespace query_data를 Read Write로 바꾸고 scott가 data를 입력함.
  SVRMGR> alter tablespace query_data read write;
  SVRMGR> select tablespace_name, status from dba_tablespaces;
  SVRMGR> alter user scott quota 1 m on query_data;
  SVRMGR> connect scott/tiger;
  SVRMGR> create table query (id number) tablespace query_data;
  SVRMGR> insert into query select id from s_emp;
  SVRMGR> commit;
  SVRMGR> connect internal;
  SVRMGR> shutdown immediate

3) Failure를 만든다
  - 업무 수행 중에 query_01.dbf  File이 삭제되었다.
  [/DBA3/DBA/dba숫자] rm /DBA3/DBA/dba숫자/u03/query_01.dbf

  SVRMGR> connect internal
  SVRMGR> startup
          ORA-00205: error in identifying control file '$ORACLE_HOME/dbs/cntrlNDBA15.ctl'
          ORA-07360: sfifi: stat error, unable to obtain information about file.
          SVR4 Error: 2: No such file or directory
  SVRMGR> shutdown abort;
  SVRMGR> exit

4) Recovery 시작

  [/DBA3/DBA/dba숫자]cp backup/dbs/cntrlNDBA숫자.ctl dbs
  [/DBA3/DBA/dba숫자]cp backup /dbs/cntrlNDBA숫자.ctl u01
  [/DBA3/DBA/dba숫자]cp backup /dbs/cntrlNDBA숫자.ctl u02
  [/DBA3/DBA/dba숫자]cp backup /u03/query_01.dbf u03
  [/DBA3/DBA/dba숫자] svrmgrl

  SVRMGR> startup mount
  SVRMGR> recover database using backup controlfile;
          ORA-00283: Recovery session canceled due to errors
          ORA-01233: file 6 is read only - cannot recover using backup controlfile
          ORA-01110: data file 6: '/DBA3/DBA/dba숫자 /u03/query_01.dbf'

  SVRMGR> alter database datafile ‘/DBA3/DBA/dba숫자 /u03/query_01.dbf' offline;

  SVRMGR> recover database using backup controlfile
          ORA-00279: Change 7479 generated at 06/03/98 16:52:00 needed for thread 1
          ORA-00289: Suggestion : /base6/NDBA/ndba15/arch_252.arc
          ORA-00280: Change 7479 for thread 1 is in sequence #252
          Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
          /base6/NDBA/ndba15/u01/log3a.rdo
          Log applied.  --> 이 message가 보일 때까지 계속 recovery 수행.
          Media recovery complete

  SVRMGR> alter database open resetlogs;
  SVRMGR> select * from v$datafile; --> MISSING000x 라는 file이 있다. (t.dbf) --> 왜 이름을 모를까?
  SVRMGR> alter database rename file 'MISSING0008' to '/tmp/t.dbf';
  SVRMGR> alter tablespace test online;
          alter tablespace test online
                 *
          ORA-01190: control file or data file 8 is from before the last RESETLOGS
          ORA-01110: data file 8: '/tmp/t.dbf'

  SVRMGR> alter tablespace query_data online;  --> 안되는 이유는?
          alter tablespace query_data online
                 *
          ORA-01190: control file or data file 6 is from before the last RESETLOGS
          ORA-01110: data file 6: '/base6/NDBA/ndba15/u03/query_01.dbf'

  SVRMGR> select count(*) from scott.s_emp;
  SVRMGR> shutdown
  SVRMGR> exit

 

 
<SCENARIO 24 : Read Only Tablespace의 상태 변경에 따른 recovery - 3>


control file은 그대로 있고 R/O 가 R/W로 변경되고 그 때 데이터의 변동은 archiving되었다.
또한 그 중간에 test라는 tablespace를 추가하였다. Control file이 깨졌는데 R/W로 변화를
가한 후 backup을 이용하면 복구가 가능하다. 항상 control file을 backup.

1) 정상적인 업무를 수행
  [/DBA3/DBA/dba숫자] svrmgrl
  SVRMGR> connect internal
  SVRMGR> startup

2) 새로운 tablespace를 생성하고 data를 입력한다.
  SVRMGR> create tablespace test datafile '/tmp/t숫자.dbf' size 3 m; --> test tablespace 생성
  SVRMGR> alter user scott quota 1 m on test;
  SVRMGR> connect scott/tiger;
  SVRMGR> create table test (id number) tablespace test;
  SVRMGR> insert into test select id from s_emp;
  SVRMGR> insert into s_emp select * from s_emp; --> 기존에 있었던 tablespace에 작업을 한다.
  SVRMGR> commit;
  SVRMGR> connect internal;
  SVRMGR> select tablespace_name, status from dba_tablespaces;

3) Read Only tablespace query_data를 Read Write로 바꾸고 scott가 data를 입력함.
  SVRMGR> alter tablespace query_data read write;
  SVRMGR> select tablespace_name, status from dba_tablespaces;
  SVRMGR> alter user scott quota 1 m on query_data;
  SVRMGR> connect scott/tiger;
  SVRMGR> create table query (id number) tablespace query_data;
  SVRMGR> insert into query select id from s_emp;
  SVRMGR> commit;
  SVRMGR> connect internal;
  SVRMGR> shutdown immediate

  SVRMGR> !ps -ef | grep NDBA15
          ndba15 25748 25747  0 11:38:49 ?        0:03 oracleNDBA15
                 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
          ndba15 25766 25765  2 11:39:26 pts/40   0:00 grep NDBA15
          ndba15 25102     1  6 11:20:43 ?        5:37 oracleNDBA15
                 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

  SVRMGR> !ls $ORACLE_HOME/trace
       alert_NDBA15.log  ora_25748.trc

  SVRMGR> !mv $ORACLE_HOME/trace/ ora_25748.trc /tmp/c.sql
  SVRMGR> !vi /tmp/c.sql
  SVRMGR

3) Failure를 만든다
  - 업무 수행 중에 control File이 삭제되었다.
    [/DBA3/DBA/dba숫자] rm */cntrl*.ctl
    [/DBA3/DBA/dba숫자] svrmgrl

    SVRMGR> connect internal
    SVRMGR> startup
      ORA-00205: error in identifying control file '$ORACLE_HOME/dbs/cntrlNDBA15.ctl'
      ORA-07360: sfifi: stat error, unable to obtain information about file.
      SVR4 Error: 2: No such file or directory

    SVRMGR> shutdown abort;
    SVRMGR> shutdown abort;

4) Recovery 시작

  SVRMGR> @/tmp/c.sql
  SVRMGR> select count(*) from scott.s_emp;
  SVRMGR> shutdown
  SVRMGR> exit

 

 
<SCENARIO 25 : Recovery from Online Backup - Data File, Control File 유실>


1) 정상적인 업무를 수행
  - Database를 기동
    [/DBA3/DBA/dba숫자] svrmgrl
    SVRMGR> connect internal
    SVRMGR> startup

  - 업무 수행 & Archived Log File 확인
    SVRMGR> @?/labs/more_emp
    SVRMGR> !ls -la *.arc      --> 마지막 번호 기억

2) Failure를 만든다.
  - Data file, Control file 삭제
    SVRMGR> shutdown abort
    SVRMGR> exit
    [/DBA3/DBA/dba숫자] rm u01/system.dbf  u03/rbs_01.dbf
    [/DBA3/DBA/dba숫자] rm dbs/*.ctl  u01/*.ctl  u02/*.ctl

3) Recovery 시작
  - Data file, Control file Restore
    [/DBA3/DBA/dba숫자] cd online_backup
    [/DBA3/DBA/dba숫자/online_backup] ls
    [/DBA3/DBA/dba숫자/online_backup] cp system.dbf  $ORACLE_HOME/u01
    [/DBA3/DBA/dba숫자/online_backup] cp rbs_01.dbf  $ORACLE_HOME/u03
    [/DBA3/DBA/dba숫자/online_backup] cp backup_control.ctl  $ORACLE_HOME/dbs/cntrlDBA숫자.ctl
    [/DBA3/DBA/dba숫자/online_backup] cp backup_control.ctl  $ORACLE_HOME/u01/cntrlDBA숫자.ctl
    [/DBA3/DBA/dba숫자/online_backup] cp backup_control.ctl  $ORACLE_HOME/u02/cntrlDBA숫자.ctl
    [/DBA3/DBA/dba숫자/online_backup] cd

    SVRMGR> connect internal
    SVRMGR> startup mount
    SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u03/query_01.dbf' offline;
    SVRMGR> recover database using backup controlfile
            Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
            앞에서 기억한 마지막 번호까지 "Return" Key를 누르고,
            Online Redo Log File 명을 Full Path로 입력
            (예)  /DBA3/DBA/dba숫자/u01/log1a.rdo --> 입력
            Error가 나면, recover와 다른 Online Redo Log File명을 다시 입력
            Media recovery complete.    --> 이 메세지가 보이면 성공한 것임

    SVRMGR> alter database open resetlogs;
    SVRMGR> alter tablespace query_data online;
    SVRMGR> select count(*) from scott.s_emp;
    SVRMGR> shutdown
    SVRMGR> exit

4) 반드시 Full Backup 해야 함.

    [/DBA3/DBA/dba숫자] cp -rp u0* backup
    [/DBA3/DBA/dba숫자] cp -p dbs/cntrlDBA숫자.ctl backup
    [/DBA3/DBA/dba숫자] cp -p dbs/initDBA숫자.ora backup
    [/DBA3/DBA/dba숫자] rm *.arc

 

 
<SCENARIO 26 : Recovery from Online Backup - File들 모두가 사라졌다.
게다가, Archived Redo Log File의 일부가 없고, Data File Backup도 일부 없다.>


0) 바로 앞의 실습(SCENARIO 15번)을 하였다면 Redo Log가 Reset 되었으므로
    Online Backup을 다시 받고 나서 아래의 과정으로 실습하여야 한다.
    Online Backup은 <시나리오12>의 실습 참고.

1) 정상적인 업무를 수행
  - Database를 기동
    SVRMGR> connect internal
    SVRMGR> startup

  - 업무 수행 & Archived Log File 확인
    SVRMGR> !ls -la *.arc    --> 현재의 Archived Log File 확인
    SVRMGR> @?/labs/more_emp

2) Failure를 만든다.
  - Database의 모든 Data file들, 모든 Control file들, 모든 Online Redo Log file들,
    Parameter file 즉, 몽조리 사라졌다. 난리 났다.

    SVRMGR> shutdown abort
    SVRMGR> exit
    [/DBA3/DBA/dba숫자] rm  u01/*  u02/*  u03/*  u04/*  dbs/*.ctl

3) Recovery 시작
  - 게다가 Archived Redo Log File 마지막 2개도 사라졌다.
    [/DBA3/DBA/dba숫자] ls *.arc
    [/DBA3/DBA/dba숫자] rm -i *.arc   --> 알아서 마지막 2개 삭제
    [/DBA3/DBA/dba숫자] ls *.arc      --> 존재하는 마지막 File의 번호를 기억

  - File들을 Restore한다. 그런데 index_01.dbf File의 Backup이 사라졌다. 기절하시겠다.
    [/DBA3/DBA/dba숫자] cd online_backup
    [/DBA3/DBA/dba숫자/online_backup] ls
    [/DBA3/DBA/dba숫자/online_backup] cp initDBA숫자.ora  $ORACLE_HOME/dbs
    [/DBA3/DBA/dba숫자/online_backup] cp backup_control.ctl  $ORACLE_HOME/dbs/cntrlDBA숫자.ctl
    [/DBA3/DBA/dba숫자/online_backup] cp backup_control.ctl  $ORACLE_HOME/u01/cntrlDBA숫자.ctl
    [/DBA3/DBA/dba숫자/online_backup] cp backup_control.ctl  $ORACLE_HOME/u02/cntrlDBA숫자.ctl
    [/DBA3/DBA/dba숫자/online_backup] cp system.dbf  $ORACLE_HOME/u01
    [/DBA3/DBA/dba숫자/online_backup] cp query_01.dbf  rbs_01.dbf  users_01.dbf  $ORACLE_HOME/u03
    [/DBA3/DBA/dba숫자/online_backup] cp temp_01.dbf  $ORACLE_HOME/u04
    [/DBA3/DBA/dba숫자/online_backup] cd

  - Online Redo Log file이 없으니까 Incomplete Recovery 수행
    [/DBA3/DBA/dba숫자]svrmgrl
    SVRMGR> connect internal
    SVRMGR> startup mount
    SVRMGR> recover database using backup controlfile until cancel
          ORA-00283: Recovery session canceled due to errors
          ORA-01233: file 5 is read only - cannot recover using backup controlfile
          ORA-01110: data file 5: '/DBA3/DBA/dba숫자/u03/query_01.dbf'

    SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u03/query_01.dbf' offline;

    SVRMGR> recover database using backup controlfile until cancel
          ORA-00283: Recovery session canceled due to errors
          ORA-01157: cannot identify data file 6 - file not found
          ORA-01110: data file 6: '/DBA3/DBA/dba숫자/u01/index_01.dbf'

    SVRMGR> alter database datafile '/DBA3/DBA/dba숫자/u01/index_01.dbf' offline;

    SVRMGR> recover database using backup controlfile until cancel
            Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
                cancel       --> 마지막 Log 번호까지 처리하고 나서 "cancel" 입력
            Media recovery cancelled.
    SVRMGR> alter database open resetlogs;
    SVRMGR> select * from v$datafile;
    SVRMGR> alter tablespace query_data online;
    SVRMGR> select * from dba_tablespaces;
    SVRMGR> drop tablespace user_index; --> Backup 자체가 존재하지 않으므로 포기하는 수 밖에 없다.
    SVRMGR> create tablespace user_index
             datafile '/DBA3/DBA/dba숫자/u01/index_01.dbf' size 500k;
    SVRMGR> select count(*) from scott.s_emp;
    SVRMGR> shutdown
    SVRMGR> exit

4) 반드시 Full Backup 해야 함.

    [/DBA3/DBA/dba숫자]cp -rp u0* backup
    [/DBA3/DBA/dba숫자]cp -p dbs/cntrlDBA숫자.ctl backup
    [/DBA3/DBA/dba숫자]cp -p dbs/initDBA숫자.ora backup
    [/DBA3/DBA/dba숫자]rm *.arc

 

 
<SCENARIO 27 : Recover with No Backup>


1) 정상적인 업무
  [/DBA3/DBA/dba숫자]svrmgrl
  SVRMGR> connect internal
  SVRMGR> startup
  SVRMGR> @?/labs/more_emp
  SVRMGR> !ls *.arc
  SVRMGR> create tablespace new_data
                 datafile '$ORACLE_HOME/u04/new_data.dbf' size 500k reuse ;
  SVRMGR> create table scott.new_data tablespace new_data
              as select * from scott.s_emp;
  SVRMGR> @?/labs/more_emp

2) Failure

  SVRMGR> shutdown abort
  SVRMGR> exit
  [/DBA3/DBA/dba숫자] ls -la $ORACLE_HOME/u04
  [/DBA3/DBA/dba숫자] rm $ORACLE_HOME/u04/new_data.dbf
  [/DBA3/DBA/dba숫자] ls -la $ORACLE_HOME/u04

3) Recovery

   [/DBA3/DBA/dba숫자] svrmgrl
   SVRMGR> connect internal
   SVRMGR> startup
          ORA-01157: cannot identify data file 7 - file not found
       ORA-01110: data file 7: '/DBA3/DBA/dbapjw/u04/new_data.dbf'
   SVRMGR> alter  database
           create datafile '/DBA3/DBA/dba숫자/u04/new_data.dbf';
   SVRMGR> !ls -la $ORACLE_HOME/u04
   SVRMGR> recover datafile '/DBA3/DBA/dba숫자/u04/new_data.dbf'
                auto 입력
   SVRMGR> alter database open;

4) 확인

   SVRMGR> select count(*) from scott.new_data;

5) 원상 복구

  SVRMGR> drop tablespace new_data including contents;
  SVRMGR> !rm /DBA3/DBA/dba숫자/u04/new_data.dbf
  SVRMGR> shutdown
  SVRMGR> exit

 

 
<SCENARIO 28 : Incremental export 와 direct path >


  $ sqlplus scott/tiger
  SQL> SELECT COUNT(1) FROM s_emp;
       COUNT(1)
      ----------
          44
  SQL> exit

  $ exp userid=sys/change_on_install full=y file=Comp001.dmp inctype=complete

  $ sqlplus system/manager
  SQL> @?/labs/more_emp
  SQL> exit

  $exp userid=sys/change_on_install full=y file=Inc002.dmp inctype=incremental

  $ sqlplus system/manager
  SQL> @?/labs/more_emp
  $ exp userid=sys/change_on_install full=y file=Inc003.dmp inctype=incremental

  $ sqlplus system/manager
  SQL> @?/labs/more_emp
  $ exp userid=sys/change_on_install full=y file=Cum004.dmp inctype=cumulative

  $ sqlplus system/manager
  SQL> @?/labs/more_emp
  $ exp userid=sys/change_on_install full=y file=Inc005.dmp inctype=incremental

  $ sqlplus scott/tiger
  SQL> select count(1) from s_emp;
  SQL> drop table s_emp;

  $ imp userid=sys/change_on_install full=y file=Comp001.dmp ignore=y
  $ imp userid=sys/change_on_install full=y file=Cum004.dmp ignore=y
  $ imp userid=sys/change_on_install full=y file=Inc005.dmp ignore=y

  $ sqlplus scott/tiger
  SQL> select count(1) from s_emp;
  $
  $

     *********************************************************
     **               Direct mode Export Test               **
     *********************************************************
  $
  $
  $vi direct.sh
  date > Dstart
  exp userid=scott/tiger table=s_emp file=direct.dmp direct=y
  date > Dend
  $vi conv.sh
  date > Cstart
  exp userid=scott/tiger table=s_emp file=conv.dmp direct=n
  date > Cend

 

 
<SCENARIO 29 : standby database 생성>


  PRIMARY DB part
  Script started on Tue Jan 20 19:53:46 1998

  $ pwd
    /disk2/inst/parkjy/oracle

  $ set | grep ORACLE
    ORACLE_HOME=/disk2/inst/parkjy/oracle
    ORACLE_SID=KELLOGG

  $ svrmgrl
    Oracle Server Manager Release 2.3.2.0.0 - Production
    Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
    O racle7 Server Release 7.3.2.1.0 - Production Release
    With the distributed and parallel query options
    PL/SQL Release 2.3.2.0.0 - Production

  SVRMGR> connect internal
    Connected.

  SVRMGR> @/tmp/more_emp;
          Statement processed.
          Statement processed.
           4 rows processed.
          Statement processed.
          Statement processed.
           4 rows processed.
          Statement processed.
          Statement processed.
           4 rows processed.
          Statement processed.
          Statement processed.
          Statement processed.
           44 rows processed.
          Statement processed.
          Statement processed.

          COUNT(*)
          ----------
             44

          1 row selected.

  SVRMGR> shutdown;
          Database closed.
          Database dismounted.
          ORACLE instance shut down.

  SVRMGR> exit
          Server Manager complete.
  $ pwd
    /disk2/inst/parkjy/oracle
  $ tar cvf dbf.tar u0?/*

  seek = 0K       a u01/system.dbf 10242K
  seek = 10243K   a u02/log1a.rdo 152K
  seek = 10395K   a u02/log1c.rdo 152K
  seek = 10548K   a u02/log1d.rdo 152K
  seek = 10700K   a u02/log2a.rdo 152K
  seek = 10853K   a u02/log3a.rdo 152K
  seek = 11005K   a u03/log1b.rdo 152K
  seek = 11158K   a u03/log2b.rdo 152K
  seek = 11310K   a u03/log3b.rdo 152K
  seek = 11463K   a u04/rbs_01.dbf 1026K
  seek = 12489K   a u05/users_01.dbf 5122K
  seek = 17612K   a u06/index_01.dbf 502K
  seek = 18114K   a u07/temp_01.dbf 1026K
  seek = 19141K   a u08/query_01.dbf 502K

  $ ftp krnile3
    Connected to krnile3.kr.oracle.com.
    220 krnile3 FTP server (UNIX(r) System V Release 4.0) ready.
    Name (krnile3:parkjy):
    331 Password required for parkjy.
    Password:
    230 User parkjy logged in.

  ftp> bin
       200 Type set to I.
  ftp> put dbf.tar
       200 PORT command successful.
       150 Binary data connection for dbf.tar (152.69.16.52,1842).
       226 Transfer complete.
       local: dbf.tar remote: dbf.tar
       20116480 bytes sent in 20 seconds (9.6e+02 Kbytes/s)

  ftp> pwd
       257 "/disk2/inst/parkjy" is current directory.
  ftp> quit
       221 Goodbye.

  $ svrmgrl
    Oracle Server Manager Release 2.3.2.0.0 - Production
    Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
    Oracle7 Server Release 7.3.2.1.0 - Production Release
    With the distributed and parallel query options
    PL/SQL Release 2.3.2.0.0 - Production

  SVRMGR> connect internal
          Connected to an idle instance.
  SVRMGR> startup
          ORACLE instance started.
          Total System Global Area       2113588 bytes
          Fixed Size                       40436 bytes
          Variable Size                  1860160 bytes
          Database Buffers                204800 bytes
          Redo Buffers                      8192 bytes
          Database mounted.
          Database opened.

  SVRMGR> alter database create standby controlfile as '/tmp/stnb.ctl';
          Statement processed.

  SVRMGR> alter system archive log current;
          Statement processed.

  SVRMGR> archive log list;
          Database log mode              Archive Mode
          Automatic archival             Enabled
          Archive destination            /disk2/inst/parkjy/oracle/arch/arc
          Oldest online log sequence     35
          Next log sequence to archive   37
          Current log sequence           37

  SVRMGR> shutdown;
          Database closed.
          Database dismounted.
          ORACLE instance shut down.
  SVRMGR> exit
          Server Manager complete.

  $ cd /tmp
  $ ftp krnile3
    Connected to krnile3.kr.oracle.com.
    220 krnile3 FTP server (UNIX(r) System V Release 4.0) ready.
    Name (krnile3:parkjy):
    331 Password required for parkjy.
    Password:
    230 User parkjy logged in.

  ftp> bin
    200 Type set to I.
    ftp> put stnb.ctl
    200 PORT command successful.
    150 Binary data connection for stnb.ctl (152.69.16.52,1851).
    226 Transfer complete.
    local: stnb.ctl remote: stnb.ctl
    145408 bytes sent in 0.1 seconds (1.4e+03 Kbytes/s)
  ftp> pwd
    257 "/disk2/inst/parkjy" is current directory.
  ftp> quit
    221 Goodbye.

  $ cd
  $ cd oracle/arch
  $ ls
    arc_1.arc    arc_16.arc   arc_22.arc   arc_29.arc   arc_35.arc   arc_6.arc
    arc_10.arc   arc_17.arc   arc_23.arc   arc_3.arc    arc_36.arc   arc_7.arc
    arc_11.arc   arc_18.arc   arc_24.arc   arc_30.arc   arc_4.arc    arc_8.arc
    arc_12.arc   arc_19.arc   arc_25.arc   arc_31.arc   arc_5.arc    arc_9.arc
    arc_13.arc   arc_2.arc    arc_26.arc   arc_32.arc   arc_514.arc
    arc_14.arc   arc_20.arc   arc_27.arc   arc_33.arc   arc_515.arc
    arc_15.arc   arc_21.arc   arc_28.arc   arc_34.arc   arc_516.arc

  $ r ftp krnile3
    Connected to krnile3.kr.oracle.com.
    220 krnile3 FTP server (UNIX(r) System V Release 4.0) ready.
    Name (krnile3:parkjy):
    331 Password required for parkjy.
    Password:
    230 User parkjy logged in.

  ftp> bin
    200 Type set to I.

  ftp> put arc_36.arc
    200 PORT command successful.
    150 Binary data connection for arc_36.arc (152.69.16.52,1854).
    226 Transfer complete.
    local: arc_36.arc remote: arc_36.arc
    14336 bytes sent in 0 seconds (14 Kbytes/s)
  ftp> quit
    221 Goodbye.

    STANDBY DB Part
    Script started on Tue Jan 20 18:56:25 1998
  $ pwd
    /disk2/inst/parkjy
  $ set | grep ORACLE
    ORACLE_HOME=/disk2/inst/parkjy/oracle
    ORACLE_SID=KELLOGG

  $ ls
    C++          TEST         arc_36.arc   dbf.tar      oracle       work
    PROC         WEB          arch         dbs_standby  stnb.ctl

  $ mv arc_36.* orace le/arch
  $ mv stnb.ctl oracle/dbs/cntrlKELLOGG.ctl
  $ ls oracle/dbs
    cntrlKELLOG.ctl   create_db.sql     log1KELLOGG.dbf   s2.ctl
    cntrlKELLOGG.bak  dbs1KELLOGG.dbf   log2KELLOGG.dbf   sql.bsq
    cntrlKELLOGG.ctl  destroydb         mkdb              standby.ctl
    create_db.sh      initKELLOGG.ora   s.ctl

  $ mv dbf.tar oracle
  $ cd oracle
  $ tar xvf dbf.. tar
    x u01/system.dbf, 10487808 bytes, 10242K
    x u02/log1a.rdo, 155648 bytes, 152K
    x u02/log1c.rdo, 155648 bytes, 152K
    x u02/log1d.rdo, 155648 bytes, 152K
    x u02/log2a.rdo, 155648 bytes, 152K
    x u02/log3a.rdo, 155648 bytes, 152K
    x u03/log1b.rdo, 155648 bytes, 152K
    x u03/log2b.rdo, 155648 bytes, 152K
    x u03/log3b.rdo, 155648 bytes, 152K
    x u04/rbs_01.dbf, 1050624 bytes, 1026K
    x u05/users_01.dbf, 5244928 bytes, 5122K
    x u06/index_01.dbf, 514048 bytes, 502K
    x u07/temp_01.dbf, 1050624 bytes, 1026K
    x u08/query_01.dbf, 514048 bytes, 502K

  $ svrmgrl
    Oracle Server Manager Release 2.1.4.0.0 - Production
    Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
    Oracle7 Server Release 7.3.2.1.0 - Production Release
    With the distributed and parallel query options
    PL/SQL Release 2.3.2.0.0 - Production

  SVRMGR> connect internal
    Connected to an idle instance.

  SVRMGR> startup nomount
    ORACLE instance started.
    Total System Global Area       2113588 bytes
    Fixed Size                       40436 bytes
    Variable Size                  1860160 bytes
    Database Buffers                204800 bytes
    Redo Buffers                      8192 bytes

  SVRMGR> alter database mount standby database;
    Statement processed.

  SVRMGR> recover standby database;
    ORA-00279: Change 9735 generated at 01/20/98 19:54:43 needed for thread 1
    ORA-00289: Suggestion : /disk2/inst/parkjy/oracle/arch/arc_36.arc
    ORA-00280: Change 9735 for thread 1 is in sequence #36
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    Log applied.

    ORA-00279: Change 9743 generated at 01/20/98 19:57:41 needed for thread 1
    ORA-00289: Suggestion : /disk2/inst/parkjy/oracle/arch/arc_37.arc
    ORA-00280: Change 9743 for thread 1 is in sequence #37
    ORA-00278: Logfile '/disk2/inst/parkjy/oracle/arch/arc_36.arc' no longer needed for this recovery
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

    cancel;
    Media recovery cancelled.

  SVRMGR> alter database activate standby database;
    Statement processed.

  SVRMGR> shutdown;
    sORA-01507: database not mounted
    Database dismounted.
    ORACLE instance shut down.

  SVGMGR> startup
  SVRMGR> ORACLE instance started.
    Total System Global Area       2113588 bytes
    Fixed Size                       40436 bytes
    Variable Size                  1860160 bytes
    Database Buffers                204800 bytes
    Redo Buffers                      8192 bytes
    Database mounted.
    Database opened.

  SVRMGR> select count(*)
       2> from d s_emp.scott           scott.s_emp;

          COUNT(*)
         ----------
            44
         1 row selected.

  SVRMGR> shutdown;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
  SVRMGR> exit
    Server Manager complete

 

 
<SCENARIO 30 : Catalog DB를 이용한 복구 Oracle8 >


Part I.

1. Try starting the rman program.
   What happens and why?

$ rman
Recovery Manager: Release 8.0.2.0.0 - Beta
RMAN-06005: connected to target database: DBA15
RMAN-06009: using target database controlfile instead of recovery catalog

RMAN>
Recovery manager connects to your database expecting no recovery
catalog. All information is retrieved from the controlfile.

2. Disconnect from the recovery manager.
   Connect to the recovery catalog using dbaXX/dbaXX@DBA16 as connect string.
   You should connect to your targeted database as internal/admin@DBAXX.
   XX is your account number.
   Do not specify a log file that way all messages will be written to
   your screen.

$ rman target=\"internal/admin@DBA15\" rcvcat=\"dba15/dba15@DBA16\"
Recovery Manager: Release 8.0.2.0.0 - Beta
RMAN-06005: connected to target database: DBA15
RMAN-06008: connected to recovery catalog database
RMAN>

3. Register your database with the recovery catalog.
RMAN> register database;
RMAN-08006: database registered in recovery catalog
RMAN-08002: starting full resync of recovery catalog
RMAN-08029: snapshot controlfile name set to default value: ?/dbs/snapcf_@.f
RMAN-08004: full resync complete
RMAN>

4. List the incarnation of the database.
RMAN> list incarnation of database;
RMAN-06240: List of Database Incarnations
RMAN-06241: DB Key  Inc Key DB Name  DB ID            CUR Reset SCN  Reset Time
RMAN-06242: ------- ------- -------- ---------------- --- ---------- -------
RMAN-06243: 1       2       DBA15    4045670789       YES 1          18-FEB-97
RMAN>

5. Try to do a resync of the recovery catalog.
RMAN> resync catalog;
RMAN-08002: starting full resync of recovery catalog
RMAN-08004: full resync complete
RMAN>

6. Exit the recovery manager and reconnect directing your output to a logfile.
rman target=\"internal/admin@DBA15\" rcvcat=\"dba15/dba15@DBA16\" \
> msglog=\"rmanDBA15.log\"

7. Try to do a resync one more time.
RMAN> resync catalog;
RMAN>

8. Exit and investigate your logfile.
RMAN> exit

$ cat rmanDBA15.log
Recovery Manager: Release 8.0.2.0.0 - Beta
RMAN-06005: connected to target database: DBA15
RMAN-06008: connected to recovery catalog database

RMAN> resync catalog;
RMAN-08002: starting full resync of recovery catalog
RMAN-08004: full resync complete

RMAN> exit
Recovery Manager complete.


Part II.

1. Investigate the script cre_back.rman
   Change "YOUR_PATH" to contain your HOME directory
   (Can be displayed using pwd from the unix prompt)

$ cat cre_back.rman
create script back_db_full {
allocate channel d1 type disk;
backup full filesperset 4
(database include current controlfile
 format "/YOUR_PATH/BACK/back_DBA15_full.%s.%p");
release channel d1;}

2. Connect to the recovery catalog database and use your database
   as the targeted database.
   Create and run the backup script
   What happens and why ?
   Note that Recovery Manager does not accept the @script as svrmgr or
   sqlplus, so you either have to cut and paste or type it in.

$ rman target=\"internal/admin@DBA15\" rcvcat=\"dba15/dba15@DBA16\"
Recovery Manager: Release 8.0.2.0.0 - Beta
RMAN-06005: connected to target database: DBA15
RMAN-06008: connected to recovery catalog database

RMAN> create script back_db_full {

2> allocate channel d1 type disk;
3> backup full filesperset 4
4> (database include current controlfile
5> format "/users/dba15/BACK/back_DBA15_full.%s.%p");
6> release channel d1;}
RMAN-08085: created script back_db_full
RMAN> run { execute script back_db_full;}
RMAN-08030: allocated channel: d1
RMAN-08500: channel d1: sid=9 devtype=DISK
RMAN-08008: channel d1: started datafile backupset
RMAN-08502: set_count=17 set_stamp=296089196
RMAN-03007: exception occurred during execution, error is retryable
RMAN-07004: unhandled exception during command execution on channel d1
RMAN-10032: unhandled exception during execution of job step 1: ORA-06512: at line 57
RMAN-10035: exception raised in RPC: ORA-19624: operation failed, retry possible
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
ORA-06512: at "SYS.X$DBMS_BACKUP_RESTORE", line 312
RMAN-10031: ORA-19624 occurred during call to X$DBMS_BACKUP_RESTORE.BACKUPDATAFILE

This happens because your database is running in NOARCHIVELOG mode and a backup
from recovery manager can only be performed with the database in mounted state.

3. Shutdown your database and restart it in mount mode.
   Rerun your script.

RMAN> exit;
Recovery Manager complete.

$ svrmgrl
Oracle Server Manager Release 3.0.2.0.0 - Beta
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle8 Server Release 8.0.2.0.0 - Beta
With the distributed, heterogeneous, replication, objects,
parallel query and Spatial Data options
PL/SQL Release 3.0.2.0.0 - Beta

SVRMGR> connect internal
Connected.

SVRMGR> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.

SVRMGR> startup mount pfile=initDBA15.ora
ORACLE instance started.
Total System Global Area       4635056 bytes
Fixed Size                       43724 bytes
Variable Size                  4116196 bytes
Database Buffers                409600 bytes
Redo Buffers                     65536 bytes
Database mounted.

SVRMGR> exit
Server Manager complete.

$ rman target=\"internal/admin@DBA15\" rcvcat=\"dba15/dba15@DBA16\"
Recovery Manager: Release 8.0.2.0.0 - Beta
RMAN-06005: connected to target database: DBA15
RMAN-06008: connected to recovery catalog database
RMAN> run { execute script back_db_full;}
RMAN-08030: allocated channel: d1
RMAN-08500: channel d1: sid=8 devtype=DISK
RMAN-08008: channel d1: started datafile backupset
RMAN-08502: set_count=18 set_stamp=296089658
RMAN-08010: channel d1: including datafile number 1 in backupset
RMAN-08010: channel d1: including datafile number 2 in backupset
RMAN-08010: channel d1: including datafile number 3 in backupset
RMAN-08010: channel d1: including datafile number 4 in backupset
RMAN-08013: channel d1: piece 1 created
RMAN-08503: piece handle=/users/dba15/BACK/back_DBA15_full.18.1 comment=NONE
RMAN-08008: channel d1: started datafile backupset
RMAN-08502: set_count=19 set_stamp=296089694
RMAN-08010: channel d1: including datafile number 5 in backupset
RMAN-08010: channel d1: including datafile number 6 in backupset
RMAN-08010: channel d1: including datafile number 7 in backupset
RMAN-08010: channel d1: including datafile number 8 in backupset
RMAN-08013: channel d1: piece 1 created
RMAN-08503: piece handle=/users/dba15/BACK/back_DBA15_full.19.1 comment=NONE
RMAN-08008: channel d1: started datafile backupset
RMAN-08502: set_count=20 set_stamp=296089706
RMAN-08010: channel d1: including datafile number 9 in backupset
RMAN-08010: channel d1: including datafile number 10 in backupset
RMAN-08010: channel d1: including datafile number 11 in backupset
RMAN-08010: channel d1: including datafile number 12 in backupset
RMAN-08013: channel d1: piece 1 created
RMAN-08503: piece handle=/users/dba15/BACK/back_DBA15_full.20.1 comment=NONE
RMAN-08008: channel d1: started datafile backupset
RMAN-08502: set_count=21 set_stamp=296089717
RMAN-08010: channel d1: including datafile number 13 in backupset
RMAN-08010: channel d1: including datafile number 14 in backupset
RMAN-08010: channel d1: including datafile number 15 in backupset
RMAN-08010: channel d1: including datafile number 16 in backupset
RMAN-08013: channel d1: piece 1 created
RMAN-08503: piece handle=/users/dba15/BACK/back_DBA15_full.21.1 comment=NONE
RMAN-08008: channel d1: started datafile backupset
RMAN-08502: set_count=22 set_stamp=296089723
RMAN-08010: channel d1: including datafile number 17 in backupset
RMAN-08010: channel d1: including datafile number 18 in backupset
RMAN-08010: channel d1: including datafile number 19 in backupset
RMAN-08011: channel d1: including current controlfile in backupset
RMAN-08013: channel d1: piece 1 created
RMAN-08503: piece handle=/users/dba15/BACK/back_DBA15_full.22.1 comment=NONE
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-08031: released channel: d1
RMAN>

4. Startup the database and force some log switches using
   the alter system switch logfile command.

svrmgrl
Oracle Server Manager Release 3.0.2.0.0 - Beta
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle8 Server Release 8.0.2.0.0 - Beta
With the distributed, heterogeneous, replication, objects,
parallel query and Spatial Data options
PL/SQL Release 3.0.2.0.0 - Beta

SVRMGR> connect internal
Connected.

SVRMGR> alter database open;
Statement processed.

SVRMGR> alter system switch logfile;
Statement processed.

SVRMGR> alter system switch logfile;
Statement processed.

SVRMGR> alter system switch logfile;
Statement processed.
SVRMGR>

5. Shutdown your database and remove the datafiles, all the logfiles  and
   all the controlfiles.

SVRMGR> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SVRMGR> exit
Server Manager complete.

$ rm *.dbf *.ctl *.log

6. Investigate the script cre_rec.rman
   Change "YOUR_PATH" to contain your HOME directory
   (Can be displayed using pwd from the unix prompt)

$ cat cre_rec.rman
create script rec_db_full{
allocate channel d1 type disk;
restore controlfile to "/YOUR_PATH/control1.ctl";
restore database;
release channel d1;}

7. Startup your instance.
$ svrmgrl
Oracle Server Manager Release 3.0.2.0.0 - Beta
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle8 Server Release 8.0.2.0.0 - Beta
With the distributed, heterogeneous, replication, objects,
parallel query and Spatial Data options
PL/SQL Release 3.0.2.0.0 - Beta

SVRMGR> connect internal
Connected.

SVRMGR> startup nomount pfile=initDBA15.ora
ORACLE instance started.
Total System Global Area       4635056 bytes
Fixed Size                       43724 bytes
Variable Size                  4116196 bytes
Database Buffers                409600 bytes
Redo Buffers                     65536 bytes
SVRMGR> exit
Server Manager complete.

8. Connect to the recovery catalog and your instance.
   Run the content of cre_rec.rman.

$ rman target=\"internal/admin@DBA15\" rcvcat=\"dba15/dba15@DBA16\"
Recovery Manager: Release 8.0.2.0.0 - Beta
RMAN-06006: connected to target database: DBA15 (not mounted)
RMAN-06008: connected to recovery catalog database
RMAN> create script rec_db_full{

2> allocate channel d1 type disk;
3> restore controlfile to "/users/dba15/control1.ctl";
4> restore database;
5> sql "alter database mount";
6> release channel d1;}
RMAN-08085: created script rec_db_full

9. Run the script rec_db_full.
RMAN> run {execute script "rec_db_full";}
MAN-08030: allocated channel: d1
RMAN-08500: channel d1: sid=6 devtype=DISK
RMAN-08016: channel d1: started datafile restore
RMAN-08021: channel d1: restoring controlfile
RMAN-08505: output filename=/users/dba15/control1.ctl
RMAN-08023: channel d1: restored backup piece 1
RMAN-08511: piece handle=/users/dba15/BACK/back_DBA15_full.22.1 params=NULL
RMAN-08024: channel d1: restore complete
RMAN-08016: channel d1: started datafile restore
RMAN-08019: channel d1: restoring datafile number 1
RMAN-08509: destination for restored datafile number=1 filename=/users/dba15/systemDBA15.dbf
RMAN-08019: channel d1: restoring datafile number 2
RMAN-08509: destination for restored datafile number=2 filename=/users/dba15/rbsDBA15.dbf
RMAN-08019: channel d1: restoring datafile number 3
RMAN-08509: destination for restored datafile number=3 filename=/users/dba15/tempDBA15.dbf
RMAN-08019: channel d1: restoring datafile number 4
RMAN-08509: destination for restored datafile number=4 filename=/users/dba15/data01DBA15_1.dbf
RMAN-08023: channel d1: restored backup piece 1
RMAN-08511: piece handle=/users/dba15/BACK/back_DBA15_full.18.1 params=NULL
RMAN-08024: channel d1: restore complete
RMAN-08016: channel d1: started datafile restore
RMAN-08019: channel d1: restoring datafile number 5
RMAN-08509: destination for restored datafile number=5 filename=/users/dba15/data01DBA15_2.dbf
RMAN-08019: channel d1: restoring datafile number 6
RMAN-08509: destination for restored datafile number=6 filename=/users/dba15/data02DBA15_1.dbf
RMAN-08019: channel d1: restoring datafile number 7
RMAN-08509: destination for restored datafile number=7 filename=/users/dba15/data02DBA15_2.dbf
RMAN-08019: channel d1: restoring datafile number 8
RMAN-08509: destination for restored datafile number=8 filename=/users/dba15/data03DBA15_1.dbf
RMAN-08023: channel d1: restored backup piece 1
RMAN-08511: piece handle=/users/dba15/BACK/back_DBA15_full.19.1 params=NULL
RMAN-08024: channel d1: restore complete
RMAN-08016: channel d1: started datafile restore
RMAN-08019: channel d1: restoring datafile number 9
RMAN-08509: destination for restored datafile number=9 filename=/users/dba15/data03DBA15_2.dbf
RMAN-08019: channel d1: restoring datafile number 10
RMAN-08509: destination for restored datafile number=10 filename=/users/dba15/data04DBA15_1.dbf
RMAN-08019: channel d1: restoring datafile number 11
RMAN-08509: destination for restored datafile number=11 filename=/users/dba15/data04DBA15_2.dbf
RMAN-08019: channel d1: restoring datafile number 12
RMAN-08509: destination for restored datafile number=12 filename=/users/dba15/index01DBA15_1.dbf
RMAN-08023: channel d1: restored backup piece 1
RMAN-08511: piece handle=/users/dba15/BACK/back_DBA15_full.20.1 params=NULL
RMAN-08024: channel d1: restore complete
RMAN-08016: channel d1: started datafile restore
RMAN-08019: channel d1: restoring datafile number 13
RMAN-08509: destination for restored datafile number=13 filename=/users/dba15/index01DBA15_2.dbf
RMAN-08019: channel d1: restoring datafile number 14
RMAN-08509: destination for restored datafile number=14 filename=/users/dba15/index02DBA15_1.dbf
RMAN-08019: channel d1: restoring datafile number 15
RMAN-08509: destination for restored datafile number=15 filename=/users/dba15/index02DBA15_2.dbf
RMAN-08019: channel d1: restoring datafile number 16
RMAN-08509: destination for restored datafile number=16 filename=/users/dba15/index03DBA15_1.dbf
RMAN-08023: channel d1: restored backup piece 1
RMAN-08511: piece handle=/users/dba15/BACK/back_DBA15_full.21.1 params=NULL
RMAN-08024: channel d1: restore complete
RMAN-08016: channel d1: started datafile restore
RMAN-08019: channel d1: restoring datafile number 17
RMAN-08509: destination for restored datafile number=17 filename=/users/dba15/index03DBA15_2.dbf
RMAN-08019: channel d1: restoring datafile number 18
RMAN-08509: destination for restored datafile number=18 filename=/users/dba15/index04DBA15_1.dbf
RMAN-08019: channel d1: restoring datafile number 19
RMAN-08509: destination for restored datafile number=19 filename=/users/dba15/index04DBA15_2.dbf
RMAN-08023: channel d1: restored backup piece 1
RMAN-08511: piece handle=/users/dba15/BACK/back_DBA15_full.22.1 params=NULL
RMAN-08024: channel d1: restore complete
RMAN-08031: released channel: d1
RMAN>

10. Exit recovery manager.
    Enter server manager and do a "fake" recovery using :
    recover database until cancel using backup controlfile;

RMAN> exit
Recovery Manager complete.

$ svrmgrl
Oracle Server Manager Release 3.0.2.0.0 - Beta
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle8 Server Release 8.0.2.0.0 - Beta
With the distributed, heterogeneous, replication, objects,
parallel query and Spatial Data options
PL/SQL Release 3.0.2.0.0 - Beta

SVRMGR> connect internal
Connected.

SVRMGR> recover database until cancel using backup controlfile;
ORA-00279: change 134717 generated at 03/17/97 23:05:27 needed for thread 1
ORA-00289: suggestion : /oracle/app/oracle/product/8.0.2/dbs/arch1_623.dbf
ORA-00280: change 134717 for thread 1 is in sequence #623
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
CANCEL
Media recovery cancelled.
SVRMGR>

11. Open the database with the resetlog option.
SVRMGR> alter database open resetlogs;
Statement processed.
SVRMGR>

12. Reset the database from recovery manager.

    (Needs to be done after an incomplete recovery)
$ rman target=\"internal/admin@DBA15\" rcvcat=\"dba15/dba15@DBA16\"
Recovery Manager: Release 8.0.2.0.0 - Beta
RMAN-06005: connected to target database: DBA15
RMAN-06008: connected to recovery catalog database
RMAN> reset database;
RMAN-08006: database registered in recovery catalog
RMAN-08002: starting full resync of recovery catalog
RMAN-08029: snapshot controlfile name set to default value: ?/dbs/snapcf_@.f
RMAN-08004: full resync complete
RMAN>

13. Check how many incarnations of your database you have now.
RMAN> list incarnation of database "DBA15";
RMAN-06240: List of Database Incarnations
RMAN-06241: DB Key  Inc Key DB Name  DB ID            CUR Reset SCN  Reset Time
RMAN-06242: ------- ------- -------- ---------------- --- ---------- -------
RMAN-06243: 1       2       DBA15    4045670789       NO  1          18-FEB-97
RMAN-06243: 1       2172    DBA15    4045670789       YES 134718     18-MAR-97

 
출처 : -

반응형
Posted by [PineTree]
ORACLE/ADMIN2006. 3. 9. 23:12
반응형

ORACLE_SID를 변경하는 방법에 관한 자료


Explanation
-----------
1. 먼저 변경하고자 하는 SID를 v$thread 로 확인한다.

SVRMGR> select instance from v$thread;
INSTANCE
----------------
RC815UT
1 row selected.  


2. DB를 shutdown한다. (shutdown normal or immediate)


3. Full backup을 받는다.(All control, redo, data files backup)

1) datafiles
SVRMGR> select file_name from dba_data_files;
FILE_NAME
----------------------------------------------------
/mnt2/data/RC815UT/oradata/system01.dbf
/mnt2/data/RC815UT/oradata/rbs01.dbf
/mnt2/data/RC815UT/oradata/tools01.dbf
/mnt2/data/RC815UT/oradata/users01.dbf
/mnt2/data/RC815UT/oradata/temp01.dbf 

2) redo log files
SVRMGR> select group#, member from v$logfile;
GROUP#     MEMBER
---------- -----------------------------------------
         1 /mnt2/data/RC815UT/oradata/redoRC815UT01.log
         2 /mnt2/data/RC815UT/oradata/redoRC815UT02.log
         3 /mnt2/data/RC815UT/oradata/redoRC815UT03.log
3 rows selected.                     

3) control files
SVRMGR> select name from v$controlfile;
NAME
----------------------------------------------------
/mnt2/data/RC815UT/oradata/control01.ctl
/mnt2/data/RC815UT/oradata/control02.ctl
/mnt2/data/RC815UT/oradata/control03.ctl
3 rows selected.    

4) full backup
SVRMGR> ! cp /mnt2/data/RC815UT/oradata/* /mnt3/rctest8i/backup


4. .profile, .cshrc, .login, oratab, tnsnames.ora 파일에
ORACLE_SID가 설정되어있다면 이를 모두 새로운 ORACLE_SID명으로 변경시킨다.

OLD ORACLE_SID : RC815UT
NEW ORACLE_SID: RC815NEW


5. $ORACLE_HOME/dbs directory에서 새로운 SID명을 사용하기 위해 다음 파일을 수정한다.

1) initSID.ora 를 새로운 initSID.ora로 rename한다.

initRC815UT.ora -> initRC815NEW.ora

2) initSID.ora file의 ifile에 설정한  configuration parameters 파일도 rename한다.

configRC815UT.ora -> contifRC815NEW.ora

3) initSID.ora와 configSID.ora 파일에 예전 ORACLE_SID관련 사항이 있으면
새로운 ORACLE_SID로 모두 변경한다.

예) initSID.ora
OLD) ifile                           = /mnt2/data/RC815UT/pfile/configRC815UT.ora
NEW) ifile                           = /mnt2/data/RC815UT/pfile/configRC815NEW.ora


6. Optional!!!
-> 기존의 SID명을 가진 data file이나 redo log file을 이용시 6번은 skip해도 된다.

만약 ORACLE_SID를 변경하면서 datafile이나 redo log file 이름도 새로운
SID명으로 함께 변경하려면 새로운 SID명의 디렉토리를 생성하여 mv로 기존 datafile과
redo log file을 모두 옮긴뒤 alter 문으로 rename한다.

기존의 /mnt2/data/RC815UT 에 있는 datafile과 redo log file을 새로운 SID명인
RC815NEW 디렉토리로 unix command 'mv'를 이용하여  모두 이동시킨다.

$mnt2/data/RC815UT> cd..
$mnt2/data> mkdir RC815NEW

$mv mnt2/data/RC815UT/redo* /mnt2/data/RC815NEW
$mv mnt2/data/RC815UT/system01.dbf /mnt2/data/RC815NEW
$mv mnt2/data/RC815UT/rbs01.dbf /mnt2/data/RC815NEW
$mv mnt2/data/RC815UT/tools01.dbf /mnt2/data/RC815NEW
$mv mnt2/data/RC815UT/users01.dbf /mnt2/data/RC815NEW
$mv mnt2/data/RC815UT/temp01.dbf /mnt2/data/RC815NEW

$svrmgrl>
SVRMGR> startup mount
SVRMGR> alter database rename file '/mnt2/data/RC815UT/redoRC815UT01.log' to '/mnt2/data/RC815NEW/redoRC815NEW01.log'
...


7. $ORACLE_HOME/dbs 밑에 orapw<OLD_SID> 가 있으면 새로운 password file로 rename 작업을 수행한다.

만약 orapw<OLD_SID>가 없으면 8번은 넘어간다.
그리고 새로운 orapw<NEW_SID>를 생성하고 싶으면 아래 COMMAND를 이용한다.

orapwd file=orapw<NEWSID password=?? entries=<number of user to be
granted permission to start the database instance>


8. db를 startup하고 shutdown한 다음 full backup을 수행한다.
(backup control, redo, data f iles)


9. 변경된 .profile을 적용하기 위해 다음을 수행한다.

$. ./.profile 을 실행하거나
$export ORACLE_SID=RC815NEW
command를 수행한다.


10. db를 startup 한다.


11. select instance from v$thread;
로 변경된 ORACLE_SID를 확인한다.

SVRMGR> select instance from v$thread;
INSTANCE
----------------
RC815NEW
1 row selected.


12. 기존에 SID명이 기록되어있는 파일들을 수정한다.
$ORACLE_HOME/network/admin/listener.ora 의 SID를 RC815NEW 로 수정
$ORACLE_HOME/network/admin/tnsnames.ora의 SID를 RC815NEW 로 수정

반응형
Posted by [PineTree]
ORACLE/ADMIN2005. 5. 25. 22:11
반응형

문서에 적힌 대로 몇줄만 그대로 따라해보니 접속이 됩니다.

 

형식은 다음과 같습니다

 

htpasswd [-cmdps] passwordfile username

 

다음은 사용예입니다.

 

C:\oracle\ora92\Apache\Apache\bin\htpasswd  -c C:\oracle\ora92\sqlplus\admin\iplusdba.pw  hr(유저명)

 

유저네임까지쓰고 엔터 그리고 패스워드/패스워드확인을 마치면 패스워드파일이 생성됩니다.

 

그리고 아래와 같이 주소창에 입력합니다.(각자의 환경에 맞추어서)

http://61.109.232.86:7778/isqlplusdba

으로 접속하면 네트웍인증창이 뜨면, 위에서 생성된 유저명과 패스워드로 인증을 합니다.

그러면, 다음과 같은

 isqlplusdba 라는 반가운 창이 뜹니다

해당 접속정보를 입력하면 프롬프트상에서와 똑같이 DB를 내리고 올릴수 있는

막강 SYSDBA로서의 임무를 감당할 수 있습니다.

 

신기하지 않습니까? 난 참 신기한데......즐휴일...

반응형

'ORACLE > ADMIN' 카테고리의 다른 글

open_cursor의 개수를 보는 방법  (0) 2006.06.09
ORA-04031 에러 : 메모리 단편화  (0) 2006.05.09
[Oracle]오라클 어드민 팁  (0) 2006.03.17
Oracle 장애의 유형과 문제해결  (0) 2006.03.15
오라클 SID변경 작업  (0) 2006.03.09
Posted by [PineTree]