๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
ORACLE/ADMIN

[Oracle] SGA Shared Pool ๊ณต์œ ํ’€ ์‚ฌ์šฉ ์›๋ฆฌ :: ๋งˆ์ด์ž๋ชฝ

by ๐ŸŒปโ™š 2020. 3. 31.

Shared Pool

Library Cache : parsing๋œ ์ •๋ณด๋ฅผ ์ €์žฅ
Data Dictionary Cache : Data Dictionary์˜ ์ •๋ณด๋ฅผ ์ €์žฅ --> Hard Parse ์ž‘์—…์„ ๋นจ๋ฆฌ ํ•ด์ฃผ๊ธฐ ์œ„ํ•ด
Result Cache : ์‹คํ–‰๋œ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅ (11g new feature) --> ๊ฒฐ๊ณผ๋กœ ์ ์€ ๋‚ด์šฉ์„ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ๊ฐ’์„ ์ €์žฅํ•ด๋‘๋ฉด ๋ฐ”๋กœ ์ฝ์„ ์ˆ˜ ์žˆ๋‹ค.

Shared Pool์€ Libray Cache, Data Dictionary Cache, Server Result Cache 3๊ฐ€์ง€ ๊ตฌ์„ฑ์š”์†Œ๋ฅผ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋™์ผํ•œ ๋ฌธ์žฅ์ด ๋ฐ˜๋ณต์ ์œผ๋กœ ๋“ค์–ด์™”์„ ๋•Œ Parse ์ž‘์—…์„ ํ•˜์ง€ ์•Š๊ณ  ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ณต์œ ์˜ ๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ์šฐ๋ฆฌ๊ฐ€ ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” SELECT๋ฌธ ์š”์ฒญ์ด ๋“ค์–ด์™”์„๋•Œ Shared Pool์—์„œ ์–ด๋–ค ์ž‘์—…์ด ์ด๋ฃจ์–ด์ง€๋Š”์ง€ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

 

Select Process

SELECT SAL FROM EMP WHERE EMPNO = 7499;

์œ„์˜ ์ฟผ๋ฆฌ๊ฐ€ User Process์—์„œ ์š”์ฒญํ•˜์—ฌ Listenser๋ฅผ ํ†ตํ•ด Connection๊นŒ์ง€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด, Server Process๊ฐ€ ํ•ด๋‹น SELECT๋ฌธ์„ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ๊นŒ์ง€ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๊นŒ์ง€ Parse - Execute - Fetch ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์นฉ๋‹ˆ๋‹ค. Shared Pool์€ Parse ๋‹จ๊ณ„์—์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

 

 

Parse

Parse ๋‹จ๊ณ„๋Š” Compileํ•˜๋Š” ๋‹จ๊ณ„๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.  ๋“ค์–ด์˜จ Query๋ฌธ์— ๋Œ€ํ•ด์„œ ๋ช‡๊ฐ€์ง€ ํ™•์ธ์„ ํ•˜๊ณ  ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ค€๋น„๋ฅผ ํ•˜๋Š” ๋‹จ๊ณ„์ž…๋‹ˆ๋‹ค.

 

 

์šฐ์„  Query์˜ ๋ฌธ๋ฒ•์— ์ด์ƒ์ด ์—†๋‚˜ ํ™•์ธํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

 

 

 

๋‹ค์Œ์€ Semantic Check ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค. Query๋ฌธ ๋‚ด์˜ ํ…Œ์ด๋ธ”๊ณผ ์ปฌ๋Ÿผ์€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์กด์žฌํ•˜๋Š”์ง€, ํ…Œ์ด๋ธ”์„ ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์€ ์žˆ๋Š”์ง€, ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

Query ๋ฌธ๋ฒ•์—๋„ ์ด์ƒ์ด ์—†๊ณ , ๊ฐ์ฒด์˜ ์œ ํšจ์„ฑ์ด๋‚˜ ๊ถŒํ•œ์—๋„ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋Š” ์‹คํ–‰๊ณ„ํš์„ ์„ ์ •ํ•˜๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค. Full Scan์„ ํ†ตํ•ด์„œ ๊ฒ€์ƒ‰ํ• ๊ฑด์ง€, Index๋ฅผ ์ด์šฉํ•œ ๊ฒ€์ƒ‰์„ ํ• ๊ฑด์ง€ ์—ฌ๋Ÿฌ ์š”์†Œ๋“ค์„ COST๋กœ ์‚ฐ์ •ํ•˜์—ฌ ๊ฐ€์žฅ ๋‚ฎ์€ COST๋ฅผ ๊ฐ–๋Š” ์‹คํ–‰๊ณ„ํš์„ ์„ ์ •ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

์‹คํ–‰ ๊ณ„ํš๊นŒ์ง€ ์‚ฐ์ •์ด ์™„๋ฃŒ๋˜๋ฉด ๋“ค์–ด์˜จ SQL๋ฌธ, ์„ ์ •๋œ ์‹คํ–‰ ๊ณ„ํš ๊ทธ๋ฆฌ๊ณ  P-Code๋ผ๋Š” ๊ฒƒ์„ Shared SQL Area ๊ณต์œ  SQL ์˜์—ญ์— ์˜ฌ๋ฆฝ๋‹ˆ๋‹ค. ๊ณต์œ  SQL ์˜์—ญ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฌ๋ฉด Parse ์ž‘์—…์€ ๋์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ƒ๊ฐํ•ด๋ณด๋ฉด, ์ด Parsing ์ž‘์—…์ด ๋งค๋ฒˆ Query๊ฐ€ ๋“ค์–ด์™”์„ ๋•Œ ํ•ด์ค˜์•ผํ• ๊นŒ์š”? ๊ทธ๋ ‡๋‹ค๋ฉด ๊ณต์œ ์˜ ์˜๋ฏธ๊ฐ€ ์—†๊ฒ ์ฃ ? ๊ทธ๋ž˜์„œ ์‚ฌ์‹ค์€ Parse ์ž‘์—…์„ ํ• ๋•Œ Shared Pool์— ๋“ค๋ ค์„œ ํ™•์ธ์ž‘์—…์„ ํ•ด์ค๋‹ˆ๋‹ค.

 

 

 

Shared Pool Select Process

Shared Pool์ด ์ค‘๊ฐ„์— ๊ฑฐ์น˜๋Š” Select Process์ž…๋‹ˆ๋‹ค.

Parse ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์น˜๊ธฐ ์ „์— Shared Pool์„ ํ•œ๋ฒˆ ๋“ค๋ฆฝ๋‹ˆ๋‹ค. ๋“ค์–ด์˜จ Query์— ๋Œ€ํ•ด์„œ Shared Pool ๊ณต์œ  SQL ์˜์—ญ์— ๋“ค์–ด์˜จ ๋‚ด์—ญ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์กด์žฌํ•œ๋‹ค๋ฉด Parse ์ž‘์—…์„ ๊ฑด๋„ˆ ๋›ฐ๊ณ  ๋ฐ”๋กœ Execute๋กœ ๋„˜์–ด๊ฐ€๊ณ  ์—†๋‹ค๋ฉด Parse ์ž‘์—…์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋‘๊ฐ€์ง€ ์ƒํ™ฉ์— ๋Œ€ํ•ด์„œ Hard Parse, Soft Parse๋ผ๊ณ  ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

 

Hard Parse : Parse ์ž‘์—…์„ ํ•จ
Soft Parse :  Parse ์ž‘์—…์„ ๊ฑด๋„ˆ๋›ฐ๊ณ  Execute๋กœ ๋„˜์–ด๊ฐ

 

 

 

Library Cache ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ

๊ณ„์† ์‚ฌ์šฉํ•˜๋‹ค ๋ณด๋ฉด ์–ธ์  ๊ฐ€๋Š” ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•˜๊ฒŒ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ ๊ณต์œ  SQL ์˜์—ญ์ด ๋“ค์–ด์žˆ๋Š” Library Cache๋Š” ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ๋ฅผ ์–ด๋–ป๊ฒŒ ํ• ๊นŒ์š”? ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด์™”์„๋•Œ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์ด ๋ถ€์กฑํ•˜๋ฉด LRU(Least Recently Used) ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์žฅ ์˜ค๋žซ๋™์•ˆ ์‚ฌ์šฉ๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ๋ถ€ํ„ฐ ์‚ญ์ œํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฝ๋‹ˆ๋‹ค.

 

 

 Shared Pool ๋ฉ”๋ชจ๋ฆฌ ํ™•์ธ

1
show parameter shared_pool_size

๊ฒฐ๊ณผ๋กœ 0์ด ๋‚˜์˜ค๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿด๋•Œ๋Š” ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ์šฉ๋Ÿ‰์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

 

1
show parameter sga_target

10g์˜ new feature๋กœ ์ž๋™ ๊ณต์œ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

ASMM(Automatic Shared Memory Management) ๋™์ ์œผ๋กœ SGA ๊ตฌ์„ฑ์š”์— ๋Œ€ํ•œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

Database Buffer Cache Execute ์ฐธ์กฐ ๊ธ€

 

[Oracle] SGA Database Buffer Cache DBC ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฒ„ํผ ์บ์‹œ ์‚ฌ์šฉ์›๋ฆฌ :: ๋งˆ์ด์ž๋ชฝ

SGA Shared Pool ๊ด€๋ จ ๋งํฌ [Oracle] SGA Shared Pool ๊ณต์œ ํ’€ ์‚ฌ์šฉ ์›๋ฆฌ :: ๋งˆ์ด์ž๋ชฝ Shared Pool Library Cache : parsing๋œ ์ •๋ณด๋ฅผ ์ €์žฅ Data Dictionary Cache : Data Dictionary์˜ ์ •๋ณด๋ฅผ ์ €์žฅ --> Hard Parse..

myjamong.tistory.com

 

 

๋Œ“๊ธ€