IBM Books

Quick Beginnings for DB2 Extended Enterprise Edition for UNIX


Using the Command Line Processor

You can use the command line processor to enter SQL statements and DB2 commands. It operates in the following modes:

Interactive Input Mode
You can enter DB2 commands or SQL statements and view their output.

Command Line Mode
The DB2 command line processor behaves like a command window from your operating system. You can enter DB2 commands or SQL statements and view their output.

File Input Mode
Refer to the Command Reference for information on the file input mode.

Interactive Input Mode

To invoke the command line processor in interactive input mode, do the following:

You can also invoke the command line processor in interactive input mode, by entering the following command at a command prompt:

In interactive input mode, the prompt looks like this:

   db2 =>

This prompt indicates that you do not type DB2 commands with a db2 prefix; instead, you just enter the DB2 command. For example:

   list node directory

To run operating system commands in interactive mode, precede the operating-system command with an exclamation mark (!). For example:

   !dir db2*.log


note

Windows 3.x does not support this method of running operating system commands.

If you need to enter a long command that does not fit on one line, use the line continuation character, \. For example:

   db2 => select firstname, lastname, dateofbirth, from \
   staff where height=68, order by \
   lastname
Note:You do not need to use a line continuation character when entering long commands in interactive input mode on Windows 3.x workstations.

To end interactive input mode, type terminate.

Command Line Mode

On UNIX, you can issue DB2 commands from a command prompt. You must include the db2 prefix. For example:

   db2 list node directory

To invoke the command line processor in command line mode on Windows 95 and Windows NT operating systems, use one of the following methods:

After you invoke the DB2 command environment, you can enter DB2 commands at the command prompt. You must include the db2 prefix.

Notes:

  1. If the DB2 command contains characters that have special meanings on the operating system you are using, you will need to enter the command in quotation marks to ensure that it is run properly. For example, the following command will successfully retrieve all information from the employee table, even if the * character has a special meaning on the operating system:
       db2 "select * from employee"
    

  2. Command line mode is not available on Windows 3.x systems.


note

For further information on using the command line processor, refer to the Command Reference.

Connecting to a Logical Node

The default logical node is one that has a value of 0 for the logical_port parameter in the db2nodes.cfg file. By default, a client connects to the default logical node unless the DB2NODE environment variable is set to another node number. For all commands and applications that connect to a database, you must ensure that the DB2NODE environment variable is set to reference the node number of the logical node that you want the operation to run on. The node number of the logical node is in the db2nodes.cfg file. If the database partition server being connected to is not started on the machine, the application returns an error. In DB2 Extended Enterprise Edition, the set client command can also be used to target a specific node within a partitioned database system. For more information, refer to the Command Reference.

Remote applications always connect to the default node, unless the DB2NODE environment variable is set to another node number. Because all logical nodes on an instance share the same database manager configuration file, only one logical node per instance on a machine can service remote applications. The default node starts up the communication subsystem, if it was configured to do so. If the default node is shut down, the communication subsystem also ends. You will have to stop and restart a logical node on the machine to re-establish the communication subsystem. If you move the default node to another machine, on which logical nodes for that instance are already running, and one of the logical nodes already has a communication subsystem for remote clients, the restarted node cannot have one.

As an example, assume that you want to update the configuration of a database partition server that belongs to a database called TEST, and that database partition server is on a machine called MACH1. Also assume that you defined nodes 0 and 1 on MACH1. Because database configuration is defined at the database partition level, you would connect to each logical node on the machine and change the database configuration. You could do the following in two sessions on MACH1:

  1. In session 1:

    1. Export DB2NODE=0.

    2. Connect to the database partition server on logical node 0. Issue the following statement:
        db2 connect to test
      

    3. Update the database configuration file for the remote server.

    4. End the connection by issuing the following statement:
        db2 connect reset
        db2 terminate
      

  2. In session 2:

    1. Export DB2NODE=1.

    2. Connect to the database partition server on logical node 1. Issue the following statement:
        db2 connect to test
      

    3. Update the database configuration file for the remote server.

    4. End the connection by issuing the following statement:
        db2 connect reset
        db2 terminate
      

If you want, you can run session 1 and 2, one after the other.

When you are connected to a database, you can list the local database directory by issuing the list database directory on path command. The output will show the catalog node number for the database and the current node number where you are connected.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]