Welcome back to my blog as I continue our examination of the new features of DB2 9 for z/OS. Today we will look at the new UPDATE SCHEMA capability of the CATMAINT utility.
Have you ever wanted to make a global change to a schema, owner, creator, or VCAT name for your DB2 objects? Well, you can do that with CATMAINT in DB2 9 for z/OS using new UPDATE SCHEMA options.
There are three (3) new options added to CATMAINT, namely:
- SCHEMA: Owner, creator and schema names can be changed using this option.
- VCAT: Indexes, table spaces and storage groups can be altered to use a different ICF or VCATNAME using this option.
- OWNER: Ownership of objects can be changed to a role using this option.
To use any of these options you must be in DB2 9 NFM and have Install SYSADM authority.
How does it work? Well, let’s take a look at a few examples, starting with the SCHEMA option. To rename the owner, creator, and schema of database objects, plan, and packages, we will run CATMAINT specifying the SCHEMA SWITCH option. This process updates every owner, creator or schema name in the catalog and directory that matches the specified schema_name value. Importantly, all GRANTs that were made by or received by the original owner are changed to the new owner. Ownership of objects is not changed if the owner is a role.
So if we want to change OLDNAME to NEWNAME we can code the following CATMAINT job:
CATMAINT UPDATE
SCHEMA SWITCH(OLDNAME, NEWNAME)
You can change multiple names by repeating the SWITCH keyword, but you are not allowed to code the same name more than once.
Be aware though, when the schema name of an object is changed, any plans or packages that are dependent on the object are invalidated. If you do not REBIND those plans and packages an automatic REBIND will occur the next time you execute any of those programs.
Here is another example, this time for the VCAT option. To change the VCAT name that is used by storage groups or by index spaces and table spaces, we can run CATMAINT specifying the VCAT SWITCH option. This option is similar to using the ALTER TABLESPACE USING VCAT statement for changing the VCAT name. You need to move the data for the affected indexes or table spaces to the data set on the new catalog in a separate step.
So if we want to change OLDVCAT to NEWVCAT we can code the following CATMAINT job:
CATMAINT UPDATE
VCAT SWITCH(OLDVCAT, NEWVCAT)
You can change multiple VCAT names by repeating the SWITCH keyword, but you cannot specify the same name more than once. There are several restrictions to this option that you should research in the IBM manuals before attempting to switch VCAT names.
The final option is the OWNER option. It is used for changing the ownership of objects from a user to a role. Roles are new in DB2 9 and are associated with a TRUSTED CONTEXT. This will be the subject of a future blog posting here on the DB2portal blog – so keep an eye out for that one soon.
For example, if we want to switch ownership of objects for OWNER1, OWNER2 and OWNER3 to a role, we can run CATMAINT as follows:
CATMAINT UPDATE
OWNER FROM(OWNER1, OWNER2, OWNER3) TO ROLE
You must be running under a trusted context with a role to run this utility. The current role will become the owner. Privileges held on the object will be transferred from the original owner to the role.
A final caveat: be sure to create backups of your DB2 Catalog and DB2 Directory before running this CATMAINT to switch SCHEMA, VCAT, or OWNER.
No comments:
Post a Comment