Home > Articles > Data > DB2

This chapter is from the book

This chapter is from the book

DB2 Instances

A DB2 instance is a logical database server environment. DB2 UDB databases are created within DB2 instances on the database server. The creation of multiple instances on the same physical server provides a unique database server environment for each instance. For example, you can maintain a test environment and a production environment on the same machine.

Each instance has an administrative group, which is an OS level group, associated with it. This administrative group must be defined in the instance configuration file known as the database manager configuration file. Members of this group have DB2 SYSADM authority for that instance.

As explained in the installation section, the installation program (db2setup) can be used to create a DB2 instance. This is the recommended method for creating instances. However, instances may be created (or dropped) after installation, and another GUI, db2isetup, is available for instance-level creation after installation of the DB2 software (it is essentially db2setup without the software installation dialogues). Remember that root authority is necessary for creating instances.

Creating a DB2 Instance

Before executing the command to create an instance (db2icrt), an instance group and an instance-owning userid must be created within the OS (db2isetup can be used to create the users/groups and the instance via a supplied GUI).

To create a user, a group, and a DB2 instance in Solaris, you must have Solaris system administrator privileges (root authority). If you use the DB2 installation program (db2setup) to install the product, the group, user, and instance can be created for you. The db2isetup GUI will also create users and groups for you.

If you don't use the db2setup/db2isetup program or want to create an instance later, you need to create a DB2 instance manually using the following steps:

  1. Create a group if one is not already defined: groupadd db2grp2

  2. Create a user who will be the instance owner and is a member for the group created in the previous step, with a secondary membership in the group defined for the administration process: useradd -d /export/home/db2inst2 -g db2grp2 –G db2asgrp db2inst2

    The new user db2inst2 remains locked until the passwd command is executed, and the password is set: passwd db2inst2

  3. Execute the following DB2 command to create an instance: db2icrt -u db2fenc2 db2inst2

You must specify a user id in the instance creation command using the –u parameter, to tell DB2 where to run user-defined functions in a separate address space. For security purposes, and to prevent poorly coded functions from crashing DB2, it is recommended that you specify a user in which fenced UDFs will execute in a different address space than those of the DB2 instance owner. You must also choose the memory usage of the instance at instance creation time using the –w (or wordsize) option on the db2icrt command. For example:

db2icrt –w 64 –u db2fenc2 db2inst2

would create the instance db2inst2 using a 64-bit memory model.

One of the files placed in the instance owner's home directory under the sqllib subdirectory is a DB2 setup (profile) file. Depending on the type of shell the user is using, the file will be called db2profile (Bourne or Korn shell) or db2cshrc (C shell). This profile must be executed before using the DB2 instance. It is added to the user's login profile to ensure that it is executed when the user enters the system.

When the instance has been created, you can view the configuration file for the instance, as shown in Figure 2.37.

02fig37.jpgFigure 2.37. The Instance Configuration

Starting a DB2 Instance

Now that we have created a DB2 instance, we must initialize or start the instance. The process of starting an instance is similar to starting a network file server; until the instance is started, the clients will not be able to access the databases on the server.

The command to start a DB2 instance is db2start. This command will allocate all the required DB2 resources for the instance on the server. These resources include memory and communications support (Figure 2.38).

02fig38.jpgFigure 2.38. Starting an Instance with db2start Command

If you want the instance to be started automatically every time the system boots, you can set this by issuing the following command:

db2set -i db2inst2 DB2AUTOSTART=TRUE

When, using the Custom install option of db2setup, choose the option to automatically start the instance. In this example, db2inst2 is the instance name.

Stopping a DB2 Instance

The command to stop the current database manager instance is db2stop.Messages are sent to standard output indicating the success or failure of the db2stop command. The instance cannot be stopped, however, if there are any active databases. To stop an instance with active databases, first try to deactivate the databases, then issue the db2stop command. To force the instance to stop, terminating all user connections, issue the db2stop force command, as illustrated in Figure 2.39.

02fig39.jpgFigure 2.39. Stopping an Instance with db2stop Command

  • + Share This
  • 🔖 Save To Your Account