6.2. The DB2 DirectoriesThis section describes the DB2 directories and how they are related. Consider the following statement used to connect to the database with the alias sample: CONNECT TO sample Given only the database alias, how does DB2 know how to find the database sample? If sample resides on a remote server, how does the client know how to connect to the server? All connect information is stored in the DB2 directories. Table 6.1 lists these directories and the corresponding commands to view, insert, and delete the contents. More information about the directories and commands is available in the next sections.
Note that you cannot update an entry you entered with the catalog command. You have to delete the entry with the uncatalog command first, and then insert the new updated entry with the catalog command. 6.2.1. The DB2 Directories: An Analogy Using a BookTo understand how the DB2 directories work let's use an analogy. Above the dotted line in Figure 6.2 is the table of contents for a book called The World. This table of contents shows that the book is divided into several parts. If you jump to any of these parts, you will see a subset of the table of contents. The Resources section presents information about other books; with that information you can find a given book in a library or bookstore or on the Internet, and once you find the book, the process repeats itself where you first review the table of contents for that book and then look at its different parts. Figure 6.2. The DB2 directories: a book analogySimilarly, with DB2 directories (shown below the dotted line), whenever you issue a CONNECT TO database statement, DB2 looks for the information in the system database directory, which is equivalent to the table of contents: it shows all the databases available for you to connect to from this machine. When an entry in this directory has the type indirect, it means the database is local (it resides on the current database server). To look for more information about this local database, you can review the local database directory, which is equivalent to the subset of the table of contents. When an entry in the system database directory is remote, it means that the database resides in a different system than the current one. Thus, you need to review the node directory for information about how to access this remote server. This is similar to the Resources (or bibliography) section of a book, where information points to a different book with more information about a given topic. The Database Connection Services (DCS) directory (not shown in Figure 6.2) contains extra information required when you connect to a host database server like DB2 for OS/390, z/OS and iSeries. NOTE In this chapter host database servers like DB2 for OS/390 and z/OS and DB2 for iSeries will only be used as database servers and not as clients. See Appendix E, Setting Up Database Connectivity for DB2 UDB for z/OS and DB2 UDB for iSeries, for the connectivity setup required for using host machines as clients. 6.2.2. The System Database DirectoryAs mentioned earlier, the system database directory is like a table of contents: it shows you all the databases you can connect to from your system. The system database directory is stored in a binary file with name SQLDBDIR and is in:
You should not modify this file manually. To display the contents of the system database directory, use the list db directory command, as shown in Figure 6.3. Figure 6.3. A sample DB2 system database directoryThe system database directory shown in Figure 6.3 indicates that you can connect to three different databases from this system: MYHOSTDB, MYRMTDB, and MYLOCDB. Let's examine each of these database entries in detail starting from the bottom (Database 3 entry) to the top (Database 1 entry). The relevant fields in Database 3 entry are
The relevant fields in Database 2 entry that have not been described yet are
The relevant field in the Database 1 entry that has not been described earlier is
6.2.3. The Local Database DirectoryThe local database directory is also stored in a file called SQLDBDIR. However, this file is different from the SQLDBDIR file for the system database directory in that it resides on every drive (in Windows) or path (in Linux/UNIX) that contains a database. It contains information only for databases on that drive/path, and it is a subset of the system database directory. Use the list db directory on drive/path command to display the local database directory, as shown in Figure 6.4. Figure 6.4. A sample DB2 local database directoryFigure 6.4 shows MYLOCDB is the only database stored in H:\MYINST2. Note that MYLOCDB also showed up in the system database directory in Figure 6.3, since the local database directory is a subset of the system database directory. On Windows, the create database command can only specify a drive, not a path, where a database can be created; therefore, the command list db directory on H: should return the same output as list db directory on H:\MYINST2. On Linux/UNIX, a path can be specified with the create database command; therefore, when using the list db directory command, specify the full path. Chapter 8, The DB2 Storage Model, explains the create database command in detail. The relevant information in the entry of Figure 6.4 is:
6.2.4. The Node DirectoryThe node directory stores information about how to communicate to a remote instance where a given database resides. It is stored in a file called SQLNODIR and is in:
One important field in the node directory is the communication protocol used to communicate with the server, as several other fields are displayed depending on this entry. For example, if the node directory contains a TCP/IP entry, then other fields provided are the IP address (or host name) of the server and the service name (or port number) of the instance where the database resides. Figure 6.5 shows an example of the contents of the node directory. Figure 6.5. A sample DB2 node directoryThere are two entries in Figure 6.5. We explain the first one in detail below; the second entry has a similar explanation, and thus will not be described. Node 1 entry has these relevant fields:
NOTE Since the node directory contains the information required to connect to an instance, it is not only used by the CONNECT statement but also by the attach command as described in Chapter 5, Understanding the DB2 Environment, DB2 Instances, and Databases. 6.2.5. The Database Connection Services DirectoryThe DCS directory is required only when connecting to a host server like DB2 for OS/390, z/OS, and iSeries. This directory is available only when the DB2 Connect software is installed. If you are running DB2 UDB Enterprise Server Edition (ESE), DB2 Connect support is built into the DB2 database product, so the DCS directory will also be available. Figure 6.6 shows the contents of a sample DCS directory. Figure 6.6. A sample DCS directoryIn Figure 6.6 the relevant fields are:
6.2.6. The Relationship Between the DB2 DirectoriesNow that you have a good understanding of the DB2 directories, let's see how all of them are related by using a few figures. 6.2.6.1 A Local ConnectionFigure 6.7 illustrates the process of connecting to a local DB2 database. When a user issues the statement: CONNECT TO mylocdb USER raul USING mypsw Figure 6.7. The local database connection processDB2 follows these steps.
6.2.6.2 A Remote Connection to a DB2 ServerFigure 6.8 illustrates the process of connecting to a remote DB2 database. When a user issues the statement: CONNECT TO myrmtdb USER raulrmt USING myrmtpsw Figure 6.8. The remote database connection processDB2 follows these steps:
6.2.6.3 A Remote Connection to a Host DB2 ServerFigure 6.9 illustrates the process of connecting to a remote DB2 host server, which can be DB2 for z/OS, OS/390, or DB2 for iSeries. When a user issues the statement: CONNECT TO myhostdb USER raulhost USING myhostpsw Figure 6.9. The remote host DB2 database connection processDB2 follows these steps:
|