You are on page 1of 8

Practice 26 - Tuning the Redo Path P a g e |1

Practice 26

Tuning the Redo Path

Practice Target
In this practice, you will perform the following:
• Demonstrate the impact of undersized redo log files on database performance

• Use redo log file size advisor to determine the optimal redo log file size

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 26 - Tuning the Redo Path P a g e |2

Preparing the Practice Environment


In this section of the practice, you will perform steps to prepare your environment for this practice.

1. In Oracle VirtualBox manager, take a snapshot of srv1.

Caution: Do not proceed with performing the practice without taking snapshot first.

2. Start Putty and connect to srv1 as oracle.

Note:
In the following steps, you will create multiple script files. If you want to save your time and create
all those scripts in one command, find attached the file tune_redo_scripts.txt file. Copy/paste
its contents into the Putty window.

3. Create the following sql script file, named as display_log_members.sql


The script displays the redo log files in ORADB database.

cat > display_log_members.sql <<EOL


col STATUS for a15
col MEMBER for a32
col MB for 999,999

SELECT G.GROUP#, G.ARCHIVED, G.STATUS,


REPLACE(REPLACE(M.MEMBER,'/u01/app/oracle/oradata/ORADB/onlinelog/','DATA_DIR/')
,
'/u01/app/oracle/fra/ORADB/ORADB/onlinelog/','FRA_DIR/') MEMBER,
BYTES/1024/1024 MB
FROM V\$LOG G, V\$LOGFILE M
WHERE G.GROUP#=M.GROUP# order by M.GROUP#, M.MEMBER;
EOL

4. Create the following sql file, named as display_log_history.sql


The script displays the number of redo log switches that happened every hour in the current
date.
cat > display_log_history.sql <<EOL
col HOUR format 99
col SWITCHES format 999
SELECT TO_CHAR(FIRST_TIME,'HH24') HOUR, COUNT(*) SWITCHES
FROM V\$LOG_HISTORY
WHERE TRUNC(FIRST_TIME)=TRUNC(SYSDATE)
GROUP BY TO_CHAR(FIRST_TIME,'HH24')
ORDER BY TO_CHAR(FIRST_TIME,'HH24');
EOL

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 26 - Tuning the Redo Path P a g e |3

5. Create the following shell script file, named as update_orders.sh

The script kicks off a number of SQL*Plus sessions in parallel. The number of SQL*Plus sessions
is to be passed to the script. Each session executes update_orders.sql script.

cat > update_orders.sh <<EOL


#!/bin/bash
counter=1
while [ \$counter -le \$1 ]
do
exit | sqlplus -L -S soe/soe @update_orders.sql \$2 &
((counter++))
done
EOL

chmod +x update_orders.sh

6. Create the following sql file, named as update_orders.sql

The script keeps updating the ORDERS table for N number of seconds. The value of N is to be
passed to the script.
cat > update_orders.sql <<EOL
DECLARE
N NUMBER := &1;
V TIMESTAMP;
X NUMBER ;
SECONDS NUMBER;
BEGIN
DBMS_APPLICATION_INFO.SET_MODULE( MODULE_NAME=> 'CRM', ACTION_NAME=>
'UPDATE_CUST');
V := SYSTIMESTAMP;
SECONDS := 0 ;
WHILE SECONDS < N LOOP
SECONDS := (EXTRACT( MINUTE from SYSTIMESTAMP - V )*60) + EXTRACT( SECOND from
SYSTIMESTAMP - V );
UPDATE ORDERS SET COST_OF_DELIVERY = COST_OF_DELIVERY + 0 WHERE ORDER_ID =
ROUND(DBMS_RANDOM.VALUE(10000,1000000));
COMMIT;
END LOOP;
END;
/
EOL

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 26 - Tuning the Redo Path P a g e |4

Demonstrating Redo Log Size Impact on Database


Performance
In this section of the practice, you will demonstrate the redo log size impact on the database
performance.

7. In the Putty window, invoke SQL*Plus and login to ORADB as sysdba. In the rest of this practice,
this session will be referred to as the admin window.
sqlplus / as sysdba
set sqlprompt "ADMIN> "

8. Display the redo log files.


ORADB has 3 redo log groups with 2 members in each group, each member size is 200 MB.

@ display_log_members.sql

9. Perform the following steps to drop the current redo log files and replace them with 10MB files.
# add three new redo log groups of size 10M each
# Note: the members will automatically be created
ALTER DATABASE ADD LOGFILE GROUP 4 SIZE 10M;
ALTER DATABASE ADD LOGFILE GROUP 5 SIZE 10M;
ALTER DATABASE ADD LOGFILE GROUP 6 SIZE 10M;

# verify the new members have been created:


@ display_log_members.sql

# switch the redo log files three times


ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;

# perform a manual checkpoint so that active groups become inactive


ALTER SYSTEM CHECKPOINT;

# verify that the groups 1,2,and 3 are inactive so that we can drop them
@ display_log_members.sql

# drop the groups 1,2, and 3:


ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 2;
ALTER DATABASE DROP LOGFILE GROUP 3;

# verify that only groups 4,5, and 6 are only available now:
@ display_log_members.sql

10. Start another Putty session and connect to srv1 as oracle. In the rest of this practice, this
session will be referred to as the client window.

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 26 - Tuning the Redo Path P a g e |5

11. In the admin window, run the following code to create two AWR snapshots within 2 minutes.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
JOB_NAME => 'CREATE_2_AWR_SNAPSHOTS',
JOB_TYPE => 'PLSQL_BLOCK',
JOB_ACTION => 'BEGIN DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT(); END;',
START_DATE => SYSDATE,
REPEAT_INTERVAL => 'FREQ=MINUTELY;INTERVAL=2',
END_DATE => SYSDATE + (1/24/60*3),
AUTO_DROP => TRUE,
ENABLED => TRUE);
END;
/

12. In the client window, run the following script. The script kicks off 4 SQL*Plus sessions for 2
minutes. Do not wait for the script to finish its execution. Go to the next step.
./update_orders.sh 4 120

13. In the admin window, run the following script several times to check the redo log switch
frequency:
From the output of the script, we can know that the database is rapidly switching the redo log
files.
As a general rule of thumb, redo log switch should happen once every twenty minutes when the
system is under normal workload.
@ display_log_history.sql

14. Run the following query several times to check on the rate at which the 'redo log space
requests' event is being incremented.
'redo log space requests' event occurs every time the current log group is full and therefore
LGWR is waiting for the log switch to finish to write into the new log group.
SELECT NAME, VALUE FROM V$SYSSTAT WHERE NAME= 'redo log space requests';

15. Wait till the 2 minutes expires.

16. Make sure the two snapshots were created as expected.


col BEGIN_INTERVAL_TIME format A25
col END_INTERVAL_TIME format A25
SELECT SNAP_ID, TO_CHAR(BEGIN_INTERVAL_TIME,'HH24:MI:SS') BEGIN_INTERVAL_TIME,
TO_CHAR(END_INTERVAL_TIME,'HH24:MI:SS') END_INTERVAL_TIME
FROM DBA_HIST_SNAPSHOT
ORDER BY SNAP_ID DESC FETCH FIRST 4 ROWS ONLY;

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 26 - Tuning the Redo Path P a g e |6

17. Generate an AWR report using the last created two snapshots.
Copy the generated report file to the shared folder directory /media/sf_extdisk/

@ ?/rdbms/admin/awrrpt.sql

18. Open the AWR report in your favorite browser. Follow the strategy that you learnt on reading
AWR to troubleshoot the bottleneck.

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 26 - Tuning the Redo Path P a g e |7

Using Redo Log File Size Advisor to Determine the Optimal


Redo Log File Size
In this section of the practice, you will use the Redo Log File Size Advisor to determine the optimal
redo log file size.

19. Set FAST_START_MTTR_TARGET to 3600 seconds.


We need to set a value to this parameter so that the advisor works.

Note: set this parameter to a high value because we concentrate on the database performance
rather than the instance recovery.

ALTER SYSTEM SET FAST_START_MTTR_TARGET =3600 SCOPE=BOTH;

20. Run the following query and observe its output.


We need to set the redo log file size to at least the value reported by the Redo Log File
Size Advisor (V$INSTANCE_RECOVERY.OPTIMAL_LOGFILE_SIZE).
Note: If the 'Effective MTTR Target' is zero, run the update_orders.sh again at the client
window then run the query again.

Note: Advisor value is influenced by the current workload. In real life scenario, it should be
consulted when the database is under normal workload.

Note: 'Effective MTTR Target' the MTTR target that the database can achieve.

SELECT ESTIMATED_MTTR "Estimated MTTR",


TARGET_MTTR "Effective MTTR Target",
OPTIMAL_LOGFILE_SIZE "OPTIMAL_LOGFILE_SIZE(MB)"
FROM V$INSTANCE_RECOVERY;

Clean up

21. Exit from Putty sessions

22. Shutdown srv1 machine

23. Restore srv1 from the snapshot taken in the beginning of the practice

24. Delete the snapshot

25. (optional) Delete the generated AWR report files from the staging folder

26. Restart srv1

Oracle Database Performance Tuning, a course by Ahmed Baraka


Practice 26 - Tuning the Redo Path P a g e |8

Summary
• Having undersized redo log files could have a serious performance impact on the entire
database performance

• Redo log file size advisor could be used to determine the optimal redo log file size

Oracle Database Performance Tuning, a course by Ahmed Baraka

You might also like