Improve INSERT Performance in oracle

Performance Tuning

One day we had an issue to increase the speed of insert statements. This activity was carried out at our one of the bank client. We had to insert about 500K record to database as quickly as possible. We were inserting at a rate of 10 records/sec. Well, I was thinking the following approaches to gain speed-

  1. Use a large blocksize ñ By defining large (i.e. 16k or 32k) blocksizes for the target tables, we can reduce I/O because more rows fit onto a block before a ìblock fullî condition (as set by PCTFREE) unlinks the block from the freelist.

DROP TABLESPACE sam_tbs INCLUDING CONTENTS AND DATAFILES;
CREATE TABLESPACE sam_tbs DATAFILE ë/mnt/extra/test1.dbfí SIZE 1024M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED blocksize 16K;

  1. Increase the size of UNDO tablespace ñ

CREATE UNDO TABLESPACE UNDOTBS DATAFILE ë/mnt/extra/test_undo1.dbfí SIZE 200M BLOCKSIZE 16K;
alter system set undo_tablespace=íUNDOTBSë scope=both;
DROP TABLESPACE UNDOTBSP1 INCLUDING CONTENTS AND DATAFILES;

  1. APPEND into tables ñ By using the APPEND hint, it ensures that Oracle always grabs fresh data blocks by raising the high-water-mark for the table.

insert /*+ append */ into customer values (íhelloí,í;thereí);

  1. Table into NOLOGGING mode ñ Putting the table into NOLOGGING mode, which will allow Oracle to avoid almost all redo logging.

SELECT logging FROM user_tables WHERE table_name = ëLOGINí;
ALTER TABLE login NOLOGGING;

Again, to enable logging ñ

ALTER TABLE login LOGGING;

  1. Disable/drop indexes ñ Itís far faster to rebuild indexes after the data load, all at-once. Also indexes will rebuild cleaner, and with less I/O if they reside in a tablespace with a large block size.
  2. Parallelize the load ñ We can invoke parallel DML (i.e. using the PARALLEL and APPEND hint) to have multiple inserts into the same table. For this INSERT optimization, make sure to define multiple freelists and use the SQL ìAPPENDî option.