Usually in Db2 LUW Database environments, Application teams encounter "db2: command not found" message upon attempting to execute a Db2 command by an application user, the common workaround for this issue is source the Instance profile (or) db2profile.
DBAs with Instance user access seldom get this message. Today I would like to share what happens exactly in the background when db2profile file is sourced by an Application user.
To demonstrate this, firstly, I am logged in as an Application/normal user (appuser1) per se who intends to run Db2 commands
appuser1@db2v10primary:~> whoami
appuser1
appuser1@db2v10primary:~>
In this step, appuser1 executes a Db2 command and encounters error.
Let's also try to understand in high-level of what happens when a command is executed from OS prompt.
- An attempt will be made to locate the binary/program for that command in all the path(s) associated with that user. Path is set of directories listed against the environment variable PATH.
- If the binary/program is located in any of the path(s) and user has execute permission on that binary/program, then that particular binary/program will be executed. Else an error message will be displayed on Standard output.
appuser1@db2v10primary:~> db2 -v "list db directory"
If 'db2' is not a typo you can run the following command to lookup the package that contains the binary:
command-not-found db2
-bash: db2: command not found
appuser1@db2v10primary:~>
Now let's list the path(s) associated with the user. We can notice that no Db2 related files such as "sqllib" which contains Db2 related binaries are seen in the path(s)
appuser1@db2v10primary:~> echo $PATH | tr [:] [\\n] | cat -n
1 /opt/ibm/db2/V10.1/java/jdk64/jre/bin
2 /home/appuser1/bin
3 /usr/local/bin
4 /usr/bin
5 /bin
6 /usr/bin/X11
7 /usr/X11R6/bin
8 /usr/games
9 /usr/lib/mit/bin
10 /usr/lib/mit/sbin
11 .
appuser1@db2v10primary:~>
In this situation, we must first find and associate the "sqllib" and "db2profile" file with the normal or application user by sourcing it. In the example, given below, we can notice the 3 db2profile files were located by the find command (This command has searched in the entire filesystem and listed db2profile files related to 2 instances residing in my Server and 1 from the location where Db2 is installed). More information about find command and it's usage can be found here.
appuser1@db2v10primary:~> find / -name "db2profile" 2>/dev/null
/opt/ibm/db2/V10.1/cfg/db2profile
/home/db2inst1/sqllib/db2profile
/home/ddinst1/sqllib/db2profile
appuser1@db2v10primary:~>
I have chosen db2profile file related db2inst1 instance and sourced the same as shown below.
appuser1@db2v10primary:~> . /home/db2inst1/sqllib/db2profile
appuser1@db2v10primary:~>
After sourcing successfully, appuser1 can execute the Db2 command as shown below.
appuser1@db2v10primary:~> db2 -v "list db directory"
list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = GAUTI1
Database name = GAUTI1
Local database directory = /tmp
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = SAMPLE
Database name = SAMPLE
Local database directory = /db2fs
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
appuser1@db2v10primary:~>
appuser1@db2v10primary:~>
Now let's verify how the PATH has changed for appuser1 user after sourcing db2profile.
appuser1@db2v10primary:~> echo $PATH | tr [:] [\\n] | cat -n
1 /opt/ibm/db2/V10.1/java/jdk64/jre/bin
2 /home/appuser1/bin
3 /usr/local/bin
4 /usr/bin
5 /bin
6 /usr/bin/X11
7 /usr/X11R6/bin
8 /usr/games
9 /usr/lib/mit/bin
10 /usr/lib/mit/sbin
11 .
12 /home/db2inst1/sqllib/bin
13 /home/db2inst1/sqllib/adm
14 /home/db2inst1/sqllib/misc
15 /home/db2inst1/sqllib/db2tss/bin
appuser1@db2v10primary:~>
Questions? Most welcome!!!
No comments:
Post a Comment