Oracle Update Statement- To understand what is happening internally

We asume that we update or select data from one table in oracle database. We just type some sql and see data on our screen. But what is happening internally?

Here is the answer:

SQL>select * from emp;
SQL>update emp set sallary=30000 where empid=10;
SQL>commit;

So Let us see, what is happening internally.. Here is the steps

1. Once we hit sqlplus statement as above client process(user) access sqlnet listener.

2. Sqlnet listener confirms that DB is open for business & create server process.

3. Server process allocates PGA.

4. ‘Connected’ Message returned to user.

5. User run:
SQL>select * from emp;

6. Server process checks the SGA to see if data is already in buffer cache.

7. If not then data is retrived from disk and copied into SGA (DB Cache).

8. Data is returned to user via PGA & server process.

9. Now another statement is:
SQL>Update emp set sallary=30000 where empid=10;

10. Server process (Via PGA) checks SGA to see if data is already there in buffer cache.

11. In our situation chances are the data is still in the SGA (DB Cache).

12. Data updated in DB cache and mark as ‘Dirty Buffer’.

13. Update employee placed into redo buffer and undo segments

14. Row updated message returned to user

15. Now the next steps is :
SQL>commit;

16. Newest SCN obtained from control file.

17. Data in DB cache is marked as ‘Updated and ready for saving’.

18. commit palced into redo buffer.

19. LGWR writes redo buffer contents to redo log files & remove from redo buffer.

20. Control file is updated with new SCN.

21. Commit complete message return to user.

22. Update emp table in datafile & update header of datafile with latest SCN.

23. SQL>exit;

24. Unsaved changes are rolled back.

25. Server process deallocates PGA.

26. Server process terminates.

27. After some period of time redo log are archived by ARCH process.

Advertisements