Hi Donna,
The alter is an online schema change that does not require an outage, however it does require exclusive control of the object to make the change. Long running transactions that have not committed will block the alter. This includes DELETE, UPDATE, INSERT and SELECT. The alter DDL will wait for locks and claimers to commit or rollback for the amount of time specified by the IRLMRWT Resource Timeout zParm before it times out. Transactions that subsequently come in will queue up in a lock-wait state behind the alter. This lock-wait behavior can be observed in a monitoring tool such as Omegamon for Db2.
The Db2 command DISPLAY BLOCKERS (dbname) DETAIL, where "dbname" is the database name that contains the table, can be used to identify transactions that might block DDL. Look for transactions that have a lock or claim on the table space, table or index for the table that will be altered, then check the AGE to see how long the transaction has been holding the lock or claim. If transactions are persistently holding claims or locks for a period of time longer than the IRLMRWT setting, then the alter DDL will likely time out. SELECT only transactions are often found to be holding claims for an excessively long period of time because people do not realize a commit is required to release the claim as long as the tread is in Db2. This is a common issue with Db2 programs used by started tasks. If this type of transaction is observed, updating the program with commit logic after the SELECT SQL will often resolve the issue.
An alternative to the DISPLAY BLOCKERS Db2 command is the SYSIBMADM.BLOCKING_THREADS built-in table function which can be executed in SPUFI or from a client application.
Before executing an alter, check the list of changes that invalidate packages
Changes that invalidate packages - IBM Documentation in the IBM Db2 documentation. The alter in the provided example does not invalidate packages, however there are alters that will.
The alter will put the table space in the non-restrictive advisory reorg pending status which will be resolved by a REORG or LOAD-replace. The follow up REORG or LOAD can be done at anytime in the future. In the meantime, Db2 will keep track of the rows that existed before the alter, the rows where the new column has been updated and the rows that were inserted after the alter.
Regards,
------------------------------
STEPHEN NEWTON
------------------------------
Original Message:
Sent: Wed April 27, 2022 05:11 PM
From: Donna Stinson
Subject: ALTER TABLE ADD COLUMN
When altering a table to add a column – char(01) not null with default.
Question – does the table first need stopped at commit and started in UT status – then alter to add new column?
Or just add new column while table is in RW status?
Maybe it depends on how much the table is accessed? This is a very large table accessed by many applications on a 7x24 basis.
#Db2forz/OS