Showing posts with label db2. Show all posts
Showing posts with label db2. Show all posts

Monday, December 16, 2019

WebSphere Application Server - DB2 RS Transaction Isolation Level is Default



In WebSphere, the default transaction level is set to something very restrictive.
It’s likely that they haven’t changed this in their app server configuration.
Have them check the webSphereDefaultIsolationLevel custom property on their data sources.


“If the database connection is obtained in a servlet, JSP, or session bean, TRANSACTION_REPEATABLE_READ is used by default.”
JDBC Isolation Level
              
DB2 Isolation Level
TRANSACTION_SERIALIZABLE      Repeatable Read (RR)
TRANSACTION_REPEATABLE_READ           Read Stability (RS)  Deafult
TRANSACTION_READ_COMMITTED          Cursor Stability (CS) What we want
TRANSACTION_READ_UNCOMMITTED    Uncommitted Read (UR)

“In WebSphere Application Server V6.1 and above, the webSphereDefaultIsolationLevel custom property can be set on a data source to change the default isolation level that is used even if indirect JNDI lookups and resource references are not used by the application.”

Procedure for changing this setting in WAS 8.5.5 can be found here:
https://www.ibm.com/support/knowledgecenter/en/SSWLGF_8.5.6/com.ibm.sr.doc/twsr_setwebspheredefaultisolationlevelproperty.html


Wednesday, January 09, 2019

Make DB2 work again after server name has changed

There is an excellent guide on the steps needed to change the name of a server that is hosting DB2 LUW database that can be found on the Filmore Group Blog..


Friday, November 18, 2016

Problems creating DB2 UDB LUW db from GUI tools

I've had tons of problems creating db's (or doing some other operations) from the GUID tools, including Data Studio, and the control center (under db2 9.7).

It's always complained about the DAS, but the DAS (the DB2 Administration Server) is always happily running.

Today I stumbled across something that told me to issue the following command:
db2admin create

I then ran a
db2admin start

!!!! WORKED LIKE A CHARM !!!!

After that, I was able to successfully verify the instance, connect, and create the db I was trying to create.

Sorry - wish I had captured some screenshots along the way, but now that I've fixed it, I can't reproduce ;-)

At any rate, hope this helps someone.

Wednesday, October 08, 2014

Admin_CMD from within Stored Procedure - Error handling

I spent a lot of time on this one, and it wasn't clear from examples precisely how the various items should be used together.

The format of the ADMIN_CMD query is pretty straight-forward, and in our case, it took on roughly this form (edited to remove any identifying data):

______________________
CALL SYSPROC.ADMIN_CMD('EXPORT TO /datadestination/subfolder1/subfolder2/FileName.IXF OF IXF MESSAGES ON SERVER SELECT ');
______________________

Using ADMIN_CMD from CLP

If you're using ADMIN_CMD from a normal query, then it's pretty straight-forward.  The command will return a result set that has a query that gets you more detailed information about what you just did.

For example:

NOTE: Result set is edited to remove whitespace.

  Result set 1
  --------------

  ROWS_EXPORTED        MSG_RETRIEVAL                                                                       MSG_REMOVAL                                        
  -------------------- ----------------------------------------------------------------------------------- ----------------------------------------------------
                     0 SELECT SQLCODE, MSG FROM TABLE(SYSPROC.ADMIN_GET_MSGS('28138_DB2ADMIN')) AS MSG     CALL SYSPROC.ADMIN_REMOVE_MSGS('28138_DB2ADMIN')   

  1 record(s) selected.
  Return Status = 0
To break that out a bit, the MSG_RETREIVAL query is:
MSG_RETRIEVAL                                                                     
-----------------------------------------------------------------------------------
SELECT SQLCODE, MSG FROM TABLE(SYSPROC.ADMIN_GET_MSGS('28138_DB2ADMIN')) AS MSG   

... The MSG_REMOVAL query is:
MSG_REMOVAL                                     
-------------------------------------------------
CALL SYSPROC.ADMIN_REMOVE_MSGS('28138_DB2ADMIN')

You can then just copy and paste those, enter them into a query window and get results.


Using ADMIN_CMD from a stored procedure

This gets a bit more dodgy.
The problem, of course, on DB2 LUW 9.5, there's just not a great, straight-forward way to retrieve these results.
Fortunately, I was able to find an excellent example on dbforums, submitted by db2girl.
Example can be found here
DB2Girl's profile can be found here.

Turns out, it is necessary to create a RESULT_SET_LOCATOR that we associate with the call to ADMIN_CMD(Export).  I'm a bit embarrassed to admit that I had not previously heard of a RESULT_SET_LOCATOR.

Even now, I'm finding it hard to find documentation on this. Prior to DB2 10, it seems to mostly appear in 3rd party documentation, such as that from Micro focus.
I guess I'm not surprised by this, IBM. But, really? Not one little example of this?  Maybe it's in the COBOL documentation.  I dunno.

So, what I place here is "by rote", meaning I don't fully understand it.
I can deduce from the example below the following:
  1. RESTULT_SET_LOCATOR is a DB2 Data Type
  2. It can be "associated" with a command using the ASSOCIATE RESULT SET LOCATORS command.
  3. A cursor can then be allocated against the result set, and used to retrieve data.
What I don't know (and what bothers me):
  1. VARYING is obviously a modifier. What, precisely, does it mean, and what alternatives are available?
The approach I took was to simply create a table for logging and inserted the results of the call to SYSPROC.ADMIN_CMD into that table. If all is not well after the job runs, this can be queried.

A better approach would be to get these results and log them, then clean up the results using ADMIN_REMOVE_MSGS().

CREATE PROCEDURE RATESTUDYSR.SP_SQL_EXP_PSH_RS_SEG_LOAD (IN INT_P_BEGIN_DATE INT, IN INT_P_END_DATE INT)
 DYNAMIC RESULT SETS 1

P1: BEGIN
 DECLARE V_MSG_RETREIVAL VARCHAR(512);
 DECLARE V_ROWS_EXP BIGINT;
 DECLARE V_MSG_REMOVAL VARCHAR(512);
 DECLARE RESULT1 RESULT_SET_LOCATOR VARYING;

 DECLARE CONTINUE HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND BEGIN END;

  CALL SYSPROC.ADMIN_CMD('EXPORT TO /export.ixf OF IXF MESSAGES ON SERVER SELECT Manyfields FROM mytables JOIN othertables' );


 ASSOCIATE RESULT SET LOCATORS(RESULT1) WITH PROCEDURE SYSPROC.ADMIN_CMD;
 ALLOCATE RSCUR CURSOR FOR RESULT SET RESULT1;
 FETCH RSCUR INTO V_ROWS_EXP, V_MSG_RETREIVAL, V_MSG_REMOVAL;

 INSERT INTO RATESTUDYSR.LOG_SP_SQL_EXP_PSH_RS_SEG_LOAD VALUES (CURRENT_TIMESTAMP, 'TO RETREIVE ADMIN_CMD INFO: ' || V_MSG_RETREIVAL);
 
END P1


So, that's where I'm at as of now.  It's not hard to imagine retuning the result set from the stored procedure rather than logging it, but that's work for another day ;-)


Friday, September 05, 2014

Regular Expressions in SQL Server, DB2 UDB, and Oracle

I was a bit surprised that not all RDBMS platforms offer robust, native support for regular expressions.

Oracle:

Oracle introduced this in 10g. It is implemented in roughly the way I would expect and looks like it's pretty useful.
Reference

DB2:

DB2 seems to have this capability in 9.7. NOTE that I have not checked to see if it was available in earlier releases.  However, it appears you have to go through the XQuery interface. I'm not surprised by this, but a bit disappointed.  I had hoped for an implementation more like Oracle's. I think that the DB2 way is going to be cumbersome for the average user.

Example:
db2 "with val as (
 select t.text
 from texts t
 where xmlcast(xmlquery('fn:matches(\$TEXT,''^[A-Za-z 0-9]*$'')') as integer) = 0
)
select * from val"

Reference1, IBM DB2 for LUW 9.7 information center reference

MS SQL Server: 

SQL Server, it seems, requires you to roll your own solution or look to some sort of 3rd party.  I'm very surprised by this.

There are 3rd party libraries that appear to be pretty robust.  One example can be found here: SQL Server Central article on RegEx in MSSQL Server

I suppose that they want us to use the full text search, which appears to have robust features, and address the same purpose.  Still, just a bit surprised ...

Monday, August 25, 2014

Createing a remote UDF for a Federated DB2 LUW 9.5 database

There are a couple good references for federated DB's that I've found in my research, but none really laid out the high level process for connecting a DB2 federated DB to a UDF on a data source.

Here are the steps.

  1. Create Function on Datasource DB
  2. Create Function Template on Federated DB
  3. Create Function Mapping on federated db



For details on how to perform each of these steps, consult

  • The DB2 9.5 Info Center. There's an entire section on Federation that's OK.
  • The Federated Systems Guide. Google it. It's a PDF.


Good luck!

Tuesday, November 19, 2013

DB2 Refrential Integrity

I was going to write a post about DB2 referential integrity, but I cannot imagine writing anything better than the very good, thorough treatment of the topic found here:
http://ibmdatamag.com/2011/01/how-well-do-you-know-the-rules/

Monday, October 14, 2013

DB2 Backup Naming convention

I had a hard time finding this on the internet, so I thought I'd post after I found it in a book.

The naming convention for a DB2 file system backup will be:
Alias.Type.Instance.Node.Catalog_Node.MonthHourSecond.Sequence
Example:
MyDB.0.DB2INST.NODE00000.CATN0000.20131015131259.001
   ↑       ↑        ↑                ↑                   ↑                ↑   ↑  ↑     ↑   ↑     ↑
Alias     |    Instance          |           Catalog Node     |    |   |      |    |      |
       Backup Type       Node                              Year  |   |      |    |      |
                                                                            Mon  Day  |  Sec   Seq
                                                                                           Min

Reference:
Understanding DB2: Learning Visually with Examples Second Edition
Page 745
14.4.6 The Backup Files
Raul F. Chong Clara Liu Sylvia F. Qi Dwaine R. Snow 

Thursday, August 29, 2013

Nothing Ever Always

Sometimes I get really frustrated by the things I used to know, but somehow forgot.
For instance, I USED to know that, in a relational database, nothing is ever always true.
Huh?

Perhaps an example will be illuminating.

Indexes - we are told that they help reads and hurt writes.  I suppose that's true, on some level, because of the processing the RDBMS has to do in order to perform the actual operation of writing to the table, and updating the indexes.

However, I had a situation today wherein I found myself creating an index to DRAMATICALLY speed up a write operation.

Both for a delete where and an update where, adding the index cut the execution (in DB2, measured in timerons) by 60 - 80 %.  Wow. 

Honestly, I should have known this.  I've been doing this for a while. I get used to pat ideas and the looking at a problem in a very particular way, or on a small set of data.

Bottom line, in relational databases, nothing ever always.

Monday, July 08, 2013

backup Db2- unable to force applications

When trying to backup a db on db2 LUW 9.5, I get the following message, even after running quiesce.

SQL1035N The database is currently in use. SQLSTATE=57019
 
There is some good advice involving authority here: http://www.dbforums.com/db2/1663529-backup-db2-unable-force-applications.html#post6596923

However, it did not apply to my situation.

In desperation, I decided to just restart the instance.
When I did, I got an error indicating invalid credentials.

I had to go into the Windows Service and change the password for the user.
That cleared up the issue.

Whaddya know...

Get Restart log using PowerShell

I'm often curious about a restart on a Windows server system. An easy way to get a list of the restart and what initiated it is to use t...