views:

479

answers:

1

Hello, i have a PL/SQL program which do a query to an AS400 database through Transparent Gateway. Sometimes the AS400 not responds to the query (may be network problems )and the PL/SQL program hangs.

Is there any method to set a timeout to the Oracle query so that when certain amount of time passes an exception is risen?

+3  A: 

Have you tried setting the HS_FDS_CONNECT_PROPERTIES parameter in the AS400 Transparent Gateway initialisation file?

For a timeout of 2 minutes:

HS_FDS_CONNECT_PROPERTIES="timeout='120'"

Another more general option for setting a query timeout is to create a profile and assign it to the user running your query.

A resource profile can be used to set limits on all sorts of usage in any particular session - one resource limit available is connection time.

For example, you could create a profile as400_tg_profile and assign it a maximum connection time of 2 minutes:

create profile as400_tg_profile limit connect_time 2;

... then you could assign this profile to the user running the query:

alter user as400_tg_user profile as400_tg_profile;

There are lots of options on creating a profile and there are many ways to assign a profile to a particular user so you should read through the documentation.

You could also look into using Oracle Resource Manager creating resource groups and resource profiles if you need to dynamically assign particular resource limits - this gives you fine-grained control of resources for individual sessions.

The Oracle documentation is really good on this - for starters, give this a read:

http://www.oracle.com/technology/products/manageability/database/pdf/twp03/twp_oracle%20database%2010g%20resource%20manager.pdf

For more detail:

http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/dbrm.htm#ADMIN027

This is one of those bits of functionality that's easier to use in Enterprise Manager, but a quick PL/SQL example is given in:

http://www.dba-oracle.com/job_scheduling/resource_manager.htm

Nick Pierpoint
how can i set these parameter? in the Transparent gateway configuration?
Telcontar
Yes - that's right. I don't know the name of the file for AS400. For SQL Server it would be inittg4msql.ora so I guess something like inittg4as400.ora.
Nick Pierpoint
Any luck? Is the timeout working?
Nick Pierpoint
I don't have DBA permissions, i've notificated your solution to the DBA, when he implement it i tell you and accept the answer. Anyway i have DBA permisions on an old oracle DB, i'm going to try to start up the system (it's stoped) and try your solution by myself.
Telcontar
i've tried on the old system but it doesn't work, but i think the problem is that in the old system we connect to the AS400 by ODBC using HS_ODBC, and maybe your parameter can only work by transparent gateway. When the current DBA tries it (a bit lazy...) i notify you.
Telcontar
You should tell your DBA to sort it out - this is prime DBA territory - and put in an oracle support call to Metalink.
Nick Pierpoint
Another more general option is for your DBA to create resource profiles. Among many other resource limits, you can set a query timeout for any connection using a particular resource profile. I'll update my answer with some details.
Nick Pierpoint
Thx for the atention, i work in a big bank of Spain, and there is a lot of bureaucracy to make any change, and our DBAs have assigned lots of systems,many more critic than ours. i'm going on with your suggestions by myself where i can.On your last comment... the user running the query is the same that is executing the plsql process, i cant limit it's connection time (or can in execute a query with another user wait it's termination or exception?), i will search if i can limit the connection time of the use of a dblink.
Telcontar
If you use "Resource Manager" instead of profiles you can get quite fine-grained controlled of resources. You can set different resource limits for the same user depending on the particular session. I find that Resource Manager is one of those things that's easier to do in Enterprise Manager than directly in pl/sql. I'll add a link or two to my answer.
Nick Pierpoint
Thx a lot, i will study the links and the docs, we use Oracle 9.2 (next year we are going to migrate to Oracle 11). I have de Oracle 9.2 Library, i will look inside becaouse may by changes between versions. I accept your answer, it's the minimun i can do.
Telcontar