Client-side Memory leak while executing PL/SQL and reading from a view

Iam noticing memory leaks in OCCI while performing the following:
Sample function()
1. Obtain a connection
2. Create a statement to execute a PL/SQL procedure
3 Execute the statement created in step #2
4. Terminate the statement created in step #2
5. Create a statement to read from a view which was populated
by executing stored procedure in step #3
6. Execute the statement created in step #5
7. Terminate the statement created in step #5
8. Release the connection
The PL/SQL populates a view with fixed 65,000 records for every execution. PL/SQL opens a cursor, loads 65000 records and populates the target view and closes the cursor at the end. If i invoke the above function it results in memory leak of 4M for every call. I tried several variants such as:
1. Disabling statement caching
2. Using setSQL instead of newly creating second SQL statement
3. Obtaining two separate connections for these two activities (PL/SQL exec and View read)
4. Breaking the sample function into two, one for each of these activities (PL/SQL exec and View read).
All the combinations results in the same behaviour of 4M memory leak.
Iam using Oracle 10g Client/Server 10.2.0.1.0.
Is there any known limitations in this area?

Yes. Iam closing the result set and terminating the statement.
My program contains layers of inhouse wrapper classes, which will take some time for
me to present it in pure OCCI calls, to be posted here for your understanding.
After some more debugging, i found that if the connection level statement caching is set to
0, the memory leak is much lower than before.
Thanks.
Message was edited by:
user498920

Similar Messages

  • Client not modifiable message while executing t-code ops7 and ops6

    Hi Guru's,
    I am getting "Client not modifiable message while executing t-code ops7 and ops6" in Unit test and Quality client.
    Pleae help me to resolve the error.
    Regards
    Sasikanth Reddy

    Hi
    Copy of the information I found regarding this issue:
    It is possible to allow the maintenance of 'Customizing'-tables in a       
    production client, even if the client is set to 'not modifiable'.          
    Normally this should be the case for tables TCJ04 (responsible person)     
    and TCJ05 (applicant).                                                                               
    Please could you check the settings in your system and change it if        
    necessary:                                                                               
    Transaction SE11:                                                                               
    Table TCJ04: delivery class should be set to 'C'                           
          TCJ05: delivery class should be set to 'C'                                                                               
    Transaction SOBJ -> Maintain                                                                               
    Position on V_TCJ04: Category should be 'CUST' field 'current settings'    
    should be marked.                                                                               
    Position on V_TCJ05: Category should be 'CUST' field 'current settings'                                                                               
    Please also check that your client is defined as 'PRODUCTIVE' via          
    transaction SCC4 (field client role).                                                                               
    I would also recommend that you review the attached notes with reference   
    to the usage of customizing setting "current settings": Nr. 77430,         
    Nr. 135028, Nr. 356483. These are also relevant for your release.          
    Kind regards,
    Zhenbo

  • ORA-06550 error while executing Dynamic Sql

    EXECUTE IMMEDIATE 'BEGIN :out := ' || lv_formula || '; END;' using out RESULT ;
    here lv_formula:= ((capcost * rate / 100) + (ob + (ob * interestrate / 100)))
    lv_formula is varchar2(360);
    and capcost,rate,ob & interestrate are my column names . Here I m declaring variables same as these columns and datatype is number.
    I am not getting any compilation error. syntax is correct
    while executing this sql i m getting ora-06550.
    can any one help me for resolving this error.
    Thanks In Advance
    hoping for more respose

    Thanks Billy for your response,
    but i still didn't get my desired solution so i am pasting my whole plsql code here. so that u can get better picture.
    /* Formatted on 2010/11/22 15:23 (Formatter Plus v4.8.5) */
    PROCEDURE xb (
    l_refno IN VARCHAR2,
    l_billtyp IN VARCHAR2,
    infor IN VARCHAR2,
    aresult OUT NUMBER
    IS
    --A NUMBER:=10; B NUMBER :=5;
    lv_formula VARCHAR2 (270); --:=(A+B)*2+5;
    l_agtmnt VARCHAR2 (18);
    l_type VARCHAR2 (2);
    RESULT NUMBER;
    refno afxbrmst.refno%TYPE;
    billtyp afxbrmst.billtyp%TYPE;
    ob afxbrmst.ob%TYPE;-- := 45283;
    status afxbrmst.status%TYPE -- := 0;
    dueamt afxbrmst.dueamt%TYPE -- := 0;
    duedate afxbrmst.duedate%TYPE;
    frequency afxbrmst.frequency%TYPE;
    lastrevrate afxbrmst.lastrevrate%TYPE -- := 0;
    penaltyamt afxbrmst.penaltyamt%TYPE -- := 0;
    accounted afxbrmst.accounted%TYPE;
    lastbillraised afxbrmst.lastbillraised%TYPE;
    noofstaff afxbrmst.noofstaff%TYPE;
    items afxbrmst.items%TYPE;
    area afxbrmst.area%TYPE;
    LENGTH afxbrmst.LENGTH%TYPE -- := 0;
    interest afxbrmst.interest%TYPE -- := 0;
    capcost NUMBER; afxbrmst.capcost%TYPE; :=1;
    -- := 1509432;
    periodfrom afxbrrate.periodfrom%TYPE;
    periodto afxbrrate.preiodto%TYPE;
    rcsrate afxbrrate.rcsrate%TYPE -- := 0;
    length_area afxbrrate.length_area%TYPE;
    rate afxbrrate.rate%TYPE --:= 0;
    -- :=3;
    erate afxbrrate.erate%TYPE -- := 0;
    feamount afxbrrate.feamount%TYPE -- := 0;
    interestrate afxbrrate.interestrate%TYPE -- := 0;
    -- :=12;
    fiamount afxbrrate.fiamount%TYPE --:= 0;
    penaltyrate afxbrrate.penaltyrate%TYPE -- := 0;
    l_ob afxbrmst_test.ob%TYPE -- := 0;
    l_capcost afxbrmst.capcost%TYPE -- := 0;
    raise_application_trigger EXCEPTION;
    inti INTEGER;
    BEGIN
    --break;
    lv_formula :=
    TO_NUMBER ((capcost * rate / 100) + (ob + (ob * interestrate / 100)));
    --infor;
    l_agtmnt := l_refno;
    l_type := l_billtyp;
    BEGIN
    SELECT a.refno, a.billtyp, a.ob, a.status, a.dueamt, a.duedate,
    a.frequency, a.lastrevrate, a.penaltyamt, a.accounted,
    a.lastbillraised, a.noofstaff, a.items, a.area, a.LENGTH,
    a.interest, a.capcost
    INTO refno, billtyp, ob, status, dueamt, duedate,
    frequency, lastrevrate, penaltyamt, accounted,
    lastbillraised, noofstaff, items, area, LENGTH,
    interest, capcost
    FROM afxbrmst_test a
    WHERE billtyp = l_type AND refno = l_agtmnt;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    END;
    BEGIN
    SELECT b.periodfrom, b.preiodto, b.rcsrate, b.length_area, b.rate,
    b.erate, b.feamount, b.interestrate, b.fiamount, b.penaltyrate
    INTO periodfrom, periodto, rcsrate, length_area, rate,
    erate, feamount, interestrate, fiamount, penaltyrate
    FROM afxbrrate b
    WHERE billtype = l_type;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    END;
    EXECUTE IMMEDIATE 'BEGIN :out := ' || lv_formula || '; END;'
    USING OUT RESULT; --USING OUT RESULT;
    aresult := RESULT;
    END;
    -- Procedure
    here i m passing the parameter through my form builder and calling this procedure.
    can you tell me where i am making wrong
    Thanks again

  • "Unable to Allocate Aligned Memory" error, while executing BR

    Hi Gurus
    I'm facing "Unable to Allocate Aligned Memory" error while executing a BR. Please help me out, I'm in a real trouble due to this.
    Thanks

    Everyday I get more and more worried about this forum and the way things are heading.
    If you are an essbase administrator you should understand the basics or just research a little bit.
    Even a quick search would reveal your answer - Re: Unable to Allocate Aligned Memory:Essbase error:1008143
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Dump While Executing ME21N, ME22N and ME23N

    Hi,
    Am getting the below Short Dump while executing ME21N, ME22N and ME23N.
    Runtime Errors         SYNTAX_ERROR
    Date and Time          08.07.2009 15:41:00
    |Short text                                                                               
    Syntax error in program "ME_PROCESS_PO_CUST============CP ".
    |What happened?                                                                               
    |    Error in the ABAP Application Program                                                                               
    |                                                                               
    |    The current ABAP program "CL_EX_ME_PROCESS_PO_CUST======CP" had to be                     
    |     terminated because it has                                                                               
    |    come across a statement that unfortunately cannot be executed.                                                  
    |                                                                               
    |    The following syntax error occurred in program                                                                             
    |     "ME_PROCESS_PO_CUST============CP " in include                                                                 
    |     "ME_PROCESS_PO_CUST============CM000 " in                                                                      
    |    line 14:                                                                               
    |    "The specified type cannot be converted into the target variables."                         
    |    " "                                                                               
    |    " "                                                                               
    |    " "                                                                               
    |                                                                               
    |    The include has been created and last changed by:                                           
    |    Created by: "SILABAP "                                                                      
    |    Last changed by: "SILABAP "                                                                 
    |    Error in the ABAP Application Program                                                        
    |                                                                               
    |    The current ABAP program "CL_EX_ME_PROCESS_PO_CUST======CP" had to be                     
    |     terminated because it has                                                                   
    |    come across a statement that unfortunately cannot be executed.                               
    |Error analysis                                                                               
    |    The following syntax error was found in the program                                          
    |     ME_PROCESS_PO_CUST============CP :                                                          
    |    "The specified type cannot be converted into the target variables."                          
    |    " "                                                                               
    |    " "                                                                               
    |    " "                                                                               
    |Trigger Location of Runtime Error                                                                
    |    Program                                 CL_EX_ME_PROCESS_PO_CUST======CP                     
    |    Include                                 CL_EX_ME_PROCESS_PO_CUST======CM001                  
    |    Row                                     1                                                    
    |    Module type                             (METHOD)                                             
    Module Name                             IF_EX_ME_PROCESS_PO_CUST~INITIALIZE
    |Source Code Extract                                                                               
    |Line |SourceCde                                                                               
    |>>>>>|method IF_EX_ME_PROCESS_PO_CUST~INITIALIZE.                                                
    |    2|  CLASS CL_EXIT_MASTER DEFINITION LOAD.                                                    
    3
    |    4|  DATA l_badi TYPE REF TO ME_PROCESS_PO_CUST.                                              
    5
    6
    7
    8
    9
    |   10|  TRY.                                                                               
    11
    |   12|    GET BADI l_badi                                                                        
    |   13|     CONTEXT me.                                                                           
    14
    |   15|    CALL BADI l_badi->INITIALIZE                                                           
    |   16|.                                                                               
    17
    18
    19
    |   20|    CATCH CX_BADI_NOT_IMPLEMENTED CX_BADI_INITIAL_REFERENCE.                               
    Please let me know is there any OSS note to resolve the Issue.
    Thanks,
    Subas

    Hi,
    when I try to do the same in my system SAP gives me an information message as follows:-
    Changes to transported Business Add-In definitions are incompatible
    Message no. ENHANCEMENT236
    Diagnosis
    This business add-in definition has already been transported. Subsequent changes could invalidate existing business add-in implementations.
    System Response
    The runtime behaviour is no longer predictable. Syntax errors or short dumps may occur.
    Procedure
    If possible, do not make these changes. Alternatively, create a new business add-in definition incorporating the changes and use it, along with the existing definition.
    It clearly indicates that the BADI definition should not be changed if active implementations already exists.
    I am really now not sure how to solve your issue.
    Try deactiviting the standard BADI implementation.
    Then again add the filter and then remove it.
    And then try activating the BADI implementation once again.
    Regards,
    Ankur Parab

  • While executing TCode F13 and F13E, purchase order number is not appearing.how it should be displayed into tcode f.13, please any one help me

    While executing TCode F13 and F13E, purchase order number is not appearing.how it should be displayed into tcode f.13, what are the requirements need to display into tcode f.13, please any one help me, i am facing this problem in  production server

    Hi Nattu,
    Please check it will show the PO no under Purchasing doc field
    Check which layout you are applied.
    its should be
    SAP&F124
    Without Specification of Crcy
    Regd,
    Khan.

  • How To... Execute Planning Functions and Sequences from MS Office Ribbon

    Dear all,
    I am working with a SAP how to paper, which is called:
    How To... Execute Planning Functions and Sequences from MS Office Ribbon.
    It is working absolutely fine and I am pretty satisfied, but as you probably know "Control the visibility of a button based on the visibility of a related crosstab: the  button just disappears once the related crosstab is not located on the active sheet."
    This means, when I insert different queries in different crosstabs, only one crosstab will have my own created ribbon. Is it also possible to set another specific ribbon with other buttons for another crosstab? Can I change the macro, included in the appendix of the how to paper, regarding this issue?
    Thanks in advance!
    Kind regards
    Dominik Drebinger

    Hey Martin,
    thanks for your reply, but I solved the problem on my own. Unfortunately my colleague did not see that the crosstabs had to be defined differently.
    Like this:
    Label
    Screentip
    Msolmage name
    Crosstab name
    Copy Initial Aligned
    Copy Initial Aligned
    CacheListData
    SAPCrosstab1
    Copy Initial Aligned 
    Copy Initial Aligned
    CacheListData
    SAPCrosstab3
    Copy Initial Aligned
    Copy Initial Aligned
    CacheListData
    SAPCrosstab5
    The macro, provided by the HowTo, is therefore working perfectly fine.
    Thanks though
    Dominik

  • Apple charged me 8 times $1 while changing the country and purchase from app stores. Help pls

    Hi all
    Apple charged me 8 times $1 while changing the country and purchase from app stores.
    Help pls, I want my money back

    To Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • Memory Leak while using -Xrunhprof option in Linux OS

    While using the follwing option in my application there is memory leak in JVM in Linux OS.
    -Xrunhprof:heap=all,cpu=times,monitor=y,file=/home/gemini/dilip/www2.log,thread=yIs this a bug ??

    Little lost here. Looks like you are facing memory leaks in Tuxedo 7.1 WS
    client code when it talks with Tuxedo 6.x? Is this correct?
    If so, try installing latest rolling patch for Tuxedo 7.1.
    We recently fixed couple of memory leaks in interop area. One was related to
    compression.
    _shailesh
    Scott Orshan <[email protected]> wrote in message
    news:[email protected]..
    If you are running with the latest patch, then report these problems to
    Support, giving them sample code so that they can reproduce the problem.
    Scott
    Thomas Winter wrote:
    Hi Scott,
    as an additional information:
    The guys at the server side changed something (their
    formaly useing the old 6.3 libraries at server side)
    and surprise... the client has no memory leak anymore.
    But, if more than one thread at the same time use the atmi calls
    there is still some memory consumption.
    The workaround is to use a mutex object to make sure, that
    only one thread use the atmi calls.
    AFAIS Tuxedo has an Problem with Multithreading.
    Thx
    Thomas

  • Error while executing a sql query for select

    HI All,
    ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.

    I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
    1. I dont want to increase the temp space
    2. I need to tune the query, please provide your recomendations.
    insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
    (REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
    select
    REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
    carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
    carrier_item_type,carried_item_protection_type,'PACS'
    from
    (select distinct
    c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
    a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
    a.carrier_item_type,a.carried_item_protection_type,'PACS'
    from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
    where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
    AND a.carrier_items=b.mux
    and c.REPORTNUMBER=(case
    when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
    else 20
    end)
    and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
    where not exists
    (select *
    from CST_DSA.HIERARCHY_MISMATCHES B where
    A.REPORTNUMBER=B.REPORT_NUM and
    A.REPORTTYPE=B.REPORT_TYPE and
    A.REPORTDESCRIPTION=B.REPORT_DESC and
    A.CARRIED_ITEMS=B.CARRIED_ITEMS and
    A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
    A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
    A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
    A.CARRIER_ITEMS=B.CARRIER_ITEMS and
    A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
    A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
    AND B.SOURCE_SYSTEM='PACS'
    Explain Plan
    ==========
    Plan
    INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1                                                        
         20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES                                                   
              19 PX COORDINATOR                                              
                   18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                         
                        17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                    
                             15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1                               
                                  4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621                          
                                       3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                     
                                            2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                
                                                 1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621           
                                  14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448                          
                                       11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448                     
                                            8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002               
                                                 7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2           
                                                      6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2      
                                                           5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
                                            10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448                
                                                 9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448           
                                       13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1                     
                                            12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1                
                             16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1

  • Strange error while execute PL/SQL

    Hi All,
    I am execting a procedure from user (say USER1) who is having the DBA role granted.
    Its getting the errors while creation:
    SQL> show errors
    Errors for PROCEDURE DISP_DBLOCKS:
    LINE/COL ERROR
    8/11 PLS-00341: declaration of cursor 'DBLOCK_CURSOR' is incomplete or
    malformed
    10/8 PL/SQL: SQL Statement ignored
    34/15 PL/SQL: ORA-00942: table or view does not exist
    42/17 PL/SQL: Item ignored
    54/8 PL/SQL: SQL Statement ignored
    56/16 PL/SQL: ORA-00942: table or view does not exist
    79/8 PL/SQL: SQL Statement ignored
    79/33 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    LINE/COL ERROR
    82/8 PL/SQL: Statement ignored
    82/27 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    But If I execute the same procedure from SYS user, its got created without any errors.
    The procedure is using tables SYS.V$LOCK L, SYS.V$SESSION S, SYS.V$PROCESS P, SYS.USER$ U, SYS.OBJ$ T and shows the locking info for DB.
    Please let me know if I am missing something and also how to resolve this issue.
    Thanks in advanced
    Bhupinder

    ORA-00942: table or view does not existbecause u don't have permission on some tables
    check it by manual issue select from these tables by new user

  • OCI crash while executing PL/SQL

    HI,
    I have a multithreaded application which uses OCI. The application has a master thread and spwans 4 child threads that connect to the db and execute specific queries. The problem occurs while trying to execute the last PL/SQL command which includes some bfile operations. I had read that OCI does not mutex properly on LOB operations, but I do not get any error, the application just hangs. Attached is part of the code that has all OCI calls.
    The culprit is the update_tables function. The application hangs in there when processing is very close in time for threads.
    [] 20080411 10:40:52.255 Oracle NOTICE - [2000][id 1093229] Executing PL/SQL to update all tables
    [] 20080411 10:40:52.259 Oracle NOTICE - [2000][id 1093230] Executing PL/SQL to update all tables
    [] 20080411 10:40:52.321 Oracle NOTICE - [2000][id 1093231] Executing PL/SQL to update all tables
    this is where is hangs.
    //!This program is the server portion of the distributed job system.
    #include "application.h"
    #include "log4cwrapper.h"
    //#include "sql.h"
    #include <oci.h>
    OCIEnv*            env;
    int main(int argc, char* argv[]){
         OCIError*     err;
         OCIServer*    srv;
         OCISvcCtx*    svc;
         OCISession*   ses;
         sword r;
         OCIStmt*       initslc;
         OCIStmt*       comm;
         OCIBind      *bnd1hp = (OCIBind*) 0;
         char stmt[]="commit";
         char update_initial[] ="update CONV_IMAGE_JOBS set conv_attempts_cnt = :1";
         FILE *log_fd_main;
         int sockfd, logfd, pidfd, count = 0, oci_error = 0;
         pthread_t job_thread;               //!<Threads for image conversion
        pthread_attr_t thread_attr;          //!<Thread attribute
        int *clientfd;                         //!<Non-negative file descriptor for new socket
        pthread_mutexattr_t mattr;          //!<Mutex attribute used to set the properties of the mutex
         char masterpid[100];
         log_fd_main = fopen(log_file, "a");
         if (log_fd_main == NULL) {
              printf(" ERROR - DjsMaster [0002] Failed to open log file.\n");
            exit(1);
        r=OCIEnvCreate( &env,
              OCI_THREADED
             , 0, 0, 0, 0, 0, 0);
        if (r != OCI_SUCCESS) {
              strcpy(err_msg,"Couldn't create environment (OCIEnvCreate)");
              oci_error = 1;
              cleanup();
         OCIHandleAlloc(env, (dvoid**)&err, OCI_HTYPE_ERROR,   0, 0);
         OCIHandleAlloc(env, (dvoid**)&srv, OCI_HTYPE_SERVER,  0, 0);
         OCIHandleAlloc(env, (dvoid**)&svc, OCI_HTYPE_SVCCTX,  0, 0);
         OCIHandleAlloc(env, (dvoid**)&ses, OCI_HTYPE_SESSION, 0, 0);
         r=OCIServerAttach(srv, err, dbname, strlen((const char*)dbname), (ub4) OCI_DEFAULT);
         if (r != OCI_SUCCESS) {
              checkerrr(err, r, err_msg);
              oci_error = 1;
              cleanup();
         OCIAttrSet(svc, OCI_HTYPE_SVCCTX, srv, 0, OCI_ATTR_SERVER,  err);
         OCIAttrSet(ses, OCI_HTYPE_SESSION, username,
                strlen((const char*)username), OCI_ATTR_USERNAME, err);
         OCIAttrSet(ses, OCI_HTYPE_SESSION, password,
                strlen((const char*)password), OCI_ATTR_PASSWORD, err);
         if ( (r=OCIAttrSet((dvoid *) svc, (ub4) OCI_HTYPE_SVCCTX,
                (dvoid *) ses, (ub4) 0, (ub4) OCI_ATTR_SESSION, err)) ) {
              checkerrr(err, r,err_msg);
              oci_error = 1;
              cleanup();
         r=OCISessionBegin (svc, err, ses, OCI_CRED_RDBMS, OCI_DEFAULT);
         if (r != OCI_SUCCESS) {
              checkerrr(err, r,err_msg);
              oci_error = 1;
              cleanup();
         if (OCIHandleAlloc((dvoid *) env, (dvoid **) &initslc,
                (ub4) OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0)) {
              checkerrr(err, r, (text*)err_msg);
              oci_error = 1;
              cleanup();
         if ((r=OCIStmtPrepare(initslc, err, (text*)(void*)update_initial,
                (ub4) strlen((char *) update_initial),
                (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))) {
              checkerrr(err, r, (text*)err_msg);
              OCIHandleFree((dvoid *) initslc, (ub4) OCI_HTYPE_STMT);
              oci_error = 1;
              cleanup();
         int coun=0;
         if ((r = OCIBindByPos(initslc, &bnd1hp, err, (ub4) 1, &coun, sizeof(count), SQLT_INT,
                                 (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT))){
               checkerrr(err, r, (text*)err_msg);
            oci_error = 1;
              cleanup();
         if ((r = OCIStmtExecute(svc, initslc, err, (ub4) 1, (ub4) 0, (CONST OCISnapshot *) 0,
                                   (OCISnapshot *) 0, (ub4) OCI_DEFAULT))){
              checkerrr(err, r, (text*)err_msg);
             OCIHandleFree((dvoid *) sh, (ub4) OCI_HTYPE_STMT);
             oci_error = 1;
               cleanup();
         if ((r=OCIHandleAlloc((dvoid *) env, (dvoid **) &comm,
                (ub4) OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0))) {
              checkerrr(err, r, (text*)err_msg);
              oci_error = 1;
              cleanup();
         if ((r=OCIStmtPrepare(comm, err, (text*)(void*)stmt,
                (ub4) strlen((char *) stmt), (ub4) OCI_NTV_SYNTAX,
                (ub4) OCI_DEFAULT))) {
              checkerrr(err, r, (text*)err_msg);
              OCIHandleFree((dvoid *) comm, (ub4) OCI_HTYPE_STMT);
              oci_error = 1;
              cleanup();
         if ((r=OCIStmtExecute(svc, comm, err, (ub4) 1, (ub4) 0,
                (CONST OCISnapshot *) 0, (OCISnapshot *) 0,
                (ub4) OCI_DEFAULT))) {
              checkerrr(err, r, (text*)err_msg);
              OCIHandleFree((dvoid *) comm, (ub4) OCI_HTYPE_STMT);
              oci_error = 1;
              cleanup();
         OCIHandleFree((dvoid *) comm, (ub4) OCI_HTYPE_STMT);
         OCIHandleFree((dvoid *) initslc, (ub4) OCI_HTYPE_STMT);
         if ((r = OCISessionEnd(svc, err, ses, OCI_DEFAULT))) {
              checkerrr(err, r, (text*)err_msg);
              oci_error = 1;
              cleanup();
        if ((r = OCIServerDetach(srv, err, OCI_DEFAULT))) {
              checkerrr(err, r, (text*)err_msg);
              oci_error = 1;
              cleanup();
         if ((r = OCIHandleFree((dvoid*) ses, (ub4) OCI_HTYPE_SESSION))) {
              checkerrr(err, r, (text*)err_msg);
              oci_error = 1;
              cleanup();
        if ((r = OCIHandleFree((dvoid*) svc, (ub4) OCI_HTYPE_SVCCTX))) {
              checkerrr(err, r, (text*)err_msg);
              oci_error = 1;
              cleanup();
        if ((r = OCIHandleFree((dvoid*) srv, (ub4) OCI_HTYPE_SERVER))) {
              checkerrr(err, r, (text*)err_msg);
              oci_error = 1;
              cleanup();
        if ((r = OCIHandleFree((dvoid*) err, (ub4) OCI_HTYPE_ERROR))) {
              oci_error = 1;
              cleanup();
         if ( oci_error == 1) {
              cleanup();
            log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
         log4c_appender_set_udata(myappender, log_fd_main);
         mylog_msg("DjsMaster", LOG4C_PRIORITY_DEBUG,
          " [0000]  daemon running, ready to accept connections,"
          "waiting for to connect......");     
         fclose(log_fd_main);
         while (1) {
                 Accept a connection from a slave. 
            clientfd = malloc(sizeof(int));
            if ((*clientfd = serv_accept(sockfd)) < 0) {
                    exit(1);
                 Fork off a child thread to process this slave. 
            pthread_create(&job_thread, &thread_attr, jobfunction, clientfd);
             //count++;
               sleep(1);
    //!Dump Oracle Error
    void cleanup() {
         log4c_appender_t* myappender;
         myappender = log4c_appender_get("myappender");
         log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
         log4c_appender_set_udata(myappender, fopen(log_file, "a"));
         mylog_log("DjsMaster", LOG4C_PRIORITY_ERROR,
          " [2001] Oracle error %s", err_msg);
    void *jobfunction(void *arg) {
         OCIError*     err;
         OCIServer*    srv;
         OCISvcCtx*    svc;
         OCISession*   ses;
         sword r;
         OCIBind      *bnd1hp = (OCIBind*) 0;
         OCIBind      *bnd2hp = (OCIBind*) 0;
         OCIBind      *bnd3hp = (OCIBind*) 0;
         OCIDefine *def1hp = (OCIDefine *) 0;
         OCIDefine *def2hp = (OCIDefine *) 0;
         OCIDefine *def3hp = (OCIDefine *) 0;
         OCIDefine *def4hp = (OCIDefine *) 0;
         OCIDefine *def5hp = (OCIDefine *) 0;
         OCIDefine *def6hp = (OCIDefine *) 0;
         OCIDefine *def7hp = (OCIDefine *) 0;
         OCIDefine *def8hp = (OCIDefine *) 0;
         OCIDefine *def9hp = (OCIDefine *) 0;
         char select_all[] =" select filename, filepath, image_system_id, quality_status_cd,"
                          " format_cd,global_id, id, conv_attempts_cnt, image_resolution"
                                  " from TABLE_NAME where conv_attempts_cnt = 0 order by created_datetime ";
         char select_count[] ="select conv_attempts_cnt, image_resolution from TABLE_NAME"
                            " where id = :1 ";
         char update_single[] ="update TABLENAME set conv_attempts_cnt = :1 where id = :2 ";
         char stmt[]="commit";
         int oci_error = 0;
            Variables to hold the values returned from SQL SELECT
         int id, global_id, format_cd, quality_status;
         int resolution, image_id, conv_attempts_cnt;
         char filename[101];                      
       char filepath[201];                      
         char filepath_full[MAX_BUF];       
         char tif_filename[101];                 
         char return_filepath[MAX_BUF];     
         char conv_details[MAX_BUF];          
         char *hold_filename;
         char *hold_filepath;
         char *hold_tiffile;
       char *progress;
         char *tempstr_p;
       char *jobnum_p;
       char *returnname_p;
         char *returnsize_p;
         char tempstr[MAX_BUF];
         int count = 0;                 
         int success_flag = 0;     
       int reprocess_flag = 0;
         char s_resolution[5];     
         char s_format[5];            
         struct stat filebuf;      
         int myfd, datafd, jobid, i, update, holdid;
         char sockread[1024], sockwrite[1024],
            jobnum[10], dataname[1024],
            line_to_log[1024], databuf[1024];
         int datasize, bufsize, returnsize, filesize;
         FILE *log_fd;
         log4c_appender_t* myappender;
         myappender = log4c_appender_get("myappender");
         log_fd = fopen(log_file, "a");
         if (log_fd == NULL) {
              perror(" ERROR - DjsMaster [1000] Failed to open log file.\n");
            exit(1);
         myfd = *((int *)arg);          
       log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
         log4c_appender_set_udata(myappender, log_fd);
         mylog_log("DjsMaster", LOG4C_PRIORITY_NOTICE,
                " [1000] Starting jobs on %d.",
                (int)pthread_self());     
         Readline_r(myfd, sockread, 255);
            Continue to read requests received from the slaves. 
         while (strcmp(sockread, SLAVE_DONE) != 0) {
              OCIStmt* slcth;               
              OCIStmt* updth;               
              OCIStmt* slcth2;           
              OCIStmt*       comm;
              sleep(15);
          log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
              log4c_appender_set_udata(myappender, log_fd);
              mylog_log("DjsMaster", LOG4C_PRIORITY_NOTICE,
             " [1000] Continue to read request from %d, looping with %s ",
             (int)pthread_self(), sockread);     
            if (strcmp(sockread, REQUEST_JOB) == 0) {
                   log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                   log4c_appender_set_udata(myappender, log_fd);
                   mylog_log("DjsMaster", LOG4C_PRIORITY_NOTICE,
                " [1000] %d  requesting job. Connecting to database.",
                (int)pthread_self());     
               if (oci_error == 1) {
                if ((r = OCIServerDetach(srv, err, OCI_DEFAULT))) {
                        checkerrr(err, r, (text*)err_msg);
                        cleanup();
                      if ((r = OCIHandleFree((dvoid*) ses, (ub4) OCI_HTYPE_SESSION))) {
                           checkerrr(err, r, (text*)err_msg);
                           cleanup();
                      if ((r = OCIHandleFree((dvoid*) svc, (ub4) OCI_HTYPE_SVCCTX))) {
                           checkerrr(err, r, (text*)err_msg);
                           cleanup();
                      if ((r = OCIHandleFree((dvoid*) srv, (ub4) OCI_HTYPE_SERVER))) {
                           checkerrr(err, r, (text*)err_msg);
                           cleanup();
                      if ((r = OCIHandleFree((dvoid*) err, (ub4) OCI_HTYPE_ERROR))) {
                           cleanup();
                oci_error = 0;
                   OCIHandleAlloc(env, (dvoid**)&err, OCI_HTYPE_ERROR,   0, 0);
                   OCIHandleAlloc(env, (dvoid**)&srv, OCI_HTYPE_SERVER,  0, 0);
                   OCIHandleAlloc(env, (dvoid**)&svc, OCI_HTYPE_SVCCTX,  0, 0);
                   OCIHandleAlloc(env, (dvoid**)&ses, OCI_HTYPE_SESSION, 0, 0);
                   r=OCIServerAttach(srv, err, dbname,
                   strlen((const char*)dbname), (ub4) OCI_DEFAULT);
                   if (r != OCI_SUCCESS) {
                        checkerrr(err, r, err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   OCIAttrSet(svc, OCI_HTYPE_SVCCTX, srv, 0, OCI_ATTR_SERVER,  err);
             OCIAttrSet(ses, OCI_HTYPE_SESSION, username,
                   strlen((const char*)username), OCI_ATTR_USERNAME, err);
             OCIAttrSet(ses, OCI_HTYPE_SESSION, password,
                   strlen((const char*)password), OCI_ATTR_PASSWORD, err);
                   if ( (r=OCIAttrSet((dvoid *) svc, (ub4) OCI_HTYPE_SVCCTX,
                   (dvoid *) ses, (ub4) 0, (ub4) OCI_ATTR_SESSION, err)) ) {
                        checkerrr(err, r,err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   r=OCISessionBegin (svc, err, ses, OCI_CRED_RDBMS, OCI_DEFAULT);
                   if (r != OCI_SUCCESS) {
                        checkerrr(err, r,err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if (OCIHandleAlloc((dvoid *) env, (dvoid **) &slcth,
                   (ub4) OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0)) {
                        checkerrr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIStmtPrepare(slcth, err, (text*)(void*)select_all,
                      (ub4) strlen((char *) select_all),
                      (ub4) OCI_NTV_SYNTAX,
                      (ub4) OCI_DEFAULT))) {
                        checkerrr(err, r, (text*)err_msg);
                        OCIHandleFree((dvoid *) slcth, (ub4) OCI_HTYPE_STMT);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIDefineByPos(slcth, &def1hp, err, 1,
                      filename, 100, SQLT_CHR, (dvoid *) 0,
                      (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIDefineByPos(slcth, &def2hp, err, 2,
                      filepath, 100, SQLT_CHR, (dvoid *) 0,
                      (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIDefineByPos(slcth, &def3hp, err, 3,
                      &image_id, sizeof(int), SQLT_INT, (dvoid *) 0,
                      (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIDefineByPos(slcth, &def4hp, err, 4,
                      &quality_status, sizeof(int), SQLT_INT,
                      (dvoid *) 0, (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIDefineByPos(slcth, &def5hp, err, 5,
                      &format_cd, sizeof(int), SQLT_INT, (dvoid *) 0,
                      (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIDefineByPos(slcth, &def6hp, err, 6,
                      &global_id, sizeof(int), SQLT_INT, (dvoid *) 0,
                      (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIDefineByPos(slcth, &def7hp, err, 7,
                      &id, sizeof(int), SQLT_INT, (dvoid *) 0,
                      (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIDefineByPos(slcth, &def8hp, err, 8,
                      &conv_attempts_cnt, sizeof(int), SQLT_INT, (dvoid *) 0,
                      (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                   if ((r=OCIDefineByPos(slcth, &def9hp, err, 9,
                      &resolution, sizeof(int), SQLT_INT, (dvoid *) 0,
                      (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                        checkerr(err, r, (text*)err_msg);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   if ((r=OCIStmtExecute(svc, slcth, err, (ub4) 0, (ub4) 0,
                      (CONST OCISnapshot *) 0, (OCISnapshot *) 0,
                      (ub4) OCI_DEFAULT))){
                        checkerr(err, r, (text*)err_msg);
                        OCIHandleFree((dvoid *) slcth, (ub4) OCI_HTYPE_STMT);
                        oci_error = 1;
                        cleanup();
                        sprintf(sockwrite, "%s", NO_JOB);
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        Readline_r(myfd, sockread, 255);
                        continue;
                   r = OCIStmtFetch(slcth, err, (ub4) 1, (ub4) OCI_FETCH_NEXT, (ub4) OCI_DEFAULT);
                   if (r == OCI_SUCCESS) {
                        success_flag = 1;
                reprocess_flag = 0;
                   else if (r == OCI_SUCCESS_WITH_INFO) {
                        success_flag = 1;
                reprocess_flag = 0;
                   else {
                        if (r != OCI_NO_DATA) {
                             checkerr(err, r, (text*)err_msg);
                             success_flag = 0;
                        success_flag = 0;
                   OCIHandleFree((dvoid *) slcth, (ub4) OCI_HTYPE_STMT);
                       No job in the table. Continue listening. Tell the slave
                       there are no current jobs to process. 
                 if (! (success_flag)) {
                if ((r = OCISessionEnd(svc, err, ses, OCI_DEFAULT))) {
                           checkerrr(err, r, (text*)err_msg);
                           oci_error = 1;
                           cleanup();
                           sprintf(sockwrite, "%s", NO_JOB);
                           Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                           Readline_r(myfd, sockread, 255);
                           continue;
                if ((r = OCIServerDetach(srv, err, OCI_DEFAULT))) {
                           checkerrr(err, r, (text*)err_msg);
                           oci_error = 1;
                           cleanup();
                           sprintf(sockwrite, "%s", NO_JOB);
                           Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                           Readline_r(myfd, sockread, 255);
                           continue;
                      if ((r = OCIHandleFree((dvoid*) ses, (ub4) OCI_HTYPE_SESSION))) {
                           checkerrr(err, r, (text*)err_msg);
                           oci_error = 1;
                           cleanup();
                           sprintf(sockwrite, "%s", NO_JOB);
                           Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                           Readline_r(myfd, sockread, 255);
                           continue;
                      if ((r = OCIHandleFree((dvoid*) svc, (ub4) OCI_HTYPE_SVCCTX))) {
                           checkerrr(err, r, (text*)err_msg);
                           oci_error = 1;
                           cleanup();
                           sprintf(sockwrite, "%s", NO_JOB);
                           Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                           Readline_r(myfd, sockread, 255);
                           continue;
                      if ((r = OCIHandleFree((dvoid*) srv, (ub4) OCI_HTYPE_SERVER))) {
                           checkerrr(err, r, (text*)err_msg);
                           oci_error = 1;
                           cleanup();
                           sprintf(sockwrite, "%s", NO_JOB);
                           Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                           Readline_r(myfd, sockread, 255);
                           continue;
                      if ((r = OCIHandleFree((dvoid*) err, (ub4) OCI_HTYPE_ERROR))) {
                           oci_error = 1;
                           cleanup();
                           sprintf(sockwrite, "%s", NO_JOB);
                           Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                           Readline_r(myfd, sockread, 255);
                           continue;
                        success_flag = 0;
                        sprintf(sockwrite, "%s", NO_JOB);
                    log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                        log4c_appender_set_udata(myappender, log_fd);
                        mylog_log("DjsMaster", LOG4C_PRIORITY_NOTICE,
                      " [1000] No new jobs, writing to %d %s",
                      (int)pthread_self(), sockwrite);     
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                Readline_r(myfd, sockread, 255);
                        success_flag = 0;
                continue;
                   /*  New job is fetched, process it.  */
                     else {
                reprocess_flag = 0;
    reprocess:     log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                        log4c_appender_set_udata(myappender, log_fd);
                        mylog_log("Oracle", LOG4C_PRIORITY_DEBUG,
                   " [2000][id %d] Fetching data for new job from databse", id);
                        mylog_log("Oracle", LOG4C_PRIORITY_DEBUG,
                   " [2000][id %d]Fetched job_id=%d, format=%d, resolution=%d, conv_attemtps=%d, imagefile=%s, imagepath=%s",
                   id, id, format_cd, resolution,
                   conv_attempts_cnt, filename, filepath);
                        log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                        log4c_appender_set_udata(myappender, log_fd);
                        mylog_log("DjsMaster", LOG4C_PRIORITY_NOTICE,
                   " [1000][id %d] New job for %d. Job will be processed.",
                   id, (int)pthread_self());     
                        holdid = id;
                if ( reprocess_flag == 1 )
                           OCIHandleAlloc(env, (dvoid**)&err, OCI_HTYPE_ERROR,   0, 0);
                           OCIHandleAlloc(env, (dvoid**)&srv, OCI_HTYPE_SERVER,  0, 0);
                           OCIHandleAlloc(env, (dvoid**)&svc, OCI_HTYPE_SVCCTX,  0, 0);
                           OCIHandleAlloc(env, (dvoid**)&ses, OCI_HTYPE_SESSION, 0, 0);
                           r=OCIServerAttach(srv, err, dbname, strlen((const char*)dbname), (ub4) OCI_DEFAULT);
                           if (r != OCI_SUCCESS) {
                                checkerrr(err, r, err_msg);
                                oci_error = 1;
                                cleanup();
                                success_flag = 0;
                                sprintf(sockwrite, "%s", NO_JOB);
                                Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                                Readline_r(myfd, sockread, 255);
                                continue;
                           OCIAttrSet(svc, OCI_HTYPE_SVCCTX, srv, 0, OCI_ATTR_SERVER,  err);
                           OCIAttrSet(ses, OCI_HTYPE_SESSION, username, strlen((const char*)username), OCI_ATTR_USERNAME, err);
                           OCIAttrSet(ses, OCI_HTYPE_SESSION, password, strlen((const char*)password), OCI_ATTR_PASSWORD, err);
                           if ( (r=OCIAttrSet((dvoid *) svc, (ub4) OCI_HTYPE_SVCCTX, (dvoid *) ses, (ub4) 0, (ub4) OCI_ATTR_SESSION, err)) ) {
                                checkerrr(err, r,err_msg);
                                oci_error = 1;
                                cleanup();
                                success_flag = 0;
                                sprintf(sockwrite, "%s", NO_JOB);
                                Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                                Readline_r(myfd, sockread, 255);
                                continue;
                           r=OCISessionBegin (svc, err, ses, OCI_CRED_RDBMS, OCI_DEFAULT);
                           if (r != OCI_SUCCESS) {
                                checkerrr(err, r,err_msg);
                                oci_error = 1;
                                cleanup();
                                success_flag = 0;
                                sprintf(sockwrite, "%s", NO_JOB);
                                Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                                Readline_r(myfd, sockread, 255);
                                continue;
                        if (OCIHandleAlloc((dvoid *) env, (dvoid **) &slcth2,
                      (ub4) OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0)) {
                             checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r=OCIStmtPrepare(slcth2, err, (text*)(void*)select_count,
                      (ub4) strlen((char *) select_count),
                      (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))) {
                             checkerrr(err, r, (text*)err_msg);
                             OCIHandleFree((dvoid *) slcth2, (ub4) OCI_HTYPE_STMT);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r=OCIDefineByPos(slcth2, &def1hp, err, 1,
                         &conv_attempts_cnt, sizeof(int), SQLT_INT, (dvoid *) 0,
                         (ub2   *) 0, (ub2   *) 0, OCI_DEFAULT))) {
                             checkerr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIBindByPos(slcth2, &bnd1hp, err, (ub4) 1,
                         &holdid, sizeof(int), SQLT_INT,
                         (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0,
                         (ub4 *) 0, OCI_DEFAULT))){
                             checkerr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIStmtExecute(svc, slcth2, err, (ub4) 0, (ub4) 0,
                         (CONST OCISnapshot *) 0,
                         (OCISnapshot *) 0, (ub4) OCI_DEFAULT))){
                             checkerr(err, r, (text*)err_msg);
                             OCIHandleFree((dvoid *) slcth2, (ub4) OCI_HTYPE_STMT);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        r = OCIStmtFetch(slcth2, err, (ub4) 1,
                      (ub4) OCI_FETCH_NEXT, (ub4) OCI_DEFAULT);
                        if (r == OCI_SUCCESS) {
                             success_flag = 1;
                        else if (r == OCI_SUCCESS_WITH_INFO) {
                             success_flag = 1;
                        else {
                             if (r != OCI_NO_DATA) {
                                  checkerr(err, r, (text*)err_msg);
                                  success_flag = 0;
                                  sprintf(sockwrite, "%s", NO_JOB);
                                  Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                                  Readline_r(myfd, sockread, 255);
                                  continue;
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        OCIHandleFree((dvoid *) slcth2, (ub4) OCI_HTYPE_STMT);
                        count = conv_attempts_cnt;
                        count++;
                        /*   Updating conv_attemtpts_cnt for the current job  */
                        if (OCIHandleAlloc((dvoid *) env, (dvoid **) &updth,
                      (ub4) OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0)) {
                             checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r=OCIStmtPrepare(updth, err, (text*)(void*)update_single,
                      (ub4) strlen((char *) update_single), (ub4) OCI_NTV_SYNTAX,
                      (ub4) OCI_DEFAULT))) {
                             checkerrr(err, r, (text*)err_msg);
                             OCIHandleFree((dvoid *) updth, (ub4) OCI_HTYPE_STMT);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIBindByPos(updth, &bnd2hp, err, (ub4) 1, &count,
                         sizeof(count), SQLT_INT, (dvoid *) 0, (ub2 *) 0,
                         (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT))){
                         checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIBindByPos(updth, &bnd3hp, err, (ub4) 2, &holdid,
                         sizeof(holdid), SQLT_INT, (dvoid *) 0, (ub2 *) 0,
                         (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT))){
                         checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIStmtExecute(svc, updth, err, (ub4) 1, (ub4) 0,
                         (CONST OCISnapshot *) 0, (OCISnapshot *) 0,
                         (ub4) OCI_DEFAULT))){
                             checkerrr(err, r, (text*)err_msg);
                             OCIHandleFree((dvoid *) updth, (ub4) OCI_HTYPE_STMT);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r=OCIHandleAlloc((dvoid *) env, (dvoid **) &comm,
                         (ub4) OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0))) {
                             checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r=OCIStmtPrepare(comm, err, (text*)(void*)stmt,
                         (ub4) strlen((char *) stmt),
                         (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))) {
                             checkerrr(err, r, (text*)err_msg);
                             OCIHandleFree((dvoid *) comm, (ub4) OCI_HTYPE_STMT);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r=OCIStmtExecute(svc, comm, err, (ub4) 1,
                      (ub4) 0, (CONST OCISnapshot *) 0, (OCISnapshot *) 0,
                      (ub4) OCI_DEFAULT))) {
                             checkerrr(err, r, (text*)err_msg);
                             OCIHandleFree((dvoid *) comm, (ub4) OCI_HTYPE_STMT);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        OCIHandleFree((dvoid *) comm, (ub4) OCI_HTYPE_STMT);
                        OCIHandleFree((dvoid *) updth, (ub4) OCI_HTYPE_STMT);
                        if ((r = OCISessionEnd(svc, err, ses, OCI_DEFAULT))) {
                             checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIServerDetach(srv, err, OCI_DEFAULT))) {
                             checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIHandleFree((dvoid*) ses, (ub4) OCI_HTYPE_SESSION))) {
                             checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIHandleFree((dvoid*) svc, (ub4) OCI_HTYPE_SVCCTX))) {
                             checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIHandleFree((dvoid*) srv, (ub4) OCI_HTYPE_SERVER))) {
                             checkerrr(err, r, (text*)err_msg);
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        if ((r = OCIHandleFree((dvoid*) err, (ub4) OCI_HTYPE_ERROR))) {
                             oci_error = 1;
                             cleanup();
                             success_flag = 0;
                             sprintf(sockwrite, "%s", NO_JOB);
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             continue;
                        hold_filename = strtok_r(filename, " ", &progress);
                        strcpy(filename,hold_filename);
                        strcpy(tif_filename, filename);
                    hold_tiffile = strtok_r(tif_filename, ".", &progress);
                        strcpy(tif_filename, hold_tiffile);
                        strcat(tif_filename, ".tif");
                        hold_filepath = strtok_r(filepath, " ", &progress);
                        strcpy(filepath, hold_filepath);
                        strcpy(return_filepath, filepath);
                        strcat(return_filepath, "/");
                        strcat(return_filepath, filename);
                        log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                        log4c_appender_set_udata(myappender, log_fd);
                        mylog_log("DjsMaster", LOG4C_PRIORITY_DEBUG,
                   " [1000][id %d]  Image %s located in %s will be converted to image filename %s ",
                   holdid, tif_filename, filepath, filename);     
                        if (tif_filename == NULL) {
                             log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                             log4c_appender_set_udata(myappender, log_fd);
                             mylog_log("DjsMaster", LOG4C_PRIORITY_WARN,
                      " [1001][id %d]  No file to convert. No file name associated with the job",
                      holdid);     
                   sprintf(sockwrite, "%s", NO_JOB);
                   log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                             log4c_appender_set_udata(myappender, log_fd);
                             mylog_log("DjsMaster", LOG4C_PRIORITY_NOTICE,
                      " [1000][id %d] No job to perform. Writing to %d %s",
                      holdid, (int)pthread_self(), sockwrite);     
                             Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                             Readline_r(myfd, sockread, 255);
                             if ( count <= max_failure ) {
                                  success_flag = 1;
                      reprocess_flag = 1;
                                  goto reprocess;
                             else {
                                  success_flag = 0;
                                  continue;
                             //continue;
                        strcpy(filepath_full, filepath);
                        strcat(filepath_full, "/");
                        strcat(filepath_full, tif_filename);
                        if (stat(filepath_full, &filebuf) < 0) {
                   log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                           log4c_appender_set_udata(myappender, log_fd);
                             mylog_log("DjsMaster", LOG4C_PRIORITY_WARN,
                      " [1002][id %d]  Could not stat the file %s. Nothing to send to %d ",
                      holdid, filepath_full, (int)pthread_self());     
                           sprintf (sockwrite, "%s", NO_JOB);
                   log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                             log4c_appender_set_udata(myappender, log_fd);
                             mylog_log("DjsMaster", LOG4C_PRIORITY_NOTICE,
                      " [1000][id %d] No job to perform. Writing to %d %s",
                      holdid, (int)pthread_self(), sockwrite);     
                           Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                   Readline_r(myfd, sockread, 255);
                             if ( count <= max_failure ) {
                                  success_flag = 1;
                      reprocess_flag = 1;
                                  goto reprocess;
                             else {
                                  success_flag = 0;
                                  continue;
                        //continue;
                        datasize = (int)filebuf.st_size;
                        sprintf(s_resolution, "%d", resolution);
                        sprintf(s_format, "%d", format_cd);
                        strcpy(conv_details, "./conv.sh:");
                        strcat(conv_details, tif_filename);
                        strcat(conv_details, ":");
                        strcat(conv_details, s_resolution);
                        strcat(conv_details, ":");
                        strcat(conv_details, s_format);
                        log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                        log4c_appender_set_udata(myappender, log_fd);
                        mylog_log("DjsMaster", LOG4C_PRIORITY_NOTICE,
                   " [1000][id %d] Writing to socket all conversion details for %d ",
                   holdid, (int)pthread_self());     
                        sprintf(sockwrite, "%d=%s%%%s%%%d%%%s\n", id, conv_details,
                      tif_filename, datasize, return_filepath);
                        log4c_appender_set_type(myappender, log4c_appender_type_get("stream"));
                        log4c_appender_set_udata(myappender, log_fd);
                        mylog_log("DjsMaster", LOG4C_PRIORITY_DEBUG, " [1000][id %d] Sending %s",
                      holdid, sockwrite);     
                        Writen_r(myfd, sockwrite, (int)strlen(sockwrite));
                        if ((datafd = open(filepath_full, O_RDONLY)) < 0) {
                   close(myfd);
                     log4c_appender_set_type(myappender,

    I wonder how OCI_OBJECT will fix it as the call to OCIServerAttach is the culprit in the update_Tables function.

  • Huge memory leaks in using PL/SQL tables and collections

    I have faced a very interesting problem recently.
    I use PL/SQL tables ( Type TTab is table of ... index by binary_integer; ) and collections ( Type TTab is table of ...; ) in my packages very widely. And have noticed avery strange thing Oracle does. It seems to me that there are memory leaks in PGA when I use PL/SQL tables or collections. Let me a little example.
    CREATE OR REPLACE PACKAGE rds_mdt_test IS
    TYPE TNumberList IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    PROCEDURE test_plsql_table(cnt INTEGER);
    END rds_mdt_test;
    CREATE OR REPLACE PACKAGE BODY rds_mdt_test IS
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    x TNumberList;
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    x(indx) := indx;
    END LOOP;
    END;
    END rds_mdt_test;
    I run the following test code:
    BEGIN
    rds_mdt_test.test_plsql_table (1000000);
    END;
    and see that my session uses about 40M in PGA.
    If I repeat this example in the same session creating the PL/SQL table of smaller size, for instance:
    BEGIN
    rds_mdt_test.test_plsql_table (1);
    END;
    I see again that the size of used memory in PGA by my session was not decreased and still be the same.
    The same result I get if I use not PL/SQL tables, but collections or varrays.
    I have tried some techniques to make Oracle to free the memory, for instance to rewrite my procedure in the following ways:
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    x TNumberList;
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    x(indx) := indx;
    END LOOP;
    x.DELETE;
    END;
    or
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    x TNumberList;
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    x(indx) := indx;
    END LOOP;
    FOR indx in 1 .. cnt LOOP
    x.DELETE(indx);
    END LOOP;
    END;
    or
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    x TNumberList;
    empty TNumberList;
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    x(indx) := indx;
    END LOOP;
    x := empty;
    END;
    and so on, but result was the same.
    This is a huge problem for me as I have to manipulate collections and PL/SQL tables of very big size (from dozens of thousand of rows to millions or rows) and just a few sessions running my procedure may cause server's fall due to memory lack.
    I can not understand what Oracle reseveres such much memory for (I use local variables) -- is it a bug or a feature?
    I will be appreciated for any help.
    I use Oracle9.2.0.1.0 server under Windows2000.
    Thank you in advance.
    Dmitriy.

    Thank you, William!
    Your advice about using DBMS_SESSION.FREE_UNUSED_USER_MEMORY was very useful. Indeed it is the tool I was looking for.
    Now I write my code like this
    declare
    type TTab is table of ... index binary_integer;
    res TTab;
    empty_tab TTab;
    begin
    res(1) := ...;
    res := empty_tab;
    DBMS_SESSION.FREE_UNUSED_USER_MEMORY;
    end;
    I use construction "res := empty_tab;" to mark all memory allocated to PL/SQL table as unused according to Tom Kyte's advices. And I could live a hapy life if everything were so easy. Unfortunately, some tests I have done showed that there are some troubles in cleaning complex nested PL/SQL tables indexed by VARCHAR2 which I use in my current project.
    Let me another example.
    CREATE OR REPLACE PACKAGE rds_mdt_test IS
    TYPE TTab0 IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    TYPE TRec1 IS RECORD(
    NAME VARCHAR2(4000),
    rows TTab0);
    TYPE TTab1 IS TABLE OF TRec1 INDEX BY BINARY_INTEGER;
    TYPE TRec2 IS RECORD(
    NAME VARCHAR2(4000),
    rows TTab1);
    TYPE TTab2 IS TABLE OF TRec2 INDEX BY BINARY_INTEGER;
    TYPE TStrTab IS TABLE OF NUMBER INDEX BY VARCHAR2(256);
    PROCEDURE test_plsql_table(cnt INTEGER);
    PROCEDURE test_str_tab(cnt INTEGER);
    x TTab2;
    empty_tab2 TTab2;
    empty_tab1 TTab1;
    empty_tab0 TTab0;
    str_tab TStrTab;
    empty_str_tab TStrTab;
    END rds_mdt_test;
    CREATE OR REPLACE PACKAGE BODY rds_mdt_test IS
    PROCEDURE test_plsql_table(cnt INTEGER) IS
    BEGIN
    FOR indx1 IN 1 .. cnt LOOP
    FOR indx2 IN 1 .. cnt LOOP
    FOR indx3 IN 1 .. cnt LOOP
    x(indx1) .rows(indx2) .rows(indx3) := indx1;
    END LOOP;
    END LOOP;
    END LOOP;
    x := empty_tab2;
    dbms_session.free_unused_user_memory;
    END;
    PROCEDURE test_str_tab(cnt INTEGER) IS
    BEGIN
    FOR indx IN 1 .. cnt LOOP
    str_tab(indx) := indx;
    END LOOP;
    str_tab := empty_str_tab;
    dbms_session.free_unused_user_memory;
    END;
    END rds_mdt_test;
    1. Running the script
    BEGIN
    rds_mdt_test.test_plsql_table ( 100 );
    END;
    I see that usage of PGA memory in my session is close to zero. So, I can judge that nested PL/SQL table indexed by BINARY_INTEGER and the memory allocated to it were cleaned successfully.
    2. Running the script
    BEGIN
    rds_mdt_test.test_str_tab ( 1000000 );
    END;
    I can see that plain PL/SQL table indexed by VARCHAR2 and memory allocated to it were cleaned also.
    3. Changing the package's type
    TYPE TTab2 IS TABLE OF TRec2 INDEX BY VARCHAR2(256);
    and running the script
    BEGIN
    rds_mdt_test.test_plsql_table ( 100 );
    END;
    I see that my session uses about 62M in PGA. If I run this script twice, the memory usage is doubled and so on.
    The same result I get if I rewrite not highest, but middle PL/SQL type:
    TYPE TTab1 IS TABLE OF TRec1 INDEX BY VARCHAR2(256);
    And only if I change the third, most nested type:
    TYPE TTab0 IS TABLE OF NUMBER INDEX BY VARCHAR2(256);
    I get the desired result -- all memory was returned to OS.
    So, as far as I can judge, in some cases Oracle does not clean complex PL/SQL tables indexed by VARCHAR2.
    Is it true or not? Perhaps there are some features in using such way indexed tables?

  • Mountain Lion memory leak while asleep?

    My early 2011 MBP started to randomly crash after installing ML and Safari would take an age to load, endless spinning wheels, apps not opening etc etc. So did a Boot sector permissions verify and repair (2 very minor mismatched files) then a reset of PRAM and SMC which has cured the crashes and improved things from startup and removed old Sophos and installed new ML version.
    But the biggest problem is when waking from sleep. I have a memory tool in my status bar which usually shows anything between 3.5 - 5gb free RAM under normal conditions (I have 8gb installed) and that is what will be showing when I put it to sleep. When waking I get constant spinning wheels, the clock is frozen (spinning wheel will start from Time Capsule icon all the way to Spotlight) and the RAM tool is displaying 45mb or less of free RAM. It takes at least 5 minutes for RAM to creep back up to 150mb or so when things will then start to become usable. But at this point I won't even get an internet connection until I use the memory tool to fee up more RAM. I've read of other problems regarding wireless connectivity when waking up but I'm using an ethernet connection. Once everything has calmed down and memory settled down MBP works flawlessly with no crashing and all apps working fine and there is a speed improvement but I shouldn't have to wait up to 10 minutes for my MBP to be usable. I did notice that when launching Sys Prefs the Time Machine tab caused it to freeze so could this have something to do with that?
    But what could be bleeding off the RAM while it's asleep?
    I'm so ****** off at this, never a problem with SL and definitely wishing I'd waited before doing this upgrade, it reminds me of my Windows Vista days!!!

    Hello.
    In my Macbook Pro 4GB RAM recently note memory leak when I opened Safari even with 1 or two windows open without refresh the web content.
    In Activity monitor could see consume Web Content the Safari Spend more the 2 GB RAM (Memory Real become Memory Inactive)
    Solution: Disable All Extensions and probe one to one. Finding that Fastesttube Extension was responsible.
    Check this Info
    http://atylmo.wordpress.com/2011/06/...d-fastesttube/
    Best Regards

  • Error while executing the .sql file

    Hello,
    Every time when i execute the below plsql it's keep throwing the error message as show in below output, this happens even when i manually create the trigger before executing the .sql file of all the below statements, can you please correct me what i am doing wrong here. Thank you.
    DROP TABLE FCSDWH.REF_DATA_MASTER;
    CREATE TABLE FCSDWH.REF_DATA_MASTER
    REF_DATA_MASTER_ID                      NUMBER PRIMARY KEY,
    DESCRIPTION                                     VARCHAR2(255 CHAR),
    CREATE_ID                                       VARCHAR2(10 CHAR),
    CREATE_DT                                       DATE,
    LST_UPD_ID                                      VARCHAR2(10 CHAR),
    LST_UPD_DT                                      DATE,
    ACT_STRT_DT                                     DATE,
    ACT_END_DT                                      DATE
    TABLESPACE FCSDWH
    STORAGE(INITIAL 50K);
    DROP SEQUENCE FCSDWH.REF_DATA_MASTER_SEQ;
    CREATE SEQUENCE FCSDWH.REF_DATA_MASTER_SEQ START WITH 1 INCREMENT BY 1;
    DROP TRIGGER "FCSDWH.REF_DATA_MASTER_TRG";
    CREATE OR REPLACE TRIGGER FCSDWH.REF_DATA_MASTER_TRG
    BEFORE INSERT ON FCSDWH.REF_DATA_MASTER
    FOR EACH ROW
    BEGIN
    SELECT FCSDWH.REF_DATA_MASTER_SEQ.NEXTVAL INTO :NEW.REF_DATA_MASTER_ID FROM DUAL;
    END;
    /Output:
    SQL> @/home/smadala/REF_DATA_MASTER.SQL
    Table dropped.
    Table created.
    Sequence dropped.
    Sequence created.
    DROP TRIGGER "FCSDWH.REF_DATA_MASTER_TRG"
    ERROR at line 1:
    ORA-04080: trigger 'FCSDWH.REF_DATA_MASTER_TRG' does not exist
    Trigger created.
    SQL>

    The trigger is "attached" to the table so when you drop the table the trigger goes as well.
    John

Maybe you are looking for

  • Can you create an iTunes account without a credit card or PayPal?

    Hello, I have been wanting to get a separate iTunes account from my brother because he spends all of my money. The only problem is, I can't continue without a Credit Card or PayPal when I go to sign up for a new account. My parents refuse to let me u

  • In what order what components needed to be configured in ODI?

    I will be migrating data from TXT files to Oracle 10g. In what order what components/objects (e.g. Project, Models, topology, data store, metadata, schema etc) needed to be configured in ODI? This will help me go through ODI manual in a logical order

  • Sending email  with message body contain data  in table   displayed in one

    Hi, I have one jsp page where I am dispalying the table data retrieved fron database. Now i am trying to send this table as message body of the mail to the user.I am doing same stuff last from six days but unable to send such data. Please help me Sir

  • Business Blueprint

    Hello I was reading an article on SAP and came across the word business blueprint.Is this something like your functional specifications or entirely different from that ? Googled the word and came across a few blueprints but I am unable to co-relate i

  • MDM with ECC6.0

    Hi all, I know it is possible to access MDM catalogs via ECC6.0 (so without SRM) however my question is whether it is possible to fill certain backend business documents (network, internal order etc.) with content from the MDM internal catalog(s). We