Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle connection/query timeout

Is it possible to specify connection/query timeout for the Oracle database queries? Either on Oracle side or in Oracle's JDBC driver (10.2.0.4)? So, that Java client just got an error back after, let's say, 2 minutes instead of waiting until Oracle finishes executing the query?

like image 805
Andrey Adamovich Avatar asked Sep 07 '09 10:09

Andrey Adamovich


People also ask

How do you set a timeout in SQL query?

Using SQL Server Management StudioIn Object Explorer, right-click a server and select Properties. Click the Connections node. Under Remote server connections, in the Remote query timeout box, type or select a value from 0 through 2,147,483,647 to set the maximum number seconds for SQL Server to wait before timing out.

How do you resolve ORA 12170 TNS Connect timeout occurred?

To avoid seeing error ORA-12170, use a static IP address rather than a DHCP for assigning an IP address of the host. In one case, the server may have shut down because the connection establishment or communication with a client did not complete in an allotted time interval.

What is Oracle session timeout?

You can set the maximum number of minutes after which Oracle Responsys logs out inactive users (i.e. session timeout). You can choose a session timeout of 15 minutes, 30 minutes, or 60 minutes.


3 Answers

If you are executing the query in the context of a transaction, the transaction timeout value of the JTA transaction monitor will be the determinant to query timeout. The configuration for this depends from one application server to another.

At an individual query level (in the absence of a JTA transaction monitor), the setQueryTimeout method can be used to set the timeout on the execution of a Statement/PreparedStatement/CallableStatement object.

Update

setQueryTimeout is not to be relied on, although it works (atleast from a J2SE client). It works via the JDBC driver performing a full round-trip to the Oracle database server. Then, it is upto the database to halt execution of the query. Don't rely on it for time critical applications.

like image 128
Vineet Reynolds Avatar answered Oct 10 '22 19:10

Vineet Reynolds


Have a look at Oracle profiles. This allows you to specify several limits at the database level. One of them is a maximum CPU time per query.

If you have queries running for more than 2 minutes on a regular basis you might want to do some tuning of your queries first.

like image 30
Rene Avatar answered Oct 10 '22 19:10

Rene


According to http://www.javamonamour.org/2012/09/oraclenetconnecttimeout.html

oracle.net.READ_TIMEOUT for jdbc versions < 10.1.0.5 oracle.jdbc.ReadTimeout for jdbc versions >=10.1.0.5

So if you are using a JDBC driver version 10.1.0.5 or higher, then oracle.jdbc.ReadTimeout is the correct property.

like image 29
Srini Karthikeyan Avatar answered Oct 10 '22 19:10

Srini Karthikeyan