전문가를 위한 오라클 데이터베이스 아키텍처 (2014년)
데이터베이스와 인스턴스 0 0 55,263

by 구루비스터디 데이터베이스 인스턴스 V$ SGA [2018.09.27]


데이터베이스와 인스턴스

오라클은 이식이 매우 편리하도록 설계되었으나 물리 구조는 다름 (윈도우, 유닉스, 메인프레임 등)

플랫폼특성
유닉스멀티 프로세스
윈도우스레드(단일 프로세스)
메인프레임복수의 '주소 공간(address space)', 단일 인스턴스


데이터베이스와 인스턴스

구분정의비고
데이터베이스물리적인 파일/디스크 집합DBF, ASM, RAW
인스턴스프로세스(스레드) + 공유 메모리 영역하나 이상의 인스턴스는 하나의 데이터베이스를 마운트/오픈(RAC)


데이터베이스와 인스턴스 간단한 예제

$ORACLE_HOME/dbs 에 아무것도 없음


$ ls -al
total 8
drwxr-xr-x  2 oracle dba 4096 Sep 25 07:43 .
drwxr-xr-x 78 oracle dba 4096 Dec 10  2013 ..



oracle 사용자 관련 프로세스 없음

$ ps -aef | grep oracle
root     18087 18086  0 07:42 ?        00:00:00 login -- oracle
oracle   18088 18087  0 07:42 pts/1    00:00:00 -bash
oracle   18796 18088  0 07:46 pts/1    00:00:00 ps -aef
oracle   18797 18088  0 07:46 pts/1    00:00:00 grep oracle


oracle 사용자 관련 공유 메모리 없음

$ ipcs -a

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 4718593    root      644        80         2
0x00000000 4751363    root      644        16384      2
0x00000000 4784132    root      644        280        2

------ Semaphore Arrays --------
key        semid      owner      perms      nsems

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages


SQL*Plus 접속 실패 (접속 대상 알 수 없음)

$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Sep 25 07:48:28 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

ERROR:
ORA-12162: TNS:net service name is incorrectly specified

Enter user-name:


SQL*Plus 접속 성공 (idle instance)

$ export ORACLE_SID=ora11g
$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Sep 25 07:51:15 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to an idle instance.

SQL>


상태 점검 (오라클 서버 프로세스만 기동 됨, 공유 메모리 없음)


SQL> !ps -aef | grep oracle
root     18087 18086  0 07:42 ?        00:00:00 login -- oracle
oracle   18088 18087  0 07:42 pts/1    00:00:00 -bash
oracle   18812 18088  0 07:51 pts/1    00:00:00 sqlplus   as sysdba
oracle   18813 18812  0 07:51 ?        00:00:00 oracleora11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle   18816 18812  0 07:52 pts/1    00:00:00 /bin/bash -c ps -aef | grep oracle
oracle   18817 18816  0 07:52 pts/1    00:00:00 ps -aef
oracle   18818 18816  0 07:52 pts/1    00:00:00 grep oracle

SQL> !ipcs -a

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 4718593    root      644        80         2
0x00000000 4751363    root      644        16384      2
0x00000000 4784132    root      644        280        2

------ Semaphore Arrays --------
key        semid      owner      perms      nsems

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

-- 프로세스 이름은 메모리에 적재할 때 변경 가능, 지금 실행 중인 프로세스 이름은 oraclee$ORACLE_SID 임 (oracleora11g)



기동 실패 (initora11g.ora 파일 없음)

SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/sw/oracle/app/oracle/product/11.2.0/dbs/initora11g.ora'


파라미터 파일 생성 (파라미터 파일은 인스턴스를 기동하기 위해 반드시 필요한 유일한 파일)

$ echo db_name=ora11g > initora11g.ora
$ cat initora11g.ora
db_name=ora11g


기동 성공 (nomount)


$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Sep 25 07:59:46 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  250560512 bytes
Fixed Size		    2227256 bytes
Variable Size		  192938952 bytes
Database Buffers	   50331648 bytes
Redo Buffers		    5062656 bytes
SQL>



상태 점검
  • 구동에 필요한 PMON, LGWR 외 다수 백그라운드 프로세스 기동 됨, 공유 메모리, 세마포어 생성 됨)


SQL> !ps -aef | grep oracle
root     18087 18086  0 07:42 ?        00:00:00 login -- oracle
oracle   18088 18087  0 07:42 pts/1    00:00:00 -bash
oracle   18833 18088  0 07:59 pts/1    00:00:00 sqlplus   as sysdba
oracle   18837     1  0 07:59 ?        00:00:00 ora_pmon_ora11g
oracle   18839     1  0 07:59 ?        00:00:00 ora_psp0_ora11g
...
oracle   18863     1  0 07:59 ?        00:00:00 ora_reco_ora11g
oracle   18865     1  0 07:59 ?        00:00:00 ora_mmon_ora11g
oracle   18867     1  0 07:59 ?        00:00:00 ora_mmnl_ora11g
oracle   18868 18833  0 07:59 ?        00:00:00 oracleora11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle   18884 18833  0 08:02 pts/1    00:00:00 /bin/bash -c ps -aef | grep oracle
oracle   18885 18884  0 08:02 pts/1    00:00:00 ps -aef
oracle   18886 18884  0 08:02 pts/1    00:00:00 grep oracle

SQL> !ipcs -a

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 4718593    root      644        80         2
0x00000000 4751363    root      644        16384      2
0x00000000 4784132    root      644        280        2
0x00000000 5308422    oracle    640        8388608    16
0x00000000 5341191    oracle    640        243269632  16
0x66a46acc 5373960    oracle    640        2097152    16

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x2121606c 262145     oracle    640        204

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages


데이터베이스 마운트 실패 (아직 데이터베이스가 없음)

SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info



Thu Sep 25 08:05:49 2014
alter database mount
Thu Sep 25 08:05:49 2014
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/sw/oracle/app/oracle/product/11.2.0/dbs/cntrlora11g.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Thu Sep 25 08:05:49 2014
Checker run found 1 new persistent data failures
ORA-205 signalled during: alter database mount...


데이터베이스 생성 (실전은 파일 경로 등 더 많은 정보를 정의 해야 함)

SQL> create database;

Database created.



Thu Sep 25 08:07:09 2014
create database
WARNING: Default Temporary Tablespace not specified in CREATE DATABASE command
Default Temporary Tablespace will be necessary for a locally managed database in future release
Database mounted in Exclusive Mode
Lost write protection disabled
Thu Sep 25 08:07:13 2014
Successful mount of redo thread 1, with mount id 4255433965
Using SCN growth rate of 16384 per second
Assigning activation ID 4255433965 (0xfda4c4ed)
Thread 1 opened at log sequence 1
  Current log# 1 seq# 1 mem# 0: /sw/oracle/app/oracle/product/11.2.0/dbs/log1ora11g.dbf
Successful open of redo thread 1
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Thu Sep 25 08:07:13 2014
SMON: enabling cache recovery
processing ?/rdbms/admin/dcore.bsq
create tablespace SYSTEM datafile '?/dbs/dbs1@.dbf' SIZE 81920000 REUSE AUTOEXTEND ON
  default storage (initial 10K next 10K) EXTENT MANAGEMENT DICTIONARY online
Completed: create tablespace SYSTEM datafile '?/dbs/dbs1@.dbf' SIZE 81920000 REUSE AUTOEXTEND ON
  default storage (initial 10K next 10K) EXTENT MANAGEMENT DICTIONARY online
create rollback segment SYSTEM tablespace SYSTEM
  storage (initial 50K next 50K)
UNDO_SEG_CRT: Could not find usn tail
Completed: create rollback segment SYSTEM tablespace SYSTEM
  storage (initial 50K next 50K)
Undo initialization finished serial:0 start:3303269434 end:3303269464 diff:30 (0 seconds)
processing ?/rdbms/admin/dsqlddl.bsq
processing ?/rdbms/admin/dmanage.bsq
CREATE TABLESPACE sysaux DATAFILE '?/dbs/dbx1@.dbf' SIZE 40960000 REUSE AUTOEXTEND ON
  EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ONLINE
Completed: CREATE TABLESPACE sysaux DATAFILE '?/dbs/dbx1@.dbf' SIZE 40960000 REUSE AUTOEXTEND ON
  EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ONLINE
processing ?/rdbms/admin/dplsql.bsq
processing ?/rdbms/admin/dtxnspc.bsq
CREATE UNDO TABLESPACE SYS_UNDOTS DATAFILE '?/dbs/dbu1@.dbf' SIZE 10M REUSE AUTOEXTEND ON
[18868] Successfully onlined Undo Tablespace 2.
Completed: CREATE UNDO TABLESPACE SYS_UNDOTS DATAFILE '?/dbs/dbu1@.dbf' SIZE 10M REUSE AUTOEXTEND ON
ALTER DATABASE DEFAULT TABLESPACE SYSTEM
Completed: ALTER DATABASE DEFAULT TABLESPACE SYSTEM
processing ?/rdbms/admin/dfmap.bsq
processing ?/rdbms/admin/denv.bsq
processing ?/rdbms/admin/drac.bsq
processing ?/rdbms/admin/dsec.bsq
Thu Sep 25 08:07:19 2014
processing ?/rdbms/admin/doptim.bsq
processing ?/rdbms/admin/dobj.bsq
processing ?/rdbms/admin/djava.bsq
processing ?/rdbms/admin/dpart.bsq
processing ?/rdbms/admin/drep.bsq
processing ?/rdbms/admin/daw.bsq
processing ?/rdbms/admin/dsummgt.bsq
processing ?/rdbms/admin/dtools.bsq
processing ?/rdbms/admin/dexttab.bsq
processing ?/rdbms/admin/ddm.bsq
processing ?/rdbms/admin/dlmnr.bsq
processing ?/rdbms/admin/ddst.bsq
SMON: enabling tx recovery
Starting background process SMCO
Thu Sep 25 08:07:23 2014
SMCO started with pid=18, OS id=18952
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Thu Sep 25 08:07:25 2014
QMNC started with pid=19, OS id=18954
Completed: create database



V$뷰 조회


SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/sw/oracle/app/oracle/product/11.2.0/dbs/dbs1ora11g.dbf
/sw/oracle/app/oracle/product/11.2.0/dbs/dbx1ora11g.dbf
/sw/oracle/app/oracle/product/11.2.0/dbs/dbu1ora11g.dbf

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/sw/oracle/app/oracle/product/11.2.0/dbs/log1ora11g.dbf
/sw/oracle/app/oracle/product/11.2.0/dbs/log2ora11g.dbf

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/sw/oracle/app/oracle/product/11.2.0/dbs/cntrlora11g.dbf


SQL> select status from v$instance;

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



데이터베이스 닫고 열기
  • 실패, 인스턴스 구동 중 하나의 데이터베이스만을 마운트하고 오픈할 수 있음

SQL> alter database close;

Database altered.

SQL> select status from v$instance;

STATUS
------------------------
MOUNTED

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-16196: database has been previously opened and closed



16196, 00000, "database has been previously opened and closed"
// *Cause:  The instance has already opened and closed the database,
//          which is allowed only once in its lifetime.
// *Action: Shut down the instance.




Thu Sep 25 08:13:28 2014
alter database close
Warning: ALTER DATABASE CLOSE is not a publicly supported command.
Thu Sep 25 08:13:28 2014
SMON: disabling tx recovery
Stopping background process QMNC
CLOSE: killing server sessions.
CLOSE: all sessions shutdown successfully.
Stopping background process SMCO
SMON: disabling cache recovery
Thu Sep 25 08:13:30 2014
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
Thread 1 closed at log sequence 1
Successful close of redo thread 1
Completed: alter database close
Thu Sep 25 08:14:17 2014
alter database open
ORA-16196 signalled during: alter database open...


데이터베이스와 인스턴스 정리

  • 하나의 인스턴스는 백그라운드 프로세스와 공유 메모리의 합집합
  • 데이터베이스는 디스크에 저장된 데이터의 집합
  • 인스턴스는 오직 하나의 데이터베이스만 마운트/오픈 가능
  • 하나의 데이터베이스를 하나 혹은 여러(RAC) 인스턴스 에서 마운트/오픈 가능


SGA와 백그라운드 프로세스


SGA 특징
  • 모든 프로세스가 액세스하기 위해 필요한 다수의 내부 데이터 구조를 갖는다
  • 디스크에서 데이터를 읽어 캐시, 디스크에 쓰기 전 리두 데이터 버퍼 등을 담는다
  • 파싱된 SQL의 실행계획 저장 등
  • 오라클은 SGA에 덧붙여진 프로세스들의 집함


백그라운드 프로세스 특징
  • 인스턴스를 구성하고 인스턴스 시작 부터 종료 까지 존재 함
  • 단 하나의 오라클 바이너리 실행 파일(oracle)이 다른 이름으로 여러번 실행 됨 (ora_pmon_ora11g, ora_ckpt_ora11g...)
  • 오라클은 데이터베이스 프로세스(스레드)가 읽고 쓰는 파일 집합을 가짐 (DBF, REDO 등...)


유닉스
  • 운영체제가 할당한 공유 메모리에 오라클 프로세스들이 붙어 있음



윈도우
  • 하나의 프로세스의 가상 메모리 공간을 스레드가 공유


|


윈도우 프로세스(스레드) 정보


-- wmic process list
Handle  HandleCount  KernelModeTime   MaximumWorkingSetSize  MinimumWorkingSetSize  Name                 OtherOperationCount  OtherTransferCount  PageFaults  PageFileUsage  ParentProcessId  PeakPageFileUsage  PeakVirtualSize  PeakWorkingSetSize  Priority  PrivatePageCount  ProcessId  QuotaNonPagedPoolUsage  QuotaPagedPoolUsage  QuotaPeakNonPagedPoolUsage  QuotaPeakPagedPoolUsage  ReadOperationCount  ReadTransferCount  SessionId  Status  TerminationDate  ThreadCount  UserModeTime  VirtualSize  WindowsVersion  WorkingSetSize  WriteOperationCount  WriteTransferCount
0       0            128570914231244                                                System Idle Process  0                    0                   1           0              0                0                  0                24                  0         0                 0          0                       0                    0                           0                        0                   0                  0                                   2            0             0            6.1.7601        24576           0                    0
4       597          12000064923                                                    System               6900200              107705434           215792      112            0                332                8654848          5372                8         114688            4          0                       0                    0                           0                        14778               129966972          0                                   98           0             3526656      6.1.7601        376832          501514               2249406070
240     33           1560010          1380                   200                    smss.exe             656                  14634               602         460            4                492                19423232         1140                11        471040            240        2                       11                   7                           38                       815                 2778171            0                                   3            0             5758976      6.1.7601        1146880         5                    20

...

3164    82           8424054          1380                   200                    conhost.exe          137                  246                 2255        5016           2984             5016               85270528         8568                8         5136384           3164       9                       155                  9                           156                      20                  649                2                                   5            624004        85266432     6.1.7601        8773632         0                    0
4000    24           468003           1380                   200                    cmd.exe              820                  11650               834         2020           1744             3024               44191744         3128                8         2068480           4000       5                       84                   5                           85                       424                 931184             2                                   1            156001        43143168     6.1.7601        3203072         0                    0
3024    83           4368028          1380                   200                    conhost.exe          173                  8810                2000        2188           2984             2188               82198528         7524                8         2240512           3024       9                       155                  9                           156                      1114                1501338            2                                   5            1248008       82186240     6.1.7601        7696384         0                    0
3360    86           1248008          1380                   200                    notepad.exe          213                  8580                2230        1864           1744             2068               82993152         8388                8         1908736           3360       9                       150                  9                           156                      1071                1963568            2                                   2            624004        79458304     6.1.7601        8552448         0                    0
2028    88           1872012          1380                   200                    notepad.exe          186                  716                 2313        1976           1744             2152               100831232        8612                8         2023424           2028       9                       189                  9                           191                      18                  12014              2                                   2            624004        99733504     6.1.7601        8744960         0                    0
468     91           780005           1380                   200                    notepad.exe          196                  572                 2351        2172           1744             2172               100782080        8768                8         2224128           468        9                       189                  9                           191                      1                   60                 2                                   4            468003        100782080    6.1.7601        8962048         0                    0
3504    124          1560010          1380                   200                    WmiPrvSE.exe         2052                 4532                4203        3548           592              3788               41172992         7260                8         3633152           3504       11                      69                   11                          71                       499                 697121             0                                   7            468003        40615936     6.1.7601        7389184         0                    0
1428    142          156001           1380                   200                    WMIC.exe             306                  3760                2398        3532           4000             3536               85581824         8776                8         3616768           1428       13                      147                  13                          147                      431                 1075816            2                                   5            312002        85434368     6.1.7601        8986624         0                    0

-- Get-WmiObject win32_thread -Filter "ProcessHandle=3284"
-- (첨부파일:thread.txt)

"데이터베이스 스터디모임" 에서 2014년에 "전문가를 위한 오라클 데이터베이스 아키텍처 " 도서를 스터디하면서 정리한 내용 입니다.

- 강좌 URL : http://www.gurubee.net/lecture/3993

- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^

- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입