One of the most common concepts in Oracle Database is a transaction that is not completed while it definitely is not recorded in the Online Redo Logs. Once a COMMIT is executed, we can really make sure that transaction was written at Online RedoLog Files and the date are safe to use in case of Disaster.
Since Oracle 10gR2 this behavior can be changed using AC. (Asynchronous Commit).
Using the feature "Asynchronous Commit" it is possible to change the performance af an a DML transaction and your consistency as well. The "Asynchronous Commit" offers a higher throughput for DML transactions with many simultaneous executions. This feature improve transactions speed and can also avoid Wait events like "Log File Sync and Log File Parallel Write"
Understanding the behavior of a COMMIT
A transaction is usually started by an a application or user process. During the execution of a transaction, data changes are generated in buffer (memory). This memory area is defined by the parameter
log_buffer. When a user or application raise a COMMIT, Oracle immediately writes the buffered data (memory) to disk (redo log files) along with the redo data to commit. Until this process is not fully completed (all data are recorded in the Online Redo Log Files) Oracle will not "release" the session.
As shown in the figure above, you can change and configure the behavior of the Log Writer process, enabling Oracle Database optimize the time of recording information in a transaction Online Redo Log Files.
Changing the behavior of a COMMIT
There are 2 options to change the COMMIT behavior:
1 - COMMIT STATEMENT
You can choose how to execute your COMMIT:
Options:
- IMMEDIATE WAIT
- IMMEDIATE NOWAIT
- BATCH WAIT
- BATCH NOWAIT
2 - Change the Session or System configuration
By session, just use the ALTER SESSION:
In Oracle 10gR2:
Options:
- IMMEDIATE WAIT
- IMMEDIATE NOWAIT
- BATCH WAIT
- BATCH NOWAIT
ALTER SESSION SET COMMIT_WRITE = '{IMMEDIATE | BATCH}, {WAIT | NOWAIT}'
From the Oracle 11.1 onawrds, this parameter became obsolete, and was divided into two new parameters:
- COMMIT_WAIT
- COMMIT_LOGGING
ALTER SESSION SET COMMIT_WAIT = {NOWAIT | WAIT | FORCE_WAIT}
ALTER SESSION SET COMMIT_LOGGING = '{IMMEDIATE | BATCH}'
By system, just use the ALTER SYSTEM:
In Oracle 10gR2:
Options:
- IMMEDIATE WAIT
- IMMEDIATE NOWAIT
- BATCH WAIT
- BATCH NOWAIT
ALTER SYSTEM SET COMMIT_WRITE = '{IMMEDIATE | BATCH}, {WAIT | NOWAIT}'
From the Oracle 11.1 onawrds, this parameter became obsolete, and was divided into two new parameters:
- COMMIT_WAIT
- COMMIT_LOGGING
ALTER SYSTEM SET COMMIT_WAIT = {NOWAIT | WAIT | FORCE_WAIT}
ALTER SYSTEM SET COMMIT_LOGGING = '{IMMEDIATE | BATCH}'
* Important considerations in Oracle 11g (R1 and / or R2)
- If the parameter COMMIT_WAIT was set to FORCE_WAIT, then the option (WAIT) will be used. If this parameter is set to System (ALTER SYSTEM) or session (ALTER SESSION) then then the options via command (Transaction) will be ignored.
- The parameter COMMIT_WRITE was retained for compatibility only.
- The parameters COMMIT_WAIT and COMMIT_LOGGING take precedence over the parameter COMMIT_WRITE.
- If the parameter COMMIT_LOGGING was changed after set the parameter COMMIT_WAIT to FORCE_WAIT, then the option FORCE_WAIT will be ignored.
Examples
1 - Create control tables
create table commit_write_to (
col_1 number,
col_2 varchar2 (500)
);
create table commit_write_from (
col_1 number,
col_2 varchar2 (500)
);
2 - Enter Initial Values
begin
for r in loop 1 .. 5000
insert into commit_write_from values (
r,
dbms_random. string ('a', 500)
);
end loop;
end;
/
3 - Create auxiliary tables for Events
create table event_pre the select * from v $ session_event where rownum = 0;
create table event_post the select * from v $ session_event where rownum = 0;
4 - Create procedure to execute commits
create or replace procedure many_commits the
start_time number;
end_time number;
my_sid number;
num_rows number: = 5;
begin
select sid into my_sid
from sys. v_ $ session
where audsid = sys_context ('userenv' 'Sessionid');
delete event_pre;
delete event_post;
insert into event_pre select * from v $ session_event where sid = my_sid;
start_time : = DBMS_UTILITY. get_time;
is r in (Select * from commit_write_from) loop
insert into commit_write_to values (
r. col_1,
r. col_2
);
commit;
end loop;
end_time : = DBMS_UTILITY. get_time;
insert into event_post select * from v $ session_event where sid = my_sid;
DBMS_OUTPUT. new_line;
DBMS_OUTPUT. put_line ('time:' | | (end_time - start_time) / 100 | |'seconds');
r is in (
select post. event,
(Post. Time_waited - nvl (pre. time_waited, 0)) / 100time_waited,
post. total_waits - nvl (pre. total_waits, 0) total_waits
from event_pre pre right join
event_post post using (Event_id)
order by post. time_waited - nvl (pre. time_waited, 0) desc
) Loop
num_rows : = num_rows - 1;
exit when num_rows = 0;
DBMS_OUTPUT. put_line (
rpad (r. event, 40) | |
to_char (r. time_waited, '9999 .99 ') | |' '| |
to_char (r. total_waits, '9999999 ')
);
end loop;
end many_commits;
/
5 - Run inserts
set Feedback off
set serveroutput on size 1000000 format wrapped
alter session September commit_write = immediate, wait;
truncate table commit_write_to;
exec many_commits;
Results:
- IMMEDIATE WAIT
- IMMEDIATE NOWAIT
- BATCH WAIT
- BATCH NOWAIT
As a result, we can see that the biggest gain (in time) is related to COMMIT_WAIT parameter, which controls when information in a transaction are "written" in the Online RedoLog Files. Because Oracle does not wait for confirmation that the data was written in Redo logs, response time is near is 0s.
Benefits of using Asynchronous Commit:
- Oracle does not wait for confirmation that the COMMIT has been successfully completed, so the transaction can ran much more faster
- The BATCH option can be used to group several commits to a request for I / O.
- Optimized response time.
Observations on the use of Asynchronous Commit:
- The COMMIT process will return successfully even if the confirmation that the data was recorded in the Online Redo Log Files are not returned, so if the database go to a "crash" situation before the data in memory (LOG_BUFFER) being written tp Redo Log in Files, or experience any kind of IO problem, the COMMIT statement will be lost along with the data.
- The COMMIT_WRITE (Oracle 10g) and COMMIT_LOGGING/COMMIT_WAIT (Both Oracle 11g) are configured at INSTANCE level and may have different values across the instances. In a RAC environment, it is recommended to keep them with the same values.
- There is no parameter to disable this feature.
- It is very important to keep in mind that a common user can change the COMMIT behavior, so as a DBA you should always guide them to the right path...
:D
Documentation:
How to Minimise Waits for 'Log File Sync'? [MOS ID 857576.1]
[]s
Victor Armbrust
You need to be a member of Oracle Community to add comments!
Join Oracle Community