Checks for read-only status of high-availability secondary servers
You can write applications to check for read-only server status, so that update operations are not attempted on read-only secondary servers.
The HCL
OneDB™ JDBC driver has extension methods to
the java.sql.Connection class that provide a way to check the HDR
secondary server's status. Users can type cast connection objects
to 'com.informix.jdbc.IfmxConnection' to access the following extension
methods.
Information obtained | Method signature | Additional information |
---|---|---|
Whether the server is read-only (a secondary server) | public boolean is ReadOnly() throws SQLException | Returns true if the active server is a secondary
server Returns an exception if a database access error occurs If ENABLE_HDRSWITCH is set to false, isReadOnly() returns the value that is initially set after the last successful HDR connection was obtained. |
Whether HDR is enabled | public boolean is HDREnabled() | Returns true if both servers in the HDR pair are
available Returns false if one of the servers is unavailable |
The type of the server (primary, secondary, or standard) | public string getHDRtype() | Returns primary or standard for a primary server,
secondary for a secondary server The database administrator can manually reset the type of the server. |
For example, you can use one of the following strategies:
- Use the isReadOnly() method before each SQL
statement that might contain an update operation. If the value of isReadOnly() is
true
, perform an appropriate action, such as sending an error message to the user or notifying the server administrator. - You call the isReadOnly() method after you establish a connection and then set a flag, like READ_ONLY, and then perform operations that are based on the flag value.
An administrator can manually switch a secondary server to a primary server to allow update operations. However, the server must be shut down in the process, which can cause uncommitted transactions to be lost.