IBM Support

When piping the output of a DB2 command to the head operating system command ("| head"), an operating system error is logged to the db2diag.log

Technote (FAQ)


Question

EINVAL (22) "Invalid argument" LEVEL: Error (OS) error is returned when you pipe the output of a DB2 command to the head operating system command (for example, db2 list tablespaces show detail | head -81).

Cause

A problem diagnosing code has been added to the sqlowqueInternal functionin DB2® UDB Version 9.

When a command such as db2 list tablespaces show detail | head -81 or db2 select * from employee | head -10 is run, DB2 Version 9 logs the following message in the db2diag.log file:

-----------------------------------------------------------------------
2007-03-06-23.17.14.080280-300 E10282A659         LEVEL: Error (OS)
PID     : 9883690              TID  : 1           PROC : db2bp
INSTANCE: hidehy               NODE : 000
APPID   : *LOCAL.hidehy.070307041048
FUNCTION: DB2 UDB, oper system services, sqlowqueInternal, probe:40
MESSAGE : ZRC=0x870F003E=-2029060034=SQLO_QUE_BAD_HANDLE "Bad Queue Handle"
          DIA8555C An invalid message queue handle was encountered.
CALLED  : OS, -, write
OSERR   : EINVAL (22) "Invalid argument"
DATA #1 : system V message queue identifier., PD_TYPE_SYSV_QUEUE_ID, 4 bytes
0x1DD001B8
DATA #2 : Pointer, 8 bytes
0x0000000110035760
DATA #3 : unsigned integer, 8 bytes
78
-----------------------------------------------------------------------


When a command such as db2 "select * from tab1" | more is run (where tab1 has a large number of records), running Control + C on HP will show the message too. However, the same scenario above cannot be reproduced in Solaris

This error might occur in any scripting language that does not use direct connection to the DB2 instance but instead, spawns a subshell to handle the DB2 connection, such as shell, C using system, and Perl using open, system or ``.

Answer

The logging of this message is expected. There is no option to remove the logging of this message. The message can be ignored.


If you pipe the DB2 command output to the less or tail commands, the message will not be written.

If you pipe the output to awk first, pipe to head or others, the message will not be written.

The following example shows how to do so:

$db2 select * from employee | awk '{print $0}' | head -10

$db2 list tablespaces show detail | awk '{print $0}' | head -81


If you use Perl and sleep(), the message will not be written.

The following example shows how you can use sleep():

open(DB2QUERY,"db2 -tf $querysql |") || die "Failed to get data from DB2, $!";
while (<DB2QUERY>)
{
. . .
}
while (!eof(DBQUERY)){};

sleep(1);
close(DB2QUERY);

Document information

More support for: DB2 for Linux, UNIX and Windows
Programming Interface - CLP

Software version: 9.1, 9.5, 9.7, 9.8, 10.1

Operating system(s): AIX, HP-UX, Solaris

Software edition: Enterprise Server

Reference #: 1259051

Modified date: 28 January 2011