• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:


1) We have DB2 8.1.5 on AIX 5.1. We installed gcc compiler for stored procedures.

2) We set /usr/local/bin as part of PATH and also in file sr_cpath.bat in /home/db2inst1/sqllib/function/routine which is the install path of the gcc compiler.

3) We set DB2_SQLROUTINE_COMPILER_PATH=/home/db2inst1/sqllib/function/routine/sr_cpath &
DB2_SQLROUTINE_COMPILE_COMMAND=cpp -fpic -D_REENTRANT -I/home/db2inst1/sqllib/include SQLROUTINE_FILENAME.c -shared -lpthread -o SQLROUTINE_FILENAME -L/home/db2inst1/sqllib/lib -ldb2

4) The SP's are compiling but while executing them we get:
$ db2 call proc1
SQL0444N  Routine "PROC1" (specific name "SQL040923201543446") is implemented
with code in library or path ".../sqlproc/SAMPLE/DB2INST1/P0154347", function
"pgsjmp" which cannot be accessed.  Reason code: "5".  SQLSTATE=42724

We find that pgsjmp function is in file  P0154347, P0154347.sqc, P0154347.c and in P0154347.log file we have following info:

-- OF /home/db2inst1/sqllib/function/routine/sqlproc/SAMPLE/DB2INST1/tmp/P2271903.sh

export SQLROUTINE_ENTRY=pgsjmp


cpp -fpic -D_REENTRANT -I/home/db2inst1/sqllib/include P2271903.c -shared -lpthread -o P2271903 -L/home/db2inst1/sqllib/lib -ldb2

-- OF /home/db2inst1/sqllib/function/routine/sqlproc/SAMPLE/DB2INST1/tmp/P2271903.exp


-- FOR /home/db2inst1/sqllib/function/routine/sqlproc/SAMPLE/DB2INST1/tmp/P2271903.c

cpp: -lpthread: linker input file unused because linking not done
cpp: -ldb2: linker input file unused because linking not done


How is SQLCODE:0 when we got error.
If we use gcc instead of cpp as start of DB2_SQLROUTINE_COMPILE_COMMAND, during compile time itself we get errors:

/usr/include/sys/context.h:155: parse error before "sigset64_t"
/usr/include/sys/context.h:158: parse error before '}' token

Please help me compile & execute our SP's.
  • 3
  • 2
  • 2
2 Solutions
Better yet, if you upgrade to DB2 8.2  (8.1 Fixpak 7) - you no longer need to compile SQL procedures  (of course this assumes yours is a SQL and not a C sp)!
yes, bondtrader is correct, this is the standard IBM reply for the really poor implementation of stored prcoedures in v8.1 up to fixpack 6. In fact, the developer team at IBM has very little idea how to fix these types of problems, thats why the mantra is upgrade to Stinger.
I would suggest that your problem lies in the dll versions that the stored procedure dll relies on. Therefore, to fix your problem, open the dll that was created by the create stored procedure command in debug mode and make a note of all the dll's it refers to. Then, on your UNIX box, check for multiple copies of these dll's and make sure all the dll's referenced by the stored proc dll exist on the machine. If not, make sure to install them.

Drop and re create the procedure. Run it again, inform me if it works. You may have to grant execute on procedure to user and or group.
k_murli_krishnaAuthor Commented:
Thanks Bondtrader & ghp7000. Few things I could not understand.

In /home/db2inst1/sqllib/function/routine/sqlproc/SAMPLE/DB2INST1, files of type P2244519, P2244519.c, P2244519.log, P2244519.scm & P2244519.sqc are getting created sometimes & at others, files of type P2141500.bnd, P2141500.c, P2141500.log, P2141500.scm & P2141500.sqc are getting created in tmp directory under above path. Why this dual behaviour?

Does the definer of SP have to be granted execute on SP.

Where can I find the dll files in AIX & I assume these get created during compile time.

My sr_cpath has following contents:

export PATH

Is this okay. My other 2 important parameters are:

DB2_SQLROUTINE_COMPILER_PATH=/home/db2inst1/sqllib/function/routine/sr_cpath &
DB2_SQLROUTINE_COMPILE_COMMAND=cpp -fpic -D_REENTRANT -I/home/db2inst1/sqllib/include SQLROUTINE_FILENAME.c -shared -lpthread -o SQLROUTINE_FILENAME -L/home/db2inst1/sqllib/lib -ldb2

Are these 2 okay. With gcc instead of cpp, the SP's were not getting compiled => errors.
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

k_murli_krishnaAuthor Commented:
bondtrader & ghp7000, please respond to my comment so that I can close this question.
every time you try and compile a stored procedure, the p*.log files are generated. Therefore, each compile attempt has an associated log file, dll and bnd file. You can erase all of these files.
if the definer of the sp is not the same user as the schema referenced in the sp, then you will have to grant execute on sp to user or group.

sorry, cant answer your question on the compiler string you are using, but you can check the meaning of each switch on the compiler home page for the product you are using.

also, I really am not very familiar with AIX, so I cant help you there either, but a simple search on the drive should suffice. Remember, the idea is to match the dll's referenced by the stored procedure to see if those dll's exist on your aix machine or to see if you have multiple copies of these dll's on your machine and if you do, if all of the copies have the same file timestamp.
k_murli_krishnaAuthor Commented:
ghp7000, the below is total list of dll's present when searched from root:


When opened in vi editor, they all show junk info. The ones which get created on compiling stored procedure are not dll's.

We have VisualAge C++ but this eval version has expired. Can we put date back so that it will work. What things may be affected by this. Can you suggest any other compiler for SQL stored procs for DB2 8.1.5 on AIX 5.1.
You should be able to use gcc on AIX.  Again though, the nice thing about 8.1.7 (aka 8.2) is that you don't need ANY compiler for SQL Procedures...

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now