Setting the default instance when using multiple Db2 copies (Windows)
The DB2INSTANCE environment is set according to the Db2® copy that your environment is currently set up to use. If you do not set it explicitly to an instance in the current copy, it defaults to the default instance that is specified with the DB2INSTDEF profile registry variable.
About this task
Use the following guidelines to set the default instance when using multiple Db2 copies:
- If DB2INSTANCE is not set for a particular Db2 copy, then the value
of DB2INSTDEF is used for that Db2 copy. This means:
- If DB2INSTANCE=ABC and DB2INSTDEF=XYZ, ABC is the value that is used
- If DB2INSTANCE is not set and DB2INSTDEF=XYZ, XYZ is used
- If DB2INSTANCE is not set and DB2INSTDEF is not set, then any application or command that depends on a valid DB2INSTANCE will not work.
- You can use either the db2envar.bat command or the
db2SelectDB2Copy API to switch Db2 copies.
Setting all the environment variables appropriately (for example, PATH,
INCLUDE, LIB, and DB2INSTANCE) will
also work, but you must ensure that they are set properly.Note: Using the db2envar.bat command is not quite the same as setting the environment variables. The db2envar.bat command determines which Db2 copy it belongs to, and then adds the path of this Db2 copy to the front of the PATH environment variable.
When there are multiple Db2 copies on the same computer, the PATH environment variable can point to only one of them: the DEFAULT COPY. For example, if DB2COPY1 is under c:\sqllib\bin and is the default copy; and DB2COPY2 is under d:\sqllib\bin. If you want to use DB2COPY2 in a regular command window, you would run d:\sqllib\bin\db2envar.bat in that command window. This adjusts the PATH (and some other environment variables) for this command window so that it picks up binaries from d:\sqllib\bin.
- DB2INSTANCE is only valid for instances under the Db2 copy that you are using. However, if you switch copies by running the db2envar.bat command, DB2INSTANCE is updated to the value of DB2INSTDEF for the Db2 copy that you switched to initially.
- DB2INSTANCE is the current Db2 instance that is used by applications that are executing in that Db2 copy. When you switch between copies, by default, DB2INSTANCE is changed to the value of DB2INSTDEF for that copy. DB2INSTDEF is less meaningful on a one copy system because all the instances are in the current copy; however, it is still applicable as being the default instance, if another instance is not set.
- All global profile registry variables are specific to a Db2 copy, unless you
specify them using
SET VARIABLE=variable_name.