Abstract
Some Informix Dynamic Server (IDS) operations, such as altering a table schema, are not allowed if its partition is open in another session, which will not necessarily appear as a lock with the “onstat -k” command or in the SQL described in a previous article here. The standard method to list open partitions is the “onstat -g opn” command, which is not user friendly, and requires operating system command line access. This article describes and provides a Stored Procedure Language (SPL) function to obtain a list of sessions holding matching table names open, so you know what needs to be terminated.
Content
Examples in this article were produced using the provided “stores_demo” database in a Docker container from informix-dockerhub with Informix Dynamic Server (IDS) updated to 14.10.FC12W5.
The most common reason for a table to be open but not locked is when it is referenced by a cursor or prepared SQL statement in an application. This can be simulated as follows.
Leave the following running in a SQL session, which can be conveniently terminated by killing the “sleep” process:
At the command line, we can show that there are no locks on “customer”, but it is held open by that session:
- The above “onstat” commands can be run by any user, and do not need configuration parameter UNSECURE_ONSTAT enabled.
- Only later IDS versions include database and table names: you need “partn” from IIUG to append them for earlier versions.
Schema changes to the table will fail meanwhile:
Any change at the database level, such as to the logical logging mode, will also fail if any partition is open:
At the command line, we would need to find out what sessions were the problem by getting these in turn:
- “rstcb” (userthread address) from “onstat -g opn”;
- “sessid” (session ID) from “onstat -u”;
- details from “onstat -g ses” and “onstat -g sql”.
An easier solution is to install the following SPL function in the database of your choice:
The above does this:
- Runs “onstat -g opn” piped to an embedded “awk” script which converts the output into a pipe-delimited file.
- Reads that file via an external table and joins it to “sysmaster” tables to get session details.
- Returns the data set.
As it says in the comments at the top, it must be executed first time by a user with DBA privileges, so that the external table can be created.
The documentation page for “onstat -g opn” has this understatement: “The output might change over time and depends on your product version or fix pack.” IDS versions from 11.50 have been tested successfully. See the DOCUMENT section for example outputs from IDS 11.50 to 14.10. Earlier versions might well work but have not been tested. The embedded “awk” code does deal with these differences.
System databases are excluded. Also, only table names are returned, not index names. It is not plausible that an index might be open without the table, and table names are sufficient to determine conflicting sessions.
You can optionally specify a match on database and table name. In our first scenario, specify the table you need to alter, for example:
| session | process | username | hostname | progname | duration | dbsname | tabname |
|---|---|---|---|---|---|---|---|
| 90 | 2954 | informix | dd2cf86eb3ef | /opt/ibm/IDS/14.10.FC12W5/bin/dbaccess | 00:00:24 | stores_demo | customer |
In the second scenario, specify the database that we need to change the logical logging mode, and “systables” as that always seems to be open if anything else is:
| session | process | username | hostname | progname | duration | dbsname | tabname |
|---|---|---|---|---|---|---|---|
| 90 | 2954 | informix | dd2cf86eb3ef | /opt/ibm/IDS/14.10.FC12W5/bin/dbaccess | 00:00:24 | stores_demo | systables |
Caveats
- Run time might be several minutes on busier systems with older IDS versions.
- The code would need some changes to the SYSTEM statement for Windows.
Conclusion
Determining what is preventing you from performing table or database maintenance is challenging using only standard commands. If you can install and execute this SPL function the first time as a DBA user, others without command line access can thereafter use it to find out what they need using a simple SQL statement.
Disclaimer
Suggestions above are provided “as is” without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement.
Contact Us
If you have any questions or would like to find out more about this topic, please contact us.