Home » SQL & PL/SQL » SQL & PL/SQL » connection timeout when calling an oracle plsql function from a java program (oracle 11g)
connection timeout when calling an oracle plsql function from a java program [message #587790] Tue, 18 June 2013 12:09 Go to next message
pradeep_kumar
Messages: 4
Registered: June 2013
Junior Member
Hi,

We have a daily batch job executing a oracle-plsql function. Actually the quartz scheduler invokes a java program which makes a call to the oracle-plsql function. This oracle plsql function deletes data (which is more than 6 months) from 4 tables and then commits the transaction.

This batch job was running successfully in the test environment but started failing when new data was dumped to the tables which happened 2 weeks ago (The code is supposed to go into production this week). Earlier the number of rows in each table was not more than 0.1 million. But now it is 1 million in 3 tables and 2.4 million in the other table.

After running for 3 hours, we are getting a error in java (written in the log file) "...Connection reset; nested exception is java.sql.SQLException: Io exception: Connection reset....". When the row-counts on the tables were checked, it was clear that no record was deleted from any of the tables.

Is it possible in oracle database, for the plsql procedure/function to be automatically terminated/killed when the connection is timed out and the invoking session is no longer active?

Thanks in advance,
Pradeep.
Re: connection timeout when calling an oracle plsql function from a java program [message #587791 is a reply to message #587790] Tue, 18 June 2013 12:17 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
if session terminates before COMMIT is issued, then ROLLBACK occurs.
It should NOT take more than 1 hour to DELETE a million rows.

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: connection timeout when calling an oracle plsql function from a java program [message #587793 is a reply to message #587790] Tue, 18 June 2013 12:21 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
In addition, there is no time-out in Oracle or PL/SQL.

Regards
Michel
Re: connection timeout when calling an oracle plsql function from a java program [message #587795 is a reply to message #587793] Tue, 18 June 2013 12:25 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
root cause & fix are external to Oracle DB.
Oracle is the victim; not the culprit.
Re: connection timeout when calling an oracle plsql function from a java program [message #587804 is a reply to message #587793] Tue, 18 June 2013 14:24 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Michel Cadot wrote on Tue, 18 June 2013 22:51
In addition, there is no time-out in Oracle or PL/SQL.

Regards
Michel


But Michel, what about Resource Plan Directives parameter, MAX_ESTIMATED_EXEC_TIME. Setting this parameter could be used to limit the time for which a query executes(Oracle decides the estimated time here). I guess the feature is with 9i and above.
Re: connection timeout when calling an oracle plsql function from a java program [message #587808 is a reply to message #587804] Tue, 18 June 2013 14:39 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
I hesitate to add "in short" or "roughly speaking" estimating that people will understand what I mean.
It is not the case.
Anyway, "time-out" is not the return code for this case.

You could also mentioned some advanced Net features...

Regards
Michel
Re: connection timeout when calling an oracle plsql function from a java program [message #587836 is a reply to message #587808] Tue, 18 June 2013 22:28 Go to previous messageGo to next message
pradeep_kumar
Messages: 4
Registered: June 2013
Junior Member
Thanks a lot for your quick response. More information about the environment and the code is like below:
1) oracle version is
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production

2) The plsql code is like below:
1 CREATE OR REPLACE FUNCTION f_housekeeping
2 RETURN SYS_REFCURSOR
3 BEGIN
4 DELETE FROM C WHERE psal_action_time<ADD_MONTHS(SYSDATE,-6);
5 DELETE FROM B WHERE pssl_action_time<ADD_MONTHS(SYSDATE,-6);
6 DELETE FROM A WHERE psll_login_time<ADD_MONTHS(SYSDATE,-6);
7 DELETE FROM D WHERE NOT EXISTS
8 (SELECT 'X' FROM C WHERE psal_action_id=D.psad_action_id);
9 COMMIT;
10 OPEN v_ref_cur FOR SELECT 'SUCCESS' FROM dual;
11 RETURN v_ref_cur;
12 EXCEPTION
13 WHEN OTHERS THEN
14 v_sql_errm:=SQLERRM;
15 OPEN v_ref_cur FOR SELECT 'FAILURE' FROM dual;
16 RETURN v_ref_cur;
17* END f_housekeeping;
18/

3) There are no indexes on the columns used in the WHERE clause. (However there is primary key defined on the tables A,B,C and no key is defined on the table D). We did not create indexes on the columns used in the WHERE clause because these indexes would be used by the batch job alone. Since it is a batch job, it can run for a few hours. That was the thought.

Thanks,
Pradeep.
Re: connection timeout when calling an oracle plsql function from a java program [message #587839 is a reply to message #587836] Wed, 19 June 2013 00:01 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
13 WHEN OTHERS THEN
14 v_sql_errm:=SQLERRM;
15 OPEN v_ref_cur FOR SELECT 'FAILURE' FROM dual;
16 RETURN v_ref_cur;


Remove that and maybe you will know if there is a problem at Oracle side.
Read WHEN OTHERS.

Regards
Michel
Re: connection timeout when calling an oracle plsql function from a java program [message #587844 is a reply to message #587836] Wed, 19 June 2013 00:12 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
@Pradeep_kumar,

Few things should be clear to go in correct direction to get the resolution:-

1. Do you mean earlier the batch process took less time, and after addition of new data the process time has increased?
2. Do you find any errors in DB? (like you are logging those errors or not.)
3. Is this code you use in production environment? The exception block seems like an amateur version.
4. In terms of number of rows you cannot measure anything. Talk in terms of size of the tables.
5. What is the rollback segment tablespace allocated? You do a commit after a lot of delete operations I see.
-- While the transactions are in progress, and if the rollback segment is "full". And since there is a transaction that is not committed with data in the rollback segment "blocks" you cannot reuse those blocks. Next oracle tries to extend, but the tablespace is full, hence it fails to extend.

[Updated on: Wed, 19 June 2013 00:16]

Report message to a moderator

Re: connection timeout when calling an oracle plsql function from a java program [message #587985 is a reply to message #587844] Wed, 19 June 2013 12:21 Go to previous messageGo to next message
pradeep_kumar
Messages: 4
Registered: June 2013
Junior Member
Hi,

Please find my response below:
1. Do you mean earlier the batch process took less time, and after addition of new data the process time has increased?
yes

2. Do you find any errors in DB? (like you are logging those errors or not.)
We are not doing any logging in the PL/SQL procedure and the audit feature on procedures is also not enabled. The only error that is captured is connection timeout error returned to the calling java program.

3. Is this code you use in production environment? The exception block seems like an amateur version.
We wanted to keep the plsql code as simple as possible so that once it goes to maintenance phase, a java developer with basic knowledge of plsql should be able to modify the code. Yes, this code is not yet in production but it will go to production this week-end.

4. In terms of number of rows you cannot measure anything. Talk in terms of size of the tables.
size of each table is approximately 8 MB

5. What is the rollback segment tablespace allocated? You do a commit after a lot of delete operations I see.
-- While the transactions are in progress, and if the rollback segment is "full". And since there is a transaction that is not committed with data in the rollback segment "blocks" you cannot reuse those blocks. Next oracle tries to extend, but the tablespace is full, hence it fails to extend.
It could be the issue. We asked the DBA to check if this is the issue. He hasn't yet responded.
Thank you so much for your help.


I tried to reproduce the error in a similar environment
1) with 100,000+ rows (0.1 million rows in each table)
2) the size of each table is 8 MB.
3) When there were no primary/unique or any other constraints or any indexes on the columns, in all the tables the data older than 6 months got deleted in 9 seconds.
4) When there are primary and foreign keys but no indexes on the columns used in the WHERE clauses, in all the tables the data older than 6 months got deleted in 26.7 minutes.
5) When there are primary and foreign keys and also indexes on the columns used in the WHERE clauses, in all the tables the data older than 6 months got deleted in 26.1 minutes.


Re: connection timeout when calling an oracle plsql function from a java program [message #587989 is a reply to message #587985] Wed, 19 June 2013 13:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
We wanted to keep the plsql code as simple as possible


So why returning a ref cursor to just return a simple string?
The whole procedure is an amateur one, so many basic errors.

Regards
Michel
Re: connection timeout when calling an oracle plsql function from a java program [message #587994 is a reply to message #587989] Wed, 19 June 2013 15:33 Go to previous messageGo to next message
pradeep_kumar
Messages: 4
Registered: June 2013
Junior Member
The intention of Refcursor is if there is an error in executing the stored procedure, it will return ERROR to the java program and the java program will write the error to the log file. We are going to change it as below:
13 WHEN OTHERS THEN
14 v_sql_errm:=SQLERRM;
15 OPEN v_ref_cur FOR SELECT 'FAILURE'||v_sql_errm FROM dual;
16 RETURN v_ref_cur;
17*END f_housekeeping;
Re: connection timeout when calling an oracle plsql function from a java program [message #588004 is a reply to message #587994] Wed, 19 June 2013 23:45 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
You return either SUCCESS ro FAILURE which are just strings, so why a ref cursor and not a string? What is slmpler a string or a ref cursor?
You didn't read WHEN OTHERS, don't you?

I repeat:

Quote:
The whole procedure is an amateur one, so many basic errors.


Regards
Micjel
Re: connection timeout when calling an oracle plsql function from a java program [message #588028 is a reply to message #587994] Thu, 20 June 2013 05:17 Go to previous message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
pradeep_kumar wrote on Wed, 19 June 2013 22:33
The intention of Refcursor is if there is an error in executing the stored procedure, it will return ERROR to the java program and the java program will write the error to the log file. We are going to change it as below:
13 WHEN OTHERS THEN
14 v_sql_errm:=SQLERRM;
15 OPEN v_ref_cur FOR SELECT 'FAILURE'||v_sql_errm FROM dual;
16 RETURN v_ref_cur;
17*END f_housekeeping;


Which is an absolutely stupid thing to do. If you just get rid of all the "when others" stuff what will happen is:

- Oracle raises an exception
- The Java program will get that exception, and even when you do nothing else in Java:
- The exception will be printed to STDERR (which should go to the log file anyway)

That will include a stack trace with ALL the relevant information, like in which Java line the error happened, in which PL/SQL Line the error happened, etc...

Which is exactly what should happen. All the "handle exceptions and pass them up the chain to the caller" is ALREADY IMPLEMENTED in the Java / JDBC / PL/SQL Layers. DON'T re-invent the wheel that is already there and working perfectly in a way that makes it absolutely impossible to actually debug errors later on.
Previous Topic: Bulk Collect
Next Topic: Incorrect query result using AVG (split from hijacked topic)
Goto Forum:
  


Current Time: Wed May 21 05:09:36 CDT 2025