|Informix Application Development - Getting Started|
|IBM Informix Developer's Handbook|
|Embedding IBM Informix|
Identifying the Server Type
With introduction of SDS and RSS, one can have a complex topology of IDS cluster. The DBA's scripts as well as applications need find out whether the server is stand-alone, Primary or Secondary. That makes it important to understand the programmatic interfaces available to find type of server being accessed.
Following are the ways to check the type of the server :
The output from 'onstat -' prints the type of the server. For all secondary types, it will say Read-Only with the type HDR, RSS or SDS. For each of the secondary server type, there are onstat options to get more details
- 'onstat -g dri' prints HDR information
- 'onstat -g sds' prints SDS information
- 'onstat -g rss' prints RSS information
On primary, view sysha_nodes view contains all the server names with types. On all secondary type servers, it has a single row with primary server's entry.
A warning is set in SQLCA when the client connects to any secondary type server. The sqlwarn.sqlwarn6 is set to 'W'. Also the SQLSTATE is set to '01I06'. Application can look at this warning flag to determine whether the server is read-only or not.
The Informix JDBC driver provides more direct APIs to check the server status. The Connection object supports three methods isReadOnly(), isHDREnabled() and getHDRtype().
- isReadOnly() : Returns true if the active server is a secondary server
- isHDREnabled() : Returns true if both servers in the HDR pair are available. Returns false if one of the servers is unavailable.
- getHDRtype() : Returns primary or standard for a primary server, secondary for a secondary server
The C UDRs can use mi_hdr_status() API to check the type of the server where the UDR is being executed. The return value should be checked for bits MI_HDR_PRIMARY and MI_HDR_SECONDARY. These macros are defined in $INFORMIXDIR/public/milib.h
There is no direct way from the SPL or Java routines. One can query against sysmaster tables mentioned above.
IDS 11.10 supports two DBA controlled routines sysdbopen() and sysdbclose(). These procedures are run by server on the behalf of the users when the try to connect/disconnect to/from a database. One can create a sysdbopen() routine that checks the server type (using the mi_ API or sysmaster query) and restrict databases or users on secondary servers.