Oracle:Commit Enhancements in Oracle 10g Database Release 2
2011-09-23 15:21
761 查看
Commit Enhancements in Oracle 10g Database Release 2
In Oracle 10g Release 2 theCOMMITcommand has been enhanced with the
WRITEclause to give a degree of control over the way redo information is written to the redo logs during the commit operation. This can improve performance, but it should only be used for processes that meet the following criteria:
They result in large numbers of transactions that require redo log writes.
Data loss can be tolerated in the event of an instance crash during the process.
Waiting for redo log writes is a significant part of the waits associated with the process.
The available options for the
COMMITcommand and the
WRITEclause are displayed below.
COMMIT; COMMIT WRITE WAIT; COMMIT WRITE NOWAIT; COMMIT WRITE BATCH; COMMIT WRITE IMMEDIATE;
The meanings of the
WRITEclause values are listed below.
IMMEDIATE- The commit "prods" the LGWR process by sending a message, so that the redo is written imemdiately to the redo logs.
BATCH- The writes to the redo logs are buffered.
WAIT- The commit command is synchronous. It doesn't return until the relevant redo information is written to the online redo log.
NOWAIT- The commit command is asynchronous. It can return before the relevant redo information is written to the online redo log.
The action associated with the regular
COMMITcommand is defined by the
COMMIT_WRITEparameter, which accepts a comma-separated list of values.
COMMIT_WRITE = '{IMMEDIATE | BATCH},{WAIT |NOWAIT}'
The
COMMIT_WRITEparameter can be specified at instance or session level using the
ALTER SYSTEMand
ALTER SESSIONcommands respectively.
ALTER [SYSTEM | SESSION] SET COMMIT_WRITE='WAIT'; ALTER [SYSTEM | SESSION] SET COMMIT_WRITE='NOWAIT'; ALTER [SYSTEM | SESSION] SET COMMIT_WRITE='IMMEDIATE'; ALTER [SYSTEM | SESSION] SET COMMIT_WRITE='BATCH'; ALTER [SYSTEM | SESSION] SET COMMIT_WRITE='BATCH,WAIT'; ALTER [SYSTEM | SESSION] SET COMMIT_WRITE='BATCH,NOWAIT'; ALTER [SYSTEM | SESSION] SET COMMIT_WRITE='IMMEDIATE,WAIT'; ALTER [SYSTEM | SESSION] SET COMMIT_WRITE='IMMEDIATE,NOWAIT';
The default actions for the
COMMIT_WRITEparameter and
WRITEclause are the same, although at the time of writing the
COMMIT_WRITEdocumentation incorrectly says they are not, so refer to the COMMIT documentations, which says:
"If you specify neither
WAITnor
NOWAIT, then
WAITis the default. If you specify neither
IMMEDIATEnor
BATCH, then
IMMEDIATEis the default."
The following code examples show the enhanced commit processing in action. First we define a table for the code to populate.
CREATE TABLE commit_test ( id NUMBER(10), description VARCHAR2(50), CONSTRAINT commit_test_pk PRIMARY KEY (id) );
Next we see the variations of the
WRITEclause in action. The code truncates the table and measures the time taken to populate it with a commit for each insert. This process is repeated for each variant of the
WRITEclause. All the times are measured in hundredths of a second.
SET SERVEROUTPUT ON DECLARE PROCEDURE do_loop (p_type IN VARCHAR2) AS l_start NUMBER; l_loops NUMBER := 1000; BEGIN EXECUTE IMMEDIATE 'TRUNCATE TABLE commit_test'; l_start := DBMS_UTILITY.get_time; FOR i IN 1 .. l_loops LOOP INSERT INTO commit_test (id, description) VALUES (i, 'Description for ' || i); CASE p_type WHEN 'WAIT' THEN COMMIT WRITE WAIT; WHEN 'NOWAIT' THEN COMMIT WRITE NOWAIT; WHEN 'BATCH' THEN COMMIT WRITE BATCH; WHEN 'IMMEDIATE' THEN COMMIT WRITE IMMEDIATE; END CASE; END LOOP; DBMS_OUTPUT.put_line(RPAD('COMMIT WRITE ' || p_type, 30) || ': ' || (DBMS_UTILITY.get_time - l_start)); END; BEGIN do_loop('WAIT'); do_loop('NOWAIT'); do_loop('BATCH'); do_loop('IMMEDIATE'); END; / COMMIT WRITE WAIT : 129 COMMIT WRITE NOWAIT : 86 COMMIT WRITE BATCH : 128 COMMIT WRITE IMMEDIATE : 128 PL/SQL procedure successfully completed. SQL>
Next we see the variations of the
COMMIT_WRITEparameter in action. This example follows the format of the previous example, but the
COMMIT_WRITEparameter is altered for each run and a standard commit is issued.
SET SERVEROUTPUT ON DECLARE PROCEDURE do_loop (p_type IN VARCHAR2) AS l_start NUMBER; l_loops NUMBER := 1000; BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET COMMIT_WRITE=''' || p_type || ''''; EXECUTE IMMEDIATE 'TRUNCATE TABLE commit_test'; l_start := DBMS_UTILITY.get_time; FOR i IN 1 .. l_loops LOOP INSERT INTO commit_test (id, description) VALUES (i, 'Description for ' || i); COMMIT; END LOOP; DBMS_OUTPUT.put_line(RPAD('COMMIT_WRITE=' || p_type, 30) || ': ' || (DBMS_UTILITY.get_time - l_start)); END; BEGIN do_loop('WAIT'); do_loop('NOWAIT'); do_loop('BATCH'); do_loop('IMMEDIATE'); do_loop('BATCH,WAIT'); do_loop('BATCH,NOWAIT'); do_loop('IMMEDIATE,WAIT'); do_loop('IMMEDIATE,NOWAIT'); END; / COMMIT_WRITE=WAIT : 141 COMMIT_WRITE=NOWAIT : 90 COMMIT_WRITE=BATCH : 78 COMMIT_WRITE=IMMEDIATE : 94 COMMIT_WRITE=BATCH,WAIT : 139 COMMIT_WRITE=BATCH,NOWAIT : 78 COMMIT_WRITE=IMMEDIATE,WAIT : 133 COMMIT_WRITE=IMMEDIATE,NOWAIT : 87 PL/SQL procedure successfully completed. SQL>
相关文章推荐
- Commit Enhancements in Oracle 10g Database Release 2
- Online Table Redefinition Enhancements in Oracle Database 11g Release 1
- Partitioning Enhancements in Oracle Database 11g Release 1
- Oracle by Example - Oracle Database 10g Release 2 on a Single Database Instance (All In One CHM)
- Transparent Data Encryption (TDE) in Oracle 10g Database Release 2
- DML Error Logging in Oracle 10g Database Release 2
- WITH Clause Enhancements in Oracle Database 12c Release 1 (12.1)
- PL/SQL Enhancements in Oracle Database 10g
- Table Compression Enhancements in Oracle Database 11g Release 1
- Data Guard Physical Standby Setup in Oracle Database 11g Release 2
- Adaptive Cursor Sharing in Oracle Database 11g Release 1
- Temporary Tablespace Enhancements in Oracle Database 11g
- DBMS_FILE_TRANSFER Package in Oracle Database 10g
- Data Guard Physical Standby Setup in Oracle Database 11g Release 2
- (转)Fine-Grained Access to Network Services in Oracle Database 11g Release 1
- Adaptive Cursor Sharing in Oracle Database 11g Release 1
- [B14237-04]Oracle® Database Reference 10g Release 2 (10.2)
- 10g Manual Database Creation in Oracle (Single Instance and RAC) (文档 ID 240052.1)
- [B15660-02]Oracle® Database Installation Guide 10g Release 2 (10.2) for Linux x86_silent installation
- Scheduler in Oracle Database 10g