CONNECT_TIMEOUT session environment option
Use the CONNECT_TIMEOUT session environment option of the SET ENVIRONMENT statement to set an upper limit on the number of seconds while the current session attempts to establish a connection to another database server, before an error is returned.
The CONNECT_TIMEOUT session environment option has this syntax:
Element | Description | Restrictions | Syntax |
---|---|---|---|
integer | An unsigned integer value > 0 sets
the maximum number of seconds to attempts to establish a connection
to a database server |
Must be delimited between single (' )
or double (" ) quotation marks. A setting of '0' defaults
to the setting of the CONNECT_TIMEOUT configuration
parameter. |
Literal Number as Quoted String |
Usage
- 'integer' >
0
- This value sets an upper limit on the time spent attempting to establish a connection, including (if the initial attempt fails) at least one additional attempt.
After the time limit that CONNECT_TIMEOUT specifies has been exceeded, or if no connection with another database server has been established after (integer_R + 1) attempts, for integer_R the CONNECT_RETRIES setting, the CONNECT statement or the implicit connection fails, and the database server returns an error. By setting the CONNECT_TIMEOUT and CONNECT_RETRIES session environment variables to configure your sever-to-server connection capability in the current session, you can minimize connection errors. To estimate the optimal value for CONNECT_TIMEOUT, take into account the total distance between nodes, the hardware speed, the volume of traffic, and the concurrency level of the network.
Order of precedence for time limits on connections
This is the ascending order of precedence (lowest to highest) among the methods for setting an upper limit on the amount of time that a CONNECT statement can spend attempting to connect to a database server instance:
- System default value of 60 seconds, if none of the methods below are set.
- CONNECT_TIMEOUT configuration parameter
- CONNECT_TIMEOUT client environment variable
SET ENVIRONMENT CONNECT_TIMEOUT
statement of SQL.
The CONNECT_TIMEOUT session environment option can override the setting of the client CONNECT_TIMEOUT environment variable, or of the CONNECT_TIMEOUT configuration parameter, or of the system default value, if any of these has established a time limit different from the SET ENVIRONMENT CONNECT_TIMEOUT value.
Setting session environment options for connections
The value of the CONNECT_TIMEOUT session environment option is divided by the value of the CONNECT_RETRIES session environment option to determine the maximum number of seconds between successive connection attempts, if the previous attempt of the same CONNECT statement failed to establish a connection.
SET ENVIRONMENT CONNECT_TIMEOUT '60'; SET ENVIRONMENT CONNECT_RETRIES '1';In this example, the CONNECT statement attempts to establish a connection for 60 seconds. An initial attempt is made to connect to the database server at
0
seconds.
If the CONNECT_TIMEOUT session environment option is set to the default
value of '0'
, an additional attempt to connect is
made within 60
seconds, if necessary, before connection
failure error -908
is returned. SET ENVIRONMENT CONNECT_RETRIES '3';
If
CONNECT_RETRIES is set to '3'
, up to three additional
attempts to connect to the database server are made (at 20
, 40
,
and 60
seconds, if necessary), before an error is
returned.
This 20-second interval is the result of dividing the CONNECT_TIMEOUT value by the CONNECT_RETRIES value.
'0'
,
as in this example,SET ENVIRONMENT CONNECT_TIMEOUT '0';
the database server automatically uses the setting of
the CONNECT_TIMEOUT configuration parameter.
If the CONNECT_TIMEOUT parameter is not set,
its default value of 60
seconds is used during subsequent
CONNECT statements in the session. Implicit connections with database statements
- DATABASE
- CREATE DATABASE
- DROP DATABASE
- a database server and a database,
- or a database server only,
- or a database only.
- All appropriate servers in the DBPATH setting are accessed at least once, even if the CONNECT_TIMEOUT value is exceeded. In this context, the CONNECT statement might take longer than the CONNECT_TIMEOUT time limit to return an error that indicates a connection failure, or indicating that the database was not found.
- The CONNECT_TIMEOUT value is divided among the number of database
server entries that are specified in DBPATH.
Thus, if DBPATH contains numerous servers, you
can use the SET ENVIRONMENT CONNECT_TIMEOUT statement to increase
the CONNECT_TIMEOUT value accordingly. For example, if DBPATH contains
three entries, in order to spend at least
30
seconds attempting each connection, set CONNECT_TIMEOUT to'90'
.SET ENVIRONMENT CONNECT_TIMEOUT '90';