I. 설치
1. 사전 환경 구성
A) 서버 정보 hosts 파일 저장
10.10.50.11 ora_act 10.10.50.21 ora_stb
hosts 파일에 Primary 서버의 정보와 Standby 서버의 정보를 입력합니다.
IP를 입력하지 않고 등록된 서버 정보로 접속을 하기 위한 작업입니다.
B) db name 파라미터 조회
show parameter db_name show parameter db_unique_name
SQL> show parameter db_name NAME TYPE VALUE ------------------------------------ --------------------------------- ------------------------------ db_name string orcl SQL> show parameter db_unique_name NAME TYPE VALUE ------------------------------------ --------------------------------- ------------------------------ db_unique_name string ORCL
만약 db_unique_name을 변경해야 할 경우 다음과 같이 spfile에 적용하여 변경한 후에 데이터베이스를 재기동해줍니다. (온라인 변경 불가능)
ALTER SYSTEM SET db_unique_name = ORCL scope=spfile;
SQL> ALTER SYSTEM SET db_unique_name = ORCL scope=spfile; System altered.
db_name 파라미터 값은 모두 동일하지만, db_unique_name은 Primary와 Standby가 달라야 합니다.
구분 | db_name | db_unique_name |
---|---|---|
Primary | orcl | ORCL |
Standby | orcl | ORCL_STB |
2. Data Guard 사용을 위한 파라미터 설정
A) 아카이브 환경 설정
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(ORCL,ORCL_STB)'; ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=ORCL_STB NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL_STB'; ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE; ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE; ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=30;
SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(ORCL,ORCL_STB)'; System altered. SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=ORCL_STB NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL_STB'; System altered. SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE; System altered. SQL> ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE; System altered. SQL> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=30; System altered.
Data Guard 운영에 필수적인 아카이브 관련 파라미터를 설정합니다.
- LOG_ARCHIVE_CONFIG : 리두 로그를 원격 대상으로 보내고 원격 리두 로그를 수신하며, Data Guard 구성에서 각 데이터베이스의 DB_UNIQUE_NAME을 지정합니다.
- LOG_ARCHIVE_DEST_2 : 아카이브 리두 로그를 보낼 원격 대상의 정보와 전송할 데이터와 방식에 대하여 지정합니다.
- LOG_ARCHIVE_DEST_STATE_2 : LOG_ARCHIVE_DEST_2에서 지정한 경로의 활성화/비활성화 등의 상태를 지정합니다.
- LOG_ARCHIVE_FORMAT : 아카이브 로그 파일명의 포맷을 지정합니다.
- LOG_ARCHIVE_MAX_PROCESSES : 최대 ARCn 프로세스의 수를 지정합니다.
B) 패스워드 접속 방식 설정
ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=shared SCOPE=SPFILE;
SQL> ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=shared SCOPE=SPFILE; System altered.
오라클이 원격 접속 시에 패스워드 파일을 사용할지의 여부를 지정합니다.
C) Data Guard 관련 파라미터 설정
ALTER SYSTEM SET FAL_CLIENT=ORCL; ALTER SYSTEM SET FAL_SERVER=ORCL_STB; ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
SQL> ALTER SYSTEM SET FAL_CLIENT=ORCL; System altered. SQL> ALTER SYSTEM SET FAL_SERVER=ORCL_STB; System altered. SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO; System altered.
Data Guard 환경 구성을 위한 파라미터를 설정합니다.
- FAL_CLIENT : FAL(fetch archive log) 클라이언트를 참조하기 위해 FAL_SERVER 초기화 매개 변수를 통해 구성된 FAL 클라이언트 이름을 지정합니다.
- FAL_SERVER : Standby 데이터베이스에 대한 FAL(fetch archive log) 서버를 지정합니다.
STANDBY_FILE_MANAGEMENT : Physical Standby에 automatic standby file management를 활성화 또는 비활성화합니다. 자동 대기 파일 관리를 사용하면 primary 데이터베이스의 파일 추가 및 삭제 작업이 standby 데이터베이스에도 적용됩니다.
3. 로그 모드 설정
A) 아카이브 로그 모드 활성화
SELECT log_mode FROM v$database;
SQL> SELECT log_mode FROM v$database; LOG_MODE ------------------------------------ ARCHIVELOG
No archive 모드시 다음과 같이 변경합니다.
SHUTDOWN IMMEDIATE; STARTUP MOUNT; ALTER DATABASE ARCHIVELOG; ALTER DATABASE OPEN;
SQL> SELECT log_mode FROM v$database; LOG_MODE ------------------------------------ NOARCHIVELOG SQL> SHUTDOWN IMMEDIATE; Database closed. Database dismounted. ORACLE instance shut down. SQL> STARTUP MOUNT; ORACLE instance started. Total System Global Area 835104768 bytes Fixed Size 2257840 bytes Variable Size 541068368 bytes Database Buffers 289406976 bytes Redo Buffers 2371584 bytes Database mounted. SQL> ALTER DATABASE ARCHIVELOG; Database altered. SQL> ALTER DATABASE OPEN; Database altered. SQL> SELECT log_mode FROM v$database; LOG_MODE ------------------------------------ ARCHIVELOG
Data Guard를 사용하기 위해서는 반드시 Archive log 모드로 구성이 되어 있어야 합니다.
로그 모드를 조회한 후 noarchive 상태이면 반드시 archive 상태로 변경합니다.
B) 강제 로그 적용 모드 활성화
ALTER DATABASE FORCE LOGGING; ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER DATABASE FORCE LOGGING; Database altered. SQL> ALTER SYSTEM SWITCH LOGFILE; System altered.
추가적으로 force logging 모드로 전환하여, 모든 작업이 강제적으로 로그로 기록될 수 있도록 합니다.
C) Flashback Database 활성화 (옵션)
ALTER DATABASE FLASHBACK ON;
Flashback Database의 적용 여부는 v$database 뷰에서 확인 가능합니다.
SELECT flashback_on FROM v$database;
SQL> SELECT flashback_on FROM v$database; FLASHBACK_ON ------------------------------------------------------ NO SQL> ALTER DATABASE FLASHBACK ON; Database altered. SQL> SELECT flashback_on FROM v$database; FLASHBACK_ON ------------------------------------------------------ YES
Failover가 발생할 경우, primary를 재사용할 수 있도록 하기 위해 설정합니다.
4. Standby Database 컨트롤, 파라미터 파일 작업
A) 컨트롤, 파라미터 파일 생성
ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/home/oracle/orcl_stb.ctl'; CREATE PFILE='/home/oracle/orcl_stb.ora' FROM SPFILE;
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/home/oracle/orcl_stb.ctl'; Database altered. SQL> CREATE PFILE='/home/oracle/orcl_stb.ora' FROM SPFILE; File created.
Standby에서 사용할 데이터베이스 컨트롤 파일과 파라미터 파일을 Primary에서 생성합니다.
B) Standby 파라미터 파일 수정
*.db_unique_name='ORCL_STB' *.service_names='ORCL_STB'
생성한 orcl_stb.ora 파일에서 Standby 환경에 맞게 파라미터 값들을 수정합니다.
db_unique_name은 반드시 primary와 다르게 지정합니다.
service_name도 primary와 구분하기 위해 다르게 지정합니다.
C) Standby로 파일 복제
scp oracle@ora_act:/home/oracle/orcl_stb.ctl <컨트롤 파일 1번 경로>/control01.ctl cp <컨트롤 파일 1번 경로>/control01.ctl <컨트롤 파일 2번 경로>/control02.ctl scp oracle@ora_act:/home/oracle/orcl_stb.ora /home/oracle/orcl_stb.ora scp oracle@ora_act:$ORACLE_HOME/dbs/orapworcl $ORACLE_HOME/dbs
[oracle@orcl ~]$ scp oracle@ora_act:/home/oracle/orcl_stb.ctl /oradata/orcl/control01.ctl The authenticity of host 'ora_act (10.10.50.11)' can't be established. RSA key fingerprint is a9:cf:9d:a5:a3:b4:8b:7b:82:a8:0f:08:84:2f:19:e0. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'ora_act,10.10.50.11' (RSA) to the list of known hosts. oracle@ora_act's password: orcl_stb.ctl 100% 9520KB 9.3MB/s 00:00 [oracle@orcl ~]$ cp /oradata/orcl/control01.ctl /oradata/fast_recovery_area/orcl/control02.ctl [oracle@orcl ~]$ scp oracle@ora_act:/home/oracle/orcl_stb.ora /home/oracle/orcl_stb.ora oracle@ora_act's password: orcl_stb.ora 100% 1296 1.3KB/s 00:00 [oracle@orcl ~]$ scp oracle@ora_act:$ORACLE_HOME/dbs/orapworcl $ORACLE_HOME/dbs oracle@ora_act's password: orapworcl 100% 1536 1.5KB/s 00:00
Primary에서 작업한 컨트롤 파일과 파라미터 파일을 Standby로 복제합니다.
컨트롤 파일의 경우 파라미터 파일 내에 경로에 맞는 위치로 복제해야 합니다.
5. Standby Log 파일 생성
ALTER DATABASE ADD STANDBY LOGFILE ('<기존 redo log 저장 경로>/standby_redo01.log') SIZE 50M; ALTER DATABASE ADD STANDBY LOGFILE ('<기존 redo log 저장 경로>/standby_redo02.log') SIZE 50M; ALTER DATABASE ADD STANDBY LOGFILE ('<기존 redo log 저장 경로>/standby_redo03.log') SIZE 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE ('/oradata/orcl/standby_redo01.log') SIZE 50M; Database altered. SQL> ALTER DATABASE ADD STANDBY LOGFILE ('/oradata/orcl/standby_redo02.log') SIZE 50M; Database altered. SQL> ALTER DATABASE ADD STANDBY LOGFILE ('/oradata/orcl/standby_redo03.log') SIZE 50M; Database altered.
Standby Redo Log를 primary에 생성합니다. 가급적 primary와 동일한 갯수와 사이즈로 생성하도록 합니다.
6. 네트워크 설정
A) Standby의 listener.ora 파일 생성
LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ora_stb)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = ORCL_STB) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcl) ) ) ADR_BASE_LISTENER = /u01/app/oracle
Standby 쪽의 listener.ora 파일은 아래와 같습니다.
B) tnsname.ora 설정
ORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ora_act)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ORCL) ) ) ORCL_STB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ora_stb)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ORCL_STB) ) )
tnsnames.ora 파일의 내용을 설정합니다.
Primary와 Standby DB에 접속 정보가 저장되며, Primary와 Standby 노드 모두 같은 내용을 사용합니다.
저장 위치는 $ORACLE_HOME/network/admin/tnsnames.ora 입니다.
7. 데이터베이스 복제
A) Standby Database 인스턴스 기동
sqlplus / as sysdba startup nomount pfile='/home/oracle/orcl_stb.ora';
[oracle@orcl ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 14 14:54:26 2018 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount pfile='/home/oracle/orcl_stb.ora'; ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2257880 bytes Variable Size 545262632 bytes Database Buffers 289406976 bytes Redo Buffers 2355200 bytes
데이터베이스 복제를 위해 Standby 인스턴스를 복제한 파라미터 파일로 기동합니다.
B) RMAN 접속
rman TARGET sys/oracle@ORCL AUXILIARY sys/oracle@ORCL_STB
[oracle@orcl ~]$ rman TARGET sys/oracle@ORCL AUXILIARY sys/oracle@ORCL_STB Recovery Manager: Release 11.2.0.4.0 - Production on Tue Aug 14 15:04:22 2018 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1511929243) connected to auxiliary database: ORCL (not mounted)
RMAM으로 primary 데이터베이스와 standby 인스턴스를 접속합니다.
Primary는 target으로, standby는 auxiliary로 접속합니다.
Primary나 standby 어느 곳에서 접속해도 됩니다.
C) Standby로 데이터베이스 복제
DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER SPFILE SET db_unique_name='ORCL_STB' COMMENT 'Is standby' SET LOG_ARCHIVE_DEST_2='SERVICE=ORCL ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL' SET FAL_SERVER='ORCL' COMMENT 'Is primary' NOFILENAMECHECK;
RMAN> DUPLICATE TARGET DATABASE 2> FOR STANDBY 3> FROM ACTIVE DATABASE 4> DORECOVER 5> SPFILE 6> SET db_unique_name='ORCL_STB' COMMENT 'Is standby' 7> SET LOG_ARCHIVE_DEST_2='SERVICE=ORCL ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL' 8> SET FAL_SERVER='ORCL' COMMENT 'Is primary' 9> NOFILENAMECHECK; Starting Duplicate Db at 18/08/14 using target database control file instead of recovery catalog allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=1 device type=DISK contents of Memory Script: { backup as copy reuse targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl' auxiliary format '/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl' targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora' auxiliary format '/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora' ; sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora''"; } executing Memory Script Starting backup at 18/08/14 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=74 device type=DISK Finished backup at 18/08/14 sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora'' contents of Memory Script: { sql clone "alter system set db_unique_name = ''ORCL_STB'' comment= ''Is standby'' scope=spfile"; sql clone "alter system set LOG_ARCHIVE_DEST_2 = ''SERVICE=ORCL ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL'' comment= '''' scope=spfile"; sql clone "alter system set FAL_SERVER = ''ORCL'' comment= ''Is primary'' scope=spfile"; shutdown clone immediate; startup clone nomount; } executing Memory Script sql statement: alter system set db_unique_name = ''ORCL_STB'' comment= ''Is standby'' scope=spfile sql statement: alter system set LOG_ARCHIVE_DEST_2 = ''SERVICE=ORCL ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL'' comment= '''' scope=spfile sql statement: alter system set FAL_SERVER = ''ORCL'' comment= ''Is primary'' scope=spfile Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 839282688 bytes Fixed Size 2257880 bytes Variable Size 545262632 bytes Database Buffers 289406976 bytes Redo Buffers 2355200 bytes contents of Memory Script: { backup as copy current controlfile for standby auxiliary format '/oradata/orcl/control01.ctl'; restore clone controlfile to '/oradata/fast_recovery_area/orcl/control02.ctl' from '/oradata/orcl/control01.ctl'; } executing Memory Script Starting backup at 18/08/14 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy copying standby control file output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.f tag=TAG20180814T150532 RECID=3 STAMP=984150332 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03 Finished backup at 18/08/14 Starting restore at 18/08/14 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=18 device type=DISK channel ORA_AUX_DISK_1: copied control file copy Finished restore at 18/08/14 contents of Memory Script: { sql clone 'alter database mount standby database'; } executing Memory Script sql statement: alter database mount standby database RMAN-05538: WARNING: implicitly using DB_FILE_NAME_CONVERT contents of Memory Script: { set newname for tempfile 1 to "/oradata/orcl/temp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/oradata/orcl/system01.dbf"; set newname for datafile 2 to "/oradata/orcl/sysaux01.dbf"; set newname for datafile 3 to "/oradata/orcl/undotbs01.dbf"; set newname for datafile 4 to "/oradata/orcl/users01.dbf"; set newname for datafile 5 to "/oradata/orcl/example01.dbf"; backup as copy reuse datafile 1 auxiliary format "/oradata/orcl/system01.dbf" datafile 2 auxiliary format "/oradata/orcl/sysaux01.dbf" datafile 3 auxiliary format "/oradata/orcl/undotbs01.dbf" datafile 4 auxiliary format "/oradata/orcl/users01.dbf" datafile 5 auxiliary format "/oradata/orcl/example01.dbf" ; sql 'alter system archive log current'; } executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /oradata/orcl/temp01.dbf in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 18/08/14 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile file number=00001 name=/oradata/orcl/system01.dbf output file name=/oradata/orcl/system01.dbf tag=TAG20180814T150542 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00002 name=/oradata/orcl/sysaux01.dbf output file name=/oradata/orcl/sysaux01.dbf tag=TAG20180814T150542 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45 channel ORA_DISK_1: starting datafile copy input datafile file number=00005 name=/oradata/orcl/example01.dbf output file name=/oradata/orcl/example01.dbf tag=TAG20180814T150542 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35 channel ORA_DISK_1: starting datafile copy input datafile file number=00003 name=/oradata/orcl/undotbs01.dbf output file name=/oradata/orcl/undotbs01.dbf tag=TAG20180814T150542 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:16 channel ORA_DISK_1: starting datafile copy input datafile file number=00004 name=/oradata/orcl/users01.dbf output file name=/oradata/orcl/users01.dbf tag=TAG20180814T150542 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 18/08/14 sql statement: alter system archive log current contents of Memory Script: { backup as copy reuse archivelog like "/oradata/fast_recovery_area/ORCL/archivelog/2018_08_14/o1_mf_1_10_fq4wh263_.arc" auxiliary format "/oradata/fast_recovery_area/ORCL_STB/archivelog/2018_08_14/o1_mf_1_10_%u_.arc" ; catalog clone recovery area; switch clone datafile all; } executing Memory Script Starting backup at 18/08/14 using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log copy input archived log thread=1 sequence=10 RECID=6 STAMP=984150514 output file name=/oradata/fast_recovery_area/ORCL_STB/archivelog/2018_08_14/o1_mf_1_10_0btahsfi_.arc RECID=0 STAMP=0 channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01 Finished backup at 18/08/14 searching for all files in the recovery area List of Files Unknown to the Database ===================================== File Name: /oradata/fast_recovery_area/ORCL_STB/archivelog/2018_08_14/o1_mf_1_10_0btahsfi_.arc cataloging files... cataloging done List of Cataloged Files ======================= File Name: /oradata/fast_recovery_area/ORCL_STB/archivelog/2018_08_14/o1_mf_1_10_0btahsfi_.arc datafile 1 switched to datafile copy input datafile copy RECID=3 STAMP=984150515 file name=/oradata/orcl/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=4 STAMP=984150515 file name=/oradata/orcl/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=5 STAMP=984150515 file name=/oradata/orcl/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=6 STAMP=984150515 file name=/oradata/orcl/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=7 STAMP=984150515 file name=/oradata/orcl/example01.dbf contents of Memory Script: { set until scn 996856; recover standby clone database delete archivelog ; } executing Memory Script executing command: SET until clause Starting recover at 18/08/14 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 10 is already on disk as file /oradata/fast_recovery_area/ORCL_STB/archivelog/2018_08_14/o1_mf_1_10_0btahsfi_.arc archived log file name=/oradata/fast_recovery_area/ORCL_STB/archivelog/2018_08_14/o1_mf_1_10_0btahsfi_.arc thread=1 sequence=10 media recovery complete, elapsed time: 00:00:00 Finished recover at 18/08/14 Finished Duplicate Db at 18/08/14
Duplicate target database 명령을 이용해 primary 데이터베이스를 standby로 복제합니다.
II. 수동 관리
1. Managed Recovery Mode 활성화하기
-- Foreground 모드로 수행 (취소하기 전까지 대기 모드로 유지됨) -- ALTER DATABASE RECOVER MANAGED STANDBY DATABASE; -- Background 모드로 수행 (프로세스 시작 후 입력 가능한 모드로 전환) ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
2. Managed Recovery Mode 취소하기
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
3. Switchover
A) Primary를 Standby로 전환
ALTER DATABASE COMMIT TO SWITCHOVER TO STANDBY; SHUTDOWN IMMEDIATE; STARTUP NOMOUNT; ALTER DATABASE MOUNT STANDBY DATABASE; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
B) Standby를 Primary로 전환
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY; SHUTDOWN IMMEDIATE; STARTUP;
III. Data Guard Broker
1. 네트워크 설정
A) Primary의 listener.ora 파일 수정
LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ora_act)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = ORCL) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcl) ) (SID_DESC = (GLOBAL_DBNAME = ORCL_DGMGRL) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcl) ) ) ADR_BASE_LISTENER = /u01/app/oracle
Data Guard Broker를 사용한다면 static listener인 DGMGRL을 별도로 등록해줍니다.
서비스를 등록하지 않을 경우, DGMGRL에서 데이터베이스를 재기동하거나 switchover하는 과정에 서비스를 찾지 못해 실패하게 됩니다.
(SID_DESC = (GLOBAL_DBNAME = ORCL_DGMGRL) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcl) )
B) Standby의 listener.ora 파일 수정
LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ora_stb)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = ORCL_STB) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcl) ) (SID_DESC = (GLOBAL_DBNAME = ORCL_STB_DGMGRL) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcl) ) ) ADR_BASE_LISTENER = /u01/app/oracle
Standby 리스너도 마찬가지로 DGMGRL 를 추가합니다.
(SID_DESC = (GLOBAL_DBNAME = ORCL_STB_DGMGRL) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcl) )
2. Data Guard Broker 환경 구성
A) Data Guard Broker 활성화
ALTER SYSTEM SET dg_broker_start=true;
SQL> ALTER SYSTEM SET dg_broker_start=true; System altered.
Primary와 Standby 양쪽에 dg_broker_start를 true로 변경하여, Data Guard Broker를 기동시킵니다.
B) DGMGRL 접속
dgmgrl sys/oracle@orcl
[oracle@orcl ~]$ dgmgrl sys/oracle@orcl DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production Copyright (c) 2000, 2009, Oracle. All rights reserved. Welcome to DGMGRL, type "help" for information. Connected.
원격 접속이 구성된 환경에서 오라클 클라이언트를 통해 DGMGRL에 접속할 수 있습니다.
원격 접속에서 password file 파일을 사용할 수 있도록 암호를 입력하는 방식으로 접속합니다.
C) 데이터베이스 등록
CREATE CONFIGURATION orcl_dg AS PRIMARY DATABASE IS orcl CONNECT IDENTIFIER IS orcl; ADD DATABASE orcl_stb AS CONNECT IDENTIFIER IS orcl_stb MAINTAINED AS PHYSICAL;
DGMGRL> CREATE CONFIGURATION orcl_dg AS PRIMARY DATABASE IS orcl CONNECT IDENTIFIER IS orcl; Configuration "orcl_dg" created with primary database "orcl"
DGMGRL> ADD DATABASE orcl_stb AS CONNECT IDENTIFIER IS orcl_stb MAINTAINED AS PHYSICAL; Database "orcl_stb" added
Primary 데이터베이스와 standby 데이터베이스를 Broker에 등록합니다.
D) Data Guard Broker 설정 활성화
ENABLE CONFIGURATION;
DGMGRL> SHOW CONFIGURATION; Configuration - orcl_dg Protection Mode: MaxPerformance Databases: orcl - Primary database orcl_stb - Physical standby database Fast-Start Failover: DISABLED Configuration Status: DISABLED DGMGRL> ENABLE CONFIGURATION; Enabled.
등록된 설정값을 갖고 Data Guard Broker를 활성화합니다.
E) Data Guard Broker 등록 정보 조회
SHOW CONFIGURATION; SHOW DATABASE orcl; SHOW DATABASE orcl_stb;
DGMGRL> SHOW CONFIGURATION; Configuration - orcl_dg Protection Mode: MaxPerformance Databases: orcl - Primary database orcl_stb - Physical standby database Fast-Start Failover: DISABLED Configuration Status: SUCCESS
DGMGRL> SHOW DATABASE orcl; Database - orcl Role: PRIMARY Intended State: TRANSPORT-ON Instance(s): orcl Database Status: SUCCESS
DGMGRL> SHOW DATABASE orcl_stb; Database - orcl_stb Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 1 second ago) Apply Lag: 0 seconds (computed 1 second ago) Apply Rate: 0 Byte/s Real Time Query: OFF Instance(s): orcl Database Status: SUCCESS
Data Guard Broker에 등록된 내용을 SHOW 명령어로 조회할 수 있습니다.
3. Switchover
A) Standby로 switchover하기
SWITCHOVER TO orcl_stb;
DGMGRL> SWITCHOVER TO orcl_stb; Performing switchover NOW, please wait... New primary database "orcl_stb" is opening... Operation requires startup of instance "orcl" on database "orcl" Starting instance "orcl"... ORACLE instance started. Database mounted. Switchover succeeded, new primary is "orcl_stb"
DGMGRL> SHOW CONFIGURATION; Configuration - orcl_dg Protection Mode: MaxPerformance Databases: orcl_stb - Primary database orcl - Physical standby database Fast-Start Failover: DISABLED Configuration Status: SUCCESS
Switchover 명령어를 이용하면 standby로 서비스를 switch over할 수 있습니다.
Primary로 원복을 하려면 다음의 명령어를 입력하면 됩니다.
SWITCHOVER TO orcl;
4. Failover
A) Standby로 Failover하기
FAILOVER TO orcl_stb;
[oracle@orcl ~]$ dgmgrl sys/oracle@orcl_stb DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production Copyright (c) 2000, 2009, Oracle. All rights reserved. Welcome to DGMGRL, type "help" for information. Connected. DGMGRL> FAILOVER TO orcl_stb; Performing failover NOW, please wait... Failover succeeded, new primary is "orcl_stb"
Standby로 failover를 수행합니다.
가급적 standby로 접속하여 명령을 수행합니다.
SHOW DATABASE orcl_stb; SHOW CONFIGURATION;
DGMGRL> SHOW DATABASE orcl_stb; Database - orcl_stb Role: PRIMARY Intended State: TRANSPORT-ON Instance(s): orcl Database Status: SUCCESS DGMGRL> SHOW CONFIGURATION; Configuration - orcl_dg Protection Mode: MaxPerformance Databases: orcl_stb - Primary database orcl - Physical standby database (disabled) ORA-16661: the standby database needs to be reinstated Fast-Start Failover: DISABLED Configuration Status: SUCCESS
Failover가 정상적으로 완료되었는지 확인합니다.
기존의 Primary는 disabled로 복구가 필요한 상태입니다.
B) Disable된 primary를 reinstate하기
REINSTATE DATABASE orcl;
DGMGRL> REINSTATE DATABASE orcl; Reinstating database "orcl", please wait... Operation requires shutdown of instance "orcl" on database "orcl" Shutting down instance "orcl"... Database closed. Database dismounted. ORACLE instance shut down. Operation requires startup of instance "orcl" on database "orcl" Starting instance "orcl"... ORACLE instance started. Database mounted. Continuing to reinstate database "orcl" ... Operation requires shutdown of instance "orcl" on database "orcl" Shutting down instance "orcl"... ORA-01109: database not open Database dismounted. ORACLE instance shut down. Operation requires startup of instance "orcl" on database "orcl" Starting instance "orcl"... ORACLE instance started. Database mounted. Continuing to reinstate database "orcl" ... Reinstatement of database "orcl" succeeded
Flashback Database가 활성화 되어 있었다면, reinstate 명령어로 간단하게 복구할 수 있습니다.
SHOW CONFIGURATION; SHOW DATABASE orcl;
DGMGRL> SHOW CONFIGURATION; Configuration - orcl_dg Protection Mode: MaxPerformance Databases: orcl_stb - Primary database orcl - Physical standby database Fast-Start Failover: DISABLED Configuration Status: SUCCESS DGMGRL> SHOW DATABASE orcl; Database - orcl Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 0 seconds ago) Apply Lag: 0 seconds (computed 0 seconds ago) Apply Rate: 0 Byte/s Real Time Query: OFF Instance(s): orcl Database Status: SUCCESS
정상적으로 reinstate가 되었는지 확인합니다.
다시 primary로 전환하려면 switchover를 수행하면 됩니다.
{}