Chap 5. Control File 관리하기

 

- Control file 은 데이터베이스 전체의 정보를 지니고 있는 Oracle server Instance 를 open 할 때 두번 째 단계인 mount 단계로 가기 위해서 필요한 파일이다.(Instance open 순서: nomount -> mount -> open) 

- Binary file 이라서 사용자가 직접 수정할 수 없고, Server process 에게 변경을 요구하는 SQL 문장이나 DDL 문장을 수행해서 변경 할 수 있다. 


 1. Control file 다중화 하기   

 

1) spfile 일 경우

- 현재 운영중인 control file 의 경로를 확인 한 후, /home/oracle/disk[1-3]/control0[1-3].ctl 이렇게 3개의 파일로 다중화를 해보겠다. 

 

step1) 현재 상태 확인

SYS> select status from v$instance; 

 

STATUS
------------
OPEN 

 

SYS>  show parameter spfile;  

 

NAME                     TYPE    VALUE
------------------------------------ ----------- ------------------------------
spfile                   string  /app/oracle/product/11g/dbs/spfiletestdb.ora

step2) 현재 control file 조회하기

SYS> select name from v$controlfile;

 

NAME
------------------------------------------------------------

/app/oracle/oradata/testdb/control01.ctl

/app/oracle/fast_recovery_area/testdb/control02.ctl

step3) spfile 내용 변경 후 instance 종료

SYS> alter system set control_files='/home/oracle/disk1/control01.ctl', '/home/oracle/disk2/control02.ctl', '/home/oracle/disk3/control03.ctl' scope=spfile;

 

System altered.  

 

SYS> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS>

 

step4) 대상 디렉토리 생성 후 파일 복사

SYS> !
[oracle@my ~]$ cd /home/oracle
[oracle@my ~]$ mkdir disk1 disk2 disk3
[oracle@my ~]$ cp /app/oracle/oradata/testdb/control01.ctl /home/oracle/disk1/control01.ctl
[oracle@my ~]$ cp /app/oracle/oradata/testdb/control01.ctl /home/oracle/disk2/control02.ctl
[oracle@my ~]$ cp /app/oracle/oradata/testdb/control01.ctl /home/oracle/disk3/control03.ctl
[oracle@my ~]$ exit
exit

step5) startup

SYS> startup
ORACLE instance started.  

 

Total System Global Area  422670336 bytes
Fixed Size          1344616 bytes
Variable Size         260049816 bytes
Database Buffers      155189248 bytes
Redo Buffers            6086656 bytes
Database mounted.
Database opened.
SYS> 
SYS> select name from v$controlfile; 

 

NAME
------------------------------------------------------------

/home/oracle/disk1/control01.ctl
/home/oracle/disk2/control02.ctl
/home/oracle/disk3/control03.ctl

2) pfile 일 경우

- 우선 현재 pfile 로 설정이 되어 있지 않을 경우 (show parameter pfile 로 조회 했을 때 value 에 값이 나오는 경우), pfile 을 생성 한 후 spfile 을 삭제하고 instance 를 재시작 한 후 다중화 해보겠다. 그리고 새로운 디렉토리를 disk[4-6] 으로 변경해 보겠다. 

- 아래는 pfile 로의 변경 작업이다.

 

SYS> !ls -l $ORACLE_HOME/dbs/
total 24
-rw-rw---- 1 oracle oinstall 1544 Aug 19 19:47 hc_DBUA0.dat
-rw-rw---- 1 oracle oinstall 1544 Aug 19 20:39 hc_testdb.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15  2009 init.ora
-rw-r----- 1 oracle oinstall   24 Aug 19 19:51 lkTESTDB
-rw-r----- 1 oracle oinstall 1536 Aug 19 19:54 orapwtestdb
-rw-r----- 1 oracle oinstall 2560 Aug 19 20:39 spfiletestdb.ora  

 

SYS> create pfile from spfile;  

 

File created. 

 

SYS> !ls -l $ORACLE_HOME/dbs/
total 28
-rw-rw---- 1 oracle oinstall 1544 Aug 19 19:47 hc_DBUA0.dat
-rw-rw---- 1 oracle oinstall 1544 Aug 19 20:39 hc_testdb.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15  2009 init.ora
-rw-r--r-- 1 oracle oinstall  913 Aug 19 20:41 inittestdb.ora
-rw-r----- 1 oracle oinstall   24 Aug 19 19:51 lkTESTDB
-rw-r----- 1 oracle oinstall 1536 Aug 19 19:54 orapwtestdb
-rw-r----- 1 oracle oinstall 2560 Aug 19 20:39 spfiletestdb.ora  

 

SYS> !rm -f $ORACLE_HOME/dbs/spfiletestdb.ora 

 

SYS> !ls -l $ORACLE_HOME/dbs/
total 24
-rw-rw---- 1 oracle oinstall 1544 Aug 19 19:47 hc_DBUA0.dat
-rw-rw---- 1 oracle oinstall 1544 Aug 19 20:39 hc_testdb.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15  2009 init.ora
-rw-r--r-- 1 oracle oinstall  913 Aug 19 20:41 inittestdb.ora
-rw-r----- 1 oracle oinstall   24 Aug 19 19:51 lkTESTDB
-rw-r----- 1 oracle oinstall 1536 Aug 19 19:54 orapwtestdb  

 

SYS> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS> startup
ORACLE instance started.  

 

Total System Global Area  422670336 bytes
Fixed Size          1344616 bytes
Variable Size         260049816 bytes
Database Buffers      155189248 bytes
Redo Buffers            6086656 bytes
Database mounted.
Database opened.
SYS>            
SYS> show parameter pfile;  

NAME                     TYPE    VALUE
------------------------------------ ----------- ------------------------------
spfile                   string
SYS>


 

step1) 현재 사용중인 control file 조회하기

SYS> select name from v$controlfile;

NAME
------------------------------------------------------------
/home/oracle/disk1/control01.ctl
/home/oracle/disk2/control02.ctl
/home/oracle/disk3/control03.ctl

 

step2) instance 종료

SYS> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS>

step3) pfile 에서 control file 의 경로 수정

SYS> !vi $ORACLE_HOME/dbs/inittestdb.ora


*.control_files='/home/oracle/disk4/control01.ctl','/home/oracle/disk5/control02.ctl','/home/oracle/disk6/control03.ctl'

 

step4) 새로운 디렉토리 생성 후 control file 복사

SYS> !
[oracle@my ~]$ cd /home/oracle
[oracle@my ~]$ mkdir disk4 disk5 disk6
[oracle@my ~]$ cp /home/oracle/disk1/control01.ctl /home/oracle/disk4/control01.ctl
[oracle@my ~]$ cp /home/oracle/disk1/control01.ctl /home/oracle/disk5/control02.ctl
[oracle@my ~]$ cp /home/oracle/disk1/control01.ctl /home/oracle/disk6/control03.ctl
[oracle@my ~]$ exit
exit

step5) startup

SYS> startup
ORACLE instance started.  

Total System Global Area  422670336 bytes
Fixed Size          1344616 bytes
Variable Size         260049816 bytes
Database Buffers      155189248 bytes
Redo Buffers            6086656 bytes
Database mounted.
Database opened.
SYS> 
SYS> select name from v$controlfile;

  
NAME
------------------------------------------------------------

/home/oracle/disk4/control01.ctl
/home/oracle/disk5/control02.ctl
/home/oracle/disk6/control03.ctl  

 

SYS>

by 짱구를꼭말려 2013. 9. 9. 20:41

Chap 4. Oracle 시작하기와 종료하기

- Oracle 서버를 시작하는 단계는 Startup -> (Parameter file) -> NoMount -> (Control file) -> Mount -> (Redo log file, Data file) -> Open 


 1. Parameter File   

- 처음 Oracle server 를 Startup 하게 되면, 서버 프로세스가 가장 먼저 이 Parameter file 을 찾아서 읽는다. 


1) pfile (정적 Parameter ) 과  spfile (동적 Parameter )

 

 항목 / 파일

 pfile (정적 Parameter )

spfile (동적 Parameter )

기본 경로

$ORACLE_HOME/dbs

파일 이름 

initSID.ora 

spfileSID.ora 

 내용 변경

관리자 

서버 프로세스 

 파일 형태

 text

binary 


 

- 서버에 spfile 과 pfile 이 동시에 있을 경우는 spfile 내용 만 사용한다. 

- 만약 이 parameter file 이 삭제 될 경우, 원본 pfile 을 $ORACLE_HOME/dbs/initSID.ora 로 복사해서 복구 하면 된다. (원본 경로: $ORACLE_BASE/admin/SID/pfile/init.ora.xxxxxxx)

[oracle@my ~]$ cd $ORACLE_HOME/dbs
[oracle@my dbs]$ cp $ORACLE_BASE/admin/testdb/pfile/init.ora.5262013203842 nittestdb.ora

- 현재 spfile 을 사용하는지, pfile을 사용하는지 조회하는 방법


SQL> show parameter pfile;

   NAME                     TYPE    VALUE
------------------------------------ ----------- ------------------------------
spfile                   string  /app/oracle/product/11g/dbs/spfiletestdb.ora

위와 같이 VALUE 부분이 써져 있으면 SP파일이다.

Value 부분이 비어 있으면 P파일 이다.

 

2) Parameter 변경

- Oracle 9i 부터는 Dynamic SGA 기능으로 재부팅 없이 Parameter 값들을 바로 적용 시킬 수 있다. 아래 문장은 DB Cache size 를 30M 으로 변경하는 명령이다.

SYS> alter system set db_cache_size=30m scope=memory;

- 마지막의 scope 옵션은 3가지가 있다. 

 

 옵션

의미 

 Memory

  Spfile 의 내용은 변경하지 말고 현재 작동중인 instance 에만 적용 

  (재부팅 후 다시 원래의 spfile 의 설정으로 돌아감)

 Spfile

  현재 운영중인 Instance 에는 적용하지 않고 Spfile 의 내용만 변경

  (즉, 재부팅 후에 변경하겠다.)

Both 

  위의 2가지 모두를 적용한다는 의미로, 운영중인 instance 에도 적용하고, 

  재부팅 후에도 적용한다는 의미이다. (Default 값이다.) 

 


 2. Instance Open 하기   

- Oracle 의 시작 단계는 nomont -> mount -> open 으로 3 단계가 있으며, DBA 가 원하는 단계까지만 지정해서 Instance 를 시작할 수 있다. 원하는 단계 후에 나머지 단계를 진행하려면 alter database 라는 명령어를 사용해야 한다.

 

< Nomount 단계 까지만 시작한 후 나머지 단계 진행하기 >
SQL> startup nomount;
ORACLE instance started.

Total System Global Area  422670336 bytes
Fixed Size          1344616 bytes
Variable Size         268438424 bytes
Database Buffers      146800640 bytes
Redo Buffers            6086656 bytes
SQL> 
SQL> alter database mount;
Database altered.
SQL> alter database open;
Database altered.
SQL>   

 

< 읽기 전용인 상태로 open 하기 >

SQL> startup mount;
ORACLE instance started.  

Total System Global Area  422670336 bytes
Fixed Size          1344616 bytes
Variable Size         268438424 bytes
Database Buffers      146800640 bytes
Redo Buffers            6086656 bytes
Database mounted.
SQL> 
SQL> alter database open read only;
Database altered.
SQL>   

< Restricted mode (제한 모드) 로 open 하기 >

SQL> startup restrict;
ORACLE instance started.  

Total System Global Area  422670336 bytes
Fixed Size          1344616 bytes
Variable Size         268438424 bytes
Database Buffers      146800640 bytes
Redo Buffers            6086656 bytes
Database mounted.
Database opened.
SQL>

 

 3. Instance 종료하기    

- shutdown 에는 아래와 같이 4가지 옵션이 있다. 


1) shutdown normal 

- 종료 전에 접속되어 있던 사용자들이 모두 스스로 접속을 종료할 때까지 기다렸다가 종료한다. 


2) shutdown transactional

- 사용자가 수행중인 Transaction 이 끝난 시점 (commit, rollback) 에 강제로 접속을 종료한다. 즉, 사용자가 업데이트를 수행한 후 commit 이나 rollback 을 하지 않으면 Instance 를 종료할 수 없다. 


3) shutdown immediate 

- 사용자의 행동에 상관없이 즉시 접속을 강제 종료 하지만, 종료 되는 시점까지 사용자가 수행한 작업을 모두 처리하고 정상적으로 instance 를 종료한다. 즉, commit 이 완료된 데이터는 data file 로 저장해 주고, commit 이 안된 작업들은 모두 rollback 처리 해준다. 


4) shutdown abort

- 무조건 강제 종료이다. 아무 작업도 하지 않는다. 즉, 비정상 종료, Instance Crash 라고 부른다. 

- 다시 startup 될 때 SMON 이 Instance recovery 를 수행해서 복구 한다.

 

by 짱구를꼭말려 2013. 9. 8. 15:28