상세 컨텐츠

본문 제목

2024년 1월 29일 2교시 헌 DB 새 DB 로 만들기, 초기 파라미터 파일이 깨졌을 때의 대처 방법(DBID)

오라클 백업 리커버리

by 병아리 엔지니어 2024. 1. 29. 11:29

본문

 

resetlogs 로 DB 를 오픈하면

과거 시간으로 돌아가는 불완전 복구시에 SCN 번호 때문에 문제가 발생할 소지가 있다.

 

RMAN> list incarnation;

더보기

RMAN> list incarnation;

List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1       1       ORA11G   256148007        PARENT  1          25-AUG-13
2       2       ORA11G   256148007        PARENT  635002     07-DEC-23
3       3       ORA11G   256148007        PARENT  1610055    08-JAN-24
4       4       ORA11G   256148007        PARENT  1891753    16-JAN-24
5       5       ORA11G   256148007        PARENT  2099801    25-JAN-24
6       6       ORA11G   256148007        PARENT  2105719    25-JAN-24
7       7       ORA11G   256148007        PARENT  2151309    26-JAN-24
8       8       ORA11G   256148007        PARENT  2155895    26-JAN-24
9       9       ORA11G   256148007        PARENT  2170776    29-JAN-24
10      10      ORA11G   256148007        CURRENT 2171427    29-JAN-24

 

그래서 아예 처음 DB 를 설치했을 때처럼 되돌아가고 싶을 때가 있는데

그럴 때는 위에 나오는 카탈로그들을 다 지워버리면 된다.

 

1. 카탈로그 지우기

 

RMAN> drop catalog;

더보기

RMAN> drop catalog;

recovery catalog owner is
enter DROP CATALOG command again to confirm catalog removal

 

2. 컨트롤파일 재생성하기

(현재 컨트롤파일의 trace 뜨기 > 재생)

 

SYS@ora11g> alter database backup controlfile to trace as '/home/oracle/con.sql';
Database altered.

 

3. 컨트롤파일을 재생성한 다음 DB 는 무조건 내려야 한다.

 

SYS@ora11g> shutdown immediate;

 

4. 트레이스파일 vi 편집기로 열기

 

SYS@ora11g> ! vi con.sql

복사하기

(QUESTION. 이거 편집기로 열어서 내용은 건드리지 않고 그대로 내버려두는 거지?

그냥 복사해와서 resetlogs 앞에 no 만 붙이면 되는 거지?

다른 데도 고친 데 있었나?)

(ANSWER. 고친 데 없다. 그냥 그대로 복사해왔을 뿐...

그리고 만치에 말로는 아래 스크립트가 resetlogs 로 된 것도 있었고 noresetlogs로 된 것도 있었다는데

난 모르겠어... 그게 여러 개였는지도 지금 알았어.

아무튼 수행이 제대로 됐으면 된 거니까 뭐)

더보기

CREATE CONTROLFILE REUSE DATABASE "ORA11G" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/ora11g/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/u01/app/oracle/oradata/ora11g/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/u01/app/oracle/oradata/ora11g/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/ora11g/system01.dbf',
  '/u01/app/oracle/oradata/ora11g/sysaux01.dbf',
  '/u01/app/oracle/oradata/ora11g/users01.dbf',
  '/u01/app/oracle/oradata/ora11g/example01.dbf',
  '/u01/app/oracle/oradata/ora11g/undotbs01.dbf'
CHARACTER SET AL32UTF8
;

 

SYS@ora11g> startup nomount

DB 노마운트 단계까지 올리기

 

5. 위의 접은글 부분 내용 복사해서 SQL + 에 붙여넣고 컨트롤파일 만들기

Control file created.

 

6. 데이터베이스 리커버리

 

SYS@ora11g> recover database;
ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required

 

(리커버리할 대상이 없다는 뜻... 이런 오류는 사랑스런 오류 )

 

7. DB 오픈 (resetlogs로 오픈하지 않는다. 그냥 오픈하면 됨)

 

SYS@ora11g> alter database open;
Database altered.

 

8. RMAN 으로 새로 접속해서 인카네이션 정보 확인하기

 

RMAN> list incarnation;

using target database control file instead of recovery catalog

List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1       1       ORA11G   256148007        CURRENT 2171427    29-JAN-24

 

오늘 새로 만든 것처럼 카탈로그가 하나만 뜬다.

 

8. 컨트롤파일을 재생성하면 템프 파일은 생성이 안되어있기 때문에 꼭 생성해주기

 

SYS@ora11g> select * from v$tempfile;
no rows selected

템프파일이 하나도 없다고 나오면

 

SYS@ora11g> alter tablespace temp add tempfile '/u01/app/oracle/oradata/ora11g/temp01.dbf' size 30408704 reuse autoextend on next 655360 maxsize 32767m;

Tablespace altered.

새로 만들어주기

 

잘 만들어졌는지 확인해보기

SYS@ora11g> select * from v$tempfile;

     FILE# CREATION_CHANGE# CREATION_        TS#     RFILE# STATUS  ENABLED
---------- ---------------- --------- ---------- ---------- ------- ----------
     BYTES     BLOCKS CREATE_BYTES BLOCK_SIZE
---------- ---------- ------------ ----------
NAME
--------------------------------------------------------------------------------
         1          2176151 29-JAN-24          3          1 ONLINE  READ WRITE
  30408704       3712     30408704       8192
/u01/app/oracle/oradata/ora11g/temp01.dbf

 

(DB 를 처음으로 되돌린 다음에

DB를 그 이전 시간으로 되돌리는 타임 베이스 리커버리는 불가능하다.)

 

9. 백업 다시 받기

 

RMAN> list backup;
백업 정보를 확인해보면:

specification does not match any backup in the repository

하나도 없다고 나온다. (DB 를 재생성했으므로)

 

그래서 이 시점에 꼭 콜드 백업을 받아놓는 것이 좋다.

(/home/oracle/backup/arch 디렉토리에 cold_20240129 라는 이름으로 콜드 백업 받아놓음)

 

RMAN> backup as compressed backupset database;

백업 다시 받기

백업셋 번호는 다시 1번부터 시작된다.

 

RMAN> list backup;

더보기

RMAN> list backup;

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    328.07M    DISK        00:00:30     29-JAN-24   
        BP Key: 1   Status: AVAILABLE  Compressed: YES  Tag: TAG20240129T105858
        Piece Name: /u01/app/oracle/fast_recovery_area/ORA11G/backupset/2024_01_29/o1_mf_nnndf_TAG20240129T105858_lvg1m2g9_.bkp
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 2176257    29-JAN-24 /u01/app/oracle/oradata/ora11g/system01.dbf
  2       Full 2176257    29-JAN-24 /u01/app/oracle/oradata/ora11g/sysaux01.dbf
  4       Full 2176257    29-JAN-24 /u01/app/oracle/oradata/ora11g/users01.dbf
  5       Full 2176257    29-JAN-24 /u01/app/oracle/oradata/ora11g/example01.dbf
  6       Full 2176257    29-JAN-24 /u01/app/oracle/oradata/ora11g/undotbs01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2       Full    1.03M      DISK        00:00:02     29-JAN-24   
        BP Key: 2   Status: AVAILABLE  Compressed: YES  Tag: TAG20240129T105858
        Piece Name: /u01/app/oracle/fast_recovery_area/ORA11G/backupset/2024_01_29/o1_mf_ncsnf_TAG20240129T105858_lvg1n6wl_.bkp
  SPFILE Included: Modification time: 29-JAN-24
  SPFILE db_unique_name: ORA11G
  Control File Included: Ckp SCN: 2176275      Ckp time: 29-JAN-24

10.

정책상 필요없는 것들 다시 한번 꼭 체크하기

 

RMAN> report obsolete;
RMAN> delete obsolete;

 

RMAN> list expired archivelog all;

RMAN> delete expired archivelog all;

RMAN> list expired archivelog all;

RMAN> report obsolete;

 

11. 콜드 백업 받아놓기 (2023년 1월 12일 3교시 참고)

 

12. DB 내리고

 

13. 초기 파라미터 파일이 있는 곳으로 가서 초기 파라미터 파일 지우기

[oracle@oracle ~]$ cd $ORACLE_HOME/dbs

 

[oracle@oracle dbs]$ ls
hc_clone.dat   initora11g_20240116.ora  orapwora11g
hc_ora11g.dat  initora11g.ora           snapcf_ora11g.f
initclone.ora  lkCLONE                  spfileora11g.ora
init.ora       lkORA11G

 

[oracle@oracle dbs]$ rm spfileora11g.ora

[oracle@oracle dbs]$ rm initora11g.ora

 

14. 그리고 DB 올리려고 하면 : 초기 파라미터 파일이 없어서 오류가 발생한다.

 

SYS@ora11g> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0.4/db_1/dbs/initora11g.ora'

 

15. RMAN 으로 새로 접속

 

[oracle@oracle ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jan 29 11:10:37 2024
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database (not started)

 

그래도 RMAN> startup nomount 해보면

오류는 발생했지만 어쨌든 샘플로 노마운트 단계까지 올려는 준다.

(리커버리를 하기 위해서 메모리를 만들어주는 작업을 해주는 것)

 

16. 백업받아놓은 것 찾아서 리스토어 작업하기

 

RMAN> restore spfile from autobackup;

오류 발생 (복구를 위해 임시로 만들어놓은 메모리이기 때문에 DB ID 값을 몰라서 발생한 오류)

그래서 DB ID 를 꼭 기록해놓고 있어야 한다.

 

RMAN> restore spfile from autobackup;

Starting restore at 29-JAN-24
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=171 device type=DISK

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/29/2024 11:11:54
RMAN-06495: must explicitly specify DBID with SET DBID command

 

17. DB ID 설정하기

 

DB ID 는 맨 처음 RMAN 으로 접속했을 때를 보면 찾을 수 있다.

못 찾겠으면 나갔다가 들어와보기

 

[oracle@oracle ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Jan 29 09:41:11 2024
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORA11G (DBID=256148007)

 

RMAN> set dbid 256148007;
executing command: SET DBID

 

DB 아이디를 설정하고

 

18. 가장 최근에 받아놓은 백업본 찾으러 가기

 

/u01/app/oracle/fast_recovery_area/ORA11G/autobackup

RMAN 백업본은 모두 이 위치에 떨어지도록 되어 있는데

 

[oracle@oracle cold_20240129]$ cd /u01/app/oracle/fast_recovery_area/ORA11G/autobackup

백업본이 떨어지는 위치로 가서

 

[oracle@oracle autobackup]$ ls
2024_01_24  2024_01_25  2024_01_26  2024_01_29

 

[oracle@oracle autobackup]$ cd 2024_01_29

오늘 받아놓은 백업본 폴더로 들어간 다음

 

[oracle@oracle 2024_01_29]$ ls -alt

거기 있는 파일들 모두 시간순으로 정렬하기

(ls -alt 명령어를 쓰면 파일들이 가장 최근에 생긴 파일순으로 위에서부터 정렬된다.

즉, 맨 위에 있는 것이 가장 최근에 받은 파일)

 

[oracle@oracle 2024_01_29]$ ls -alt
total 29956
-rw-r-----. 1 oracle oinstall 10223616 Jan 29 10:13 o1_mf_s_1159524816_lvfyy0ls_.bkp
drwxr-x---. 2 oracle oinstall     4096 Jan 29 10:13 .
-rw-r-----. 1 oracle oinstall 10223616 Jan 29 10:07 o1_mf_s_1159524434_lvfyl37q_.bkp
-rw-r-----. 1 oracle oinstall 10223616 Jan 29 09:45 o1_mf_s_1159523107_lvfx8n4v_.bkp
drwxr-x---. 6 oracle oinstall       78 Jan 29 09:45 ..

 

(파란색으로 표시해놓은 파일이 가장 최근에 받은 백업본)

 

19. 가장 최근의 백업본을 가지고 초기 파라미터 파일 복구하기

 

RMAN> restore spfile from '/u01/app/oracle/fast_recovery_area/ORA11G/autobackup/2024_01_29/o1_mf_s_1159524816_lvfyy0ls_.bkp';

복구하고

 

20. 다시 RMAN 에서 DB 내렸다 올리기

 

RMAN> shutdown abort
Oracle instance shut down

임시 메모리에서 나간 다음

 

RMAN> startup

DB 올리기

 

21. SQL+ 에서 초기 파라미터 파일 확인하기

 

SYS@ora11g> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/11.2.0
                                                 .4/db_1/dbs/spfileora11g.ora

 

잘 만들어져 있다.

 

SYS@ora11g> create pfile from spfile;
File created.

 

그리고 pfile 을 만들려면 너무 힘들기 때문에,

꼭 미리미리 pfile 을 열어서 문서에 붙여넣어놓고 보관해놓도록 하자.

 

22. 그리고 나서 다시 RMAN  의 환경을 보면: 다 초기화되어 있는데

컨트롤파일 자동 백업 설정 ON 으로 바꿔주기

 

RMAN> configure controlfile autobackup on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

관련글 더보기