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

[Oracle] Rollfoward & Rollback ์„œ๋ฒ„๊ฐ€ ๋น„์ •์ƒ์ ์œผ๋กœ ์ฃฝ์—ˆ์„ ๋•Œ, Checkpoint ํšŒ๋ณต

by ๐ŸŒปโ™š 2020. 4. 4.

Oracle startup

Oracle ์„œ๋ฒ„๋ฅผ ๊ธฐ๋™ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋•Œ ์ˆœ์„œ๋Œ€๋กœ instance started - database mounted - database opened ์ˆœ์„œ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

instance started
Oracle Instance์ธ SGA ๊ณต์œ  ๋ฉ”๋ชจ๋ฆฌ์™€ Background Process๋“ค์„ ๊ธฐ๋™ํ•ฉ๋‹ˆ๋‹ค.

database mounted
Control File์„ ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ์ƒํƒœ๊ฐ€ mounted ์ž…๋‹ˆ๋‹ค.
์ด ๋‹จ๊ณ„์—์„œ ๋งŒ์•ฝ ์ „์— ์ •์ƒ์ ์œผ๋กœ ๋‚ด๋ ค๊ฐ€์ง€ ์•Š์•˜๋‹ค๋ฉด SMON Background Process๊ฐ€ Instance Recovery ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค.
Instance Recovery ์ž‘์—…์œผ๋กœ Rollfoward์™€ Rollback ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค.

database opened
๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์—ด์–ด์ค๋‹ˆ๋‹ค.
๋งŒ์•ฝ Instance Recovery ์ž‘์—…์„ ํ•˜๊ณ  ์žˆ๋‹ค๋ฉด, Rollfoward ์ž‘์—…๋งŒ ๋๋‚˜๋ฉด ๋ฐ”๋กœ openํ•ฉ๋‹ˆ๋‹ค. 

๋น„์ •์ƒ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ์„œ๋ฒ„๊ฐ€ ๋‚ด๋ ค๊ฐ”์„๋•Œ Instance Recovery ๋‹จ๊ณ„๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

 

Inconsistent Data

์‚ฌ์šฉ์ž๊ฐ€ Commit์„ ํ•ด๋„ DB File์— ๋ฐ˜์˜์ด ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ์™€ Commit์„ ์•ˆํ–ˆ๋Š”๋ฐ๋„ DB File์— ๋ฐ˜์˜๋˜๋Š” ๊ฒฝ์šฐ ๋‘๊ฐ€์ง€ ์ด์œ ๋กœ ๋ฐ์ดํ„ฐ์˜ ์ผ๊ด€์„ฑ์ด ๊นจ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 1๋ฒˆ์˜ ๊ฒฝ์šฐ DB File์— ๋ฐ˜์˜ํ•˜๋Š” ๊ณผ์ •์—์„œ ์ค‘๊ฐ„์— ์„œ๋ฒ„๊ฐ€ ๋‚ด๋ ค๊ฐ€๋ฉด ์ถฉ๋ถ„ํžˆ ๋ฐœ์ƒํ• ์ˆ˜๋„ ์žˆ๋Š” ์ƒํ™ฉ์ด๋ผ๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ 2๋ฒˆ์˜ ๊ฒฝ์šฐ ์–ด๋–ค ์ƒํ™ฉ์—์„œ ์ด๋Ÿฐ ๊ฒฝ์šฐ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”์ง€ ๊ฐ์ด ์ž˜ ์•ˆ ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋จผ์ € DBC์—์„œ DB File๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜์˜ํ•ด์ฃผ๋Š” DBW(DB Writer)๊ฐ€ ์ผ์„ ํ•˜๋Š” ์‹œ์ ๊ณผ LGWR(Log Writer)๊ฐ€ Redo Log Buffer๋กœ ๋ถ€ํ„ฐ ๋กœ๊ทธ๋ฅผ ๊ธฐ๋กํ•˜๋Š” ์‹œ์ ์„ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

DBW ์ผํ•˜๋Š” ์‹œ์ 

1. Free Buffer๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด LRU List๋ฅผ ์ž„๊ณ„๊ธธ์ด ๋งŒํผ ์ฐพ์•˜์„ ๋•Œ

2. Dirty List๊ฐ€ ์ž„๊ณ„๊ธธ์ด๋งŒํผ ๋Š˜์–ด๋‚ฌ์„ ๋•Œ

3. timeout 3์ดˆ ๋งˆ๋‹ค

4. Checkpoint Event ๋ฐœ์ƒ

 

LGWR ์ผํ•˜๋Š” ์‹œ์ 

1. Commit

2. ์ „์ฒด ์šฉ๋Ÿ‰์˜ 1/3 ์ฐผ์„ ๋•Œ

3. 1MB ์šฉ๋Ÿ‰ ์ฐผ์„ ๋•Œ

4. DBW๊ฐ€ ์ผ ์‹œ์ž‘ํ•˜๊ธฐ ์ „์— ์‹ ํ˜ธ๋ฅผ ์คฌ์„ ๋•Œ

 

 

์‚ฌ์šฉ์ž๊ฐ€ Commit์„ ํ•˜๋ฉด ๋ฐ”๋กœ ๋ฐ์ดํ„ฐ๋ฅผ DB File์— ์ €์žฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. Commit ํ–ˆ์„ ๋•Œ๋Š” Redo Log์— ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ๊ธฐ๋กํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ Commitํ•˜์ง€ ์•Š์€ ๋‚ด์šฉ๋„ DB File์— ๋“ค์–ด๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋ž˜์„œ ์ด๋Ÿฐ Instance Recovery ์ž‘์—…์„ ํ• ๋•Œ Checkpoint์™€ Undo Block์„ ์ด์šฉํ•ด์„œ RollFoward์™€ Rollback๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

Rollfoward

Commit ๋˜์—ˆ๋Š”๋ฐ DB File์—๋Š” ๋ฐ˜์˜๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ๋Š” Rollfoward ์ž‘์—…์„ ํ†ตํ•ด ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Rollfoward๋Š” ๋งˆ์ง€๋ง‰ Checkpoint๊ฐ€ ๋ฐœ์ƒํ•œ ์‹œ์ ์—์„œ ๋ถ€ํ„ฐ redo log์— ๊ธฐ๋ก๋œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋‹ค์‹œ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ ์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ Commitํ–ˆ์„ ๋•Œ ๊ฐ€์žฅ ๋จผ์ € ์‹คํ–‰๋˜๋Š” ์ž‘์—…์€ Redo Log์— ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ์ €์žฅํ•˜๋Š” ๊ฒƒ ์ด๋ผ๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๋น„์ •์ƒ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ์„œ๋ฒ„๊ฐ€ ๋‚ด๋ ค๊ฐ”๋‹ค๋ฉด Redo Log์˜ ๋‚ด์šฉ์„ ๋‹ค์‹œ ์ ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ€ ์›ํ•˜๋Š” Commit๋‚ด์šฉ์„ ๋ณต๊ตฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

Rollback

Commitํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ DB File์— ๋ฐ˜์˜๋œ ๋‚ด์šฉ์€ Rollback์„ ํ†ตํ•ด ๋‚ด์šฉ์„ ๋ณต๊ตฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

Database open

์„œ๋ฒ„ ๊ธฐ๋™์„ ํ–ˆ์„ ๋•Œ ๋งˆ์ง€๋ง‰์œผ๋กœ Database open ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ๋งŒ์•ฝ Database mount ๋‹จ๊ณ„์—์„œ Instance Recovery ์‹œ๊ฐ„์€ ๋งˆ์ง€๋ง‰ checkpoint๋กœ๋ถ€ํ„ฐ ์ ์šฉํ•ด์•ผํ•  redo์˜ ์ž‘์—…๋Ÿ‰์— ๋”ฐ๋ผ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์ด ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

 

Database open ์ž‘์—…์€ Rollfoward์ด ๋๋‚˜๋ฉด ๋ฐ”๋กœ ์—ฝ๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” ๊ฐ€์šฉ์„ฑ์„ ๋งค์šฐ ์ค‘์‹œํ•˜๊ธฐ ๋•Œ๋ฌธ์— 1๋ถ„์ด๋ผ๋„ ๋นจ๋ฆฌ ๊ธฐ๋™์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ ์ด๋ ‡๊ฒŒ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

Rollback์— ๋Œ€ํ•œ ์ž‘์—…์€ ๊ณ„์† ์ง„ํ–‰๋˜๋Š”๋ฐ, ๋งŒ์•ฝ Rollback๋˜์ง€ ์ด๊ฑด์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์ ‘๊ทผํ•˜๋ ค๊ณ ํ•˜๋ฉด, ๊ทธ๋•Œ Rollback ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค.

 

๋Œ“๊ธ€