Oracle: How to execute an insert trigger without delaying the insert response?

13,835

Solution 1

There is a perfect solution for this exact situation called Database Change Notification.

You can think of it almost exactly like an async trigger.

You use the DBMS_Change_Notification package to tell oracle which tables to watch and what to do when a change occurs. You can monitor for DML and DDL, you can have Oracle batch the changes (i.e. wait for 10 changes to occur before firing). It will call a sproc with an object containing all the rowids of the changed rows... you can decide how to handle, including calling HTTP. It will not have to finish for the insert to commit. Documentation for 10gR2

Solution 2

One approach is to have the trigger create a dbms_job that runs once (each) time to perform the http transfer. The dbms_job creation is relatively quick and you can think of this as effectively spawning a new thread in parallel.

See http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:7267435205059 for further info - his example deals with sending email, but the idea is the same.

Solution 3

Maybe you could create a local table that store the info do you have to transfer, and create a job that executes every X minutes. The job read from the table, transfer all the data and delete the transfered data from the table.

Solution 4

Isn't it possible to use the Oracle replication options? You send your inserted data via http to a remote location in an after or before statement trigger. What will happen when there is a rollback? Your hhtp send message will not be rollbacked so you have inconsistent data.

Share:
13,835
Jader Dias
Author by

Jader Dias

Perl, Javascript, C#, Go, Matlab and Python Developer

Updated on June 12, 2022

Comments

  • Jader Dias
    Jader Dias almost 2 years

    The trigger below is delaying my insert response. How can I prevent this?

    create or replace
    TRIGGER GETHTTPONINSERT
    BEFORE INSERT ON TABLENAME
    FOR EACH ROW 
    Declare
      --   
    BEGIN
      -- The inserted data is transfered via HTTP to a remote location
    END;
    

    EDIT People are telling me to do batch jobs, but I would rather have the data earlier than having 100% consistency. The advantage of the trigger is that it happens as soon as the data arrives, but I can't afford the insert response delay.