728x90


Problem(Abstract)

When running a select query that contains COUNT(*) the following errors are returned:
> echo "select count(*) from customer;" | dbaccess stores_demo

Database selected.

252: Cannot get system information for table.

113: ISAM error: the file is locked.
Error in line 1
Near character position 61


Database closed.

Symptom

Errors -252/-113 are returned:

252: Cannot get system information for table.

113: ISAM error: the file is locked.

Cause

Isolation level Committed Read or Last Committed is used and there is an exclusive lock on the table

Diagnosing the problem

Using 'onstat -g sql' check the isolation level that sessions are using:

> onstat -g sql

IBM Informix Dynamic Server Version 11.70.FC3 -- on-Line -- Up 00:52:17 -- 182532 Kbytes

Sess SQL Current Iso Lock SQL ISAM F.E.
Id Stmt type Database Lvl Mode ERR ERR Vers Explain
39 - stores_demo CR Not Wait 0 0 9.24 Off
27 sysadmin DR Wait 5 0 0 - Off
26 sysadmin DR Wait 5 0 0 - Off
25 sysadmin DR Wait 5 0 0 - Off

In the above example session #39 is using an isolation level of Committed Read (CR).

Then check the table for exclusive locks. To do so, first get the partnum of the table. This can be done by running the 'oncheck -pt <dbname:tabname>' command:

> oncheck -pt stores_demo:customer

TBLspace Report for stores_demo:informix.customer

Physical Address 2:678
Creation date 08/05/2011 15:55:41
TBLspace Flags 802 Row Locking
TBLspace use 4 bit bit-maps
Maximum row size 134
Number of special columns 0
Number of keys 0
Number of extents 1
Current serial value 129
Current SERIAL8 value 1
Current BIGSERIAL value 1
Current REFID value 1
Pagesize (k) 2
First extent size 8
Next extent size 8
Number of pages allocated 8
Number of pages used 3
Number of data pages 2
Number of rows 28
Partition partnum 1049059
Partition lockid 1049059
<...>

Next, convert the partnum value into HEX: 1049059 = 0x1001e3

Finally, grep the partnum value (without the leading 0x) from 'onstat -k' output:

> onstat -k | grep 1001e3
4ebef028 0 4b85c418 4ebeed28 HDR+X 1001e3 102 0 D
4ebef328 0 4b85c418 4ebef228 HDR+X 1001e3 103 0 D
4ebef528 0 4b85c418 4ebef428 HDR+X 1001e3 104 0 D
4ebef728 0 4b85c418 4ebef628 HDR+X 1001e3 105 0 D
4ebef828 0 4b85c418 4ebeefa8 HDR+X 1001e3 106 0 D
4ebefa28 0 4b85c418 4ebef9a8 HDR+X 1001e3 107 0 D
4ebefb28 0 4b85c418 4ebefaa8 HDR+X 1001e3 108 0 D
4ebefd28 0 4b85c418 4ebefca8 HDR+X 1001e3 109 0 D
4ebeff28 0 4b85c418 4ebefea8 HDR+X 1001e3 10a 0 D
4ebf0128 0 4b85c418 4ebf00a8 HDR+X 1001e3 10b 0 D
4ebf0328 0 4b85c418 4ebf02a8 HDR+X 1001e3 10c 0 D
4ebf0528 0 4b85c418 4ebf04a8 HDR+X 1001e3 10d 0 D
4ebf0728 0 4b85c418 4ebf06a8 HDR+X 1001e3 10e 0 D
4ebf0928 0 4b85c418 4ebf08a8 HDR+X 1001e3 201 0 D
4ebf0b28 0 4b85c418 4ebf0aa8 HDR+X 1001e3 202 0 D
4ebf0ca8 0 4b85c418 4ebf0c28 HDR+X 1001e3 203 0 D
4ebf0ea8 0 4b85c418 4ebf0e28 HDR+X 1001e3 204 0 D
4ebf10a8 0 4b85c418 4ebf1028 HDR+X 1001e3 205 0 D
4ebf12a8 0 4b85c418 4ebf1228 HDR+X 1001e3 206 0 D
4ebf1428 0 4b85c418 4ebf13a8 HDR+X 1001e3 207 0 D
4ebf1628 0 4b85c418 4ebf15a8 HDR+X 1001e3 208 0 D
4ebf1828 0 4b85c418 4ebf17a8 HDR+X 1001e3 209 0 D
4ebf1a28 0 4b85c418 4ebf19a8 HDR+X 1001e3 20a 0 D
4ebf1c28 0 4b85c418 4ebf1ba8 HDR+X 1001e3 20b 0 D
4ebf1e28 0 4b85c418 4ebf1da8 HDR+X 1001e3 20c 0 D
4ebf2028 0 4b85c418 4ebf1fa8 HDR+X 1001e3 20d 0 D
4ebf2228 0 4b85c418 4ebf21a8 HDR+X 1001e3 20e 0 D
4ebfeda8 0 4b85c418 4ebfee28 HDR+X 1001e3 101 0 D
4ebfee28 0 4b85c418 44452788 HDR+IX 1001e3 0 0

In the above example, the table has an intent-exclusive lock on the whole table (HDR+IX) and some exclusive locks on its rows (HDR+X).

Resolving the problem

Set the isolation level to Dirty Read at the session level before running the query:

> echo "set isolation to dirty read; select count(*) from customer;" | dbaccess stores_demo

Database selected.

Isolation level set.


(count(*))

28

1 row(s) retrieved.

Database closed.

Another option is to set lock mode to wait in order to allow the query to wait until the lock is released:

> echo "set lock mode to wait; select count(*) from customer;" | dbaccess stores_demo


728x90
728x90

Question

If you think that the DB2® index manager might be the origin of a problem, collect diagnostic data that you or IBM® Software Support can use to diagnose and resolve the problem.

Cause

Background

There are many flavours of index-related corruption problems, for instance:

  • Unique index contains duplicates with different RID(s) or same RID(s)
  • Multiple index entries pointing to the same RID
  • Index key is out of place (wrong index key order)
  • Row exists, but index keys do not exist in any or some of the indexes
  • Index entry pointing to an empty data slot or unused data slot or RID is invalid
  • Incorrect previous or next index page pointers, incorrect high key or other corruptions on index pages

Even if you see the same return code from the same function or probe point, problems could vary from one to another. For instance, when SQLI_NOKEY error is received from index function "procLeaf2Del" or "sqlischd" during a delete or update, you could be hitting problems 3, 4, or 6. 

If "row not found" or "bad page" type of error is received when an index is used to fetch the RID for a delete, update or select, then you could be hitting problems 3 or 5. 

In short, for each problem, a DB2 support analyst will need to look at the data collected, and analyze it to determine root cause. To have data collected as much as possible at the first failure point as well as preserving necessary log files are often critical to the root cause determination. 

Since index corruption or index data inconsistency type of errors could be caused by DB2 defects or by other issues such as hardware problems, it is necessary to collect the proper diagnostic data in order to determine the potential cause of the error. 


DB2 tools to detect these problems 

DB2 products offer a variety of tools to detect index or data corruption problems and index or data mismatch problems. 

  1. An off-line db2dart /t (table inspection) would be able to detect corruption symptoms 1, 2, 3, 6 of the above list. For example:

    Table resides in table space id 4, and object id of table is 2, the database name is T30, the output is "inspTsi4oi2.rpt":
    db2dart T30 /t /tsi 4 /oi 2 /scr n /rptn inspTsi4oi2.rpt

  2. The RUNSTATS command with a special registry variable set will collect statistics as well as detect corruption symptoms 4, 5 of the above list. For example:

    db2stop
    db2set DB2_KEYDATACHECK=IXSTATDATADEBUG
    db2start

    db2 connect to <database>
    db2 -v "runstats on table <tableschema>.<tabname> and detailed indexes all allow read access"

    NOTE: After each RUNSTATS, you need to save the contents of the sqllib/db2dump directory. You can do so by moving the entire content to another location. As long as the RUNSTATS does not return with DB2 completed successfully, you will need to report this to DB2 support.

Some enhancements are currently being investigated. The goal is to improve the existing tools for serviceability and usability in future releases in the above areas.

Answer

You often need an advanced knowledge of DB2 in order to determine whether the problem is an index corruption or an index or data inconsistency problem. Therefore you should always contact IBM support organization to help you recover from these problems.



For index-related corruption or index or data inconsistency problems, the following information is typically required:

  • the contents of the DB2DUMP directory
  • the on-disk version of the related index pages (collected via the db2dart tool)
  • related data page(s) for the index or data object (collected via the db2dart tool)
  • database transaction log files, which are used to understand the past history of the index or table object that encountered the error.

The following steps are the recommended best practice for data collection (and database recovery) when an error related to index corruption occurs. NOTE: DO NOT perform these steps unless you have been asked to do so by an IBM DB2 Support analyst. 

  1. Collect the standard diagnostic information using the db2support command. This should include all the files in DB2DUMP directory (or the path specified by DIAGPATH in the dbm configuration).

    There are cases where the corruptions are caused by a disk problem, and you do not care about root cause analysis of the problem. In these situations, skip step 2, and go directly to step 3.

  2. Run db2dart as indicated below (note: if this is a multi-partition DPF environment, then you will need to run db2dart on the partition where failure occurred):

    db2dart <dbname> /t /tsi <pool id> /oi <object id> /rptn inspTsi<poolid>oi<objectid>_bcrashrec.rpt

    In general, this inspection should be fairly quick. If the database is mission critical database and needs to be brought up online immediately, then you may skip this step at this time.

  3. Restart your database and verify crash recovery completes successfully.


    If crash recovery completes successfully and you cannot take the time needed to collect this data for root cause analysis of the problem, skip steps 4, 5 and 6 and go directly to step 7.


    If the restart fails, and it is determined to be a problem redoing or undoing an index record, then you can mark an index invalid (e.g. db2dart <dbname> /mi /oi <objectID> /tsi <tablespaceID>). INDEXREC will control when the invalid index object will be recreated.
  4. To prevent the previous failing application from accessing the table again before the problem on the related index or table is resolved, you can lock the table in exclusive mode. Use the following command:


    db2 +c "LOCK TABLE <SCHEMA NAME>.<TABLENAME> IN EXCLUSIVE MODE"


    The "+c" turns off the auto commit, since LOCK TABLE is only effective within the unit of work.


    If you do care about the availability of the rest of the tables in the same table space as the problem table, instead you may also want to consider quiescing the table spaces for the table object. For example:


    db2 "QUIESCE TABLESPACES FOR TABLE <SCHEMA NAME>.<TABLE NAME> EXCLUSIVE"


    NOTE: QUIESCE command will also quiesce the index table space if the index object is in a separate table space. In a partitioned database environment, this command will only quiesce the portion on current node.

  5. Run db2dart against the index and table object.


    If the problem is an index NOKEY error, then a number of db2dart commands will be printed in the db2diag.log file. Search for these commands (using eithergrep on UNIX® or find on Windows®) and save them in a file. Edit the file, replace "DBNAME" with the database name. If the problem has been hit multiple times, then there could be some duplicate entries. You only need to keep the latest set of db2dart commands.

    If it is the data manager that reports row not found or bad page, then NO db2dart commands are printed out. You can determine the pool id, object id, data page number from the db2diag.log entries. For example:


    2006-06-17-11.32.59.941406+000 I235565A460 LEVEL: Severe
    PID : 9224396 TID : 1 PROC : db2agent (SAMPLE) 0
    INSTANCE: db2inst NODE : 000 DB : OB8
    APPHDL : 0-78 APPID: ....
    FUNCTION: DB2 UDB, data management, sqldDeleteRow, probe:1329
    RETCODE : ZRC=0x87040001=-2029780991=SQLD_BADPAGE "Bad Data Page"
    DIA8500C A data file error has occurred, record id is "".


    2006-06-17-11.32.59.964241+000 I236403A380 LEVEL: Severe
    PID : 9224396 TID : 1 PROC : db2agent (SAMPLE) 0
    INSTANCE: db2inst NODE : 000 DB : OB8
    APPHDL : 0-78 APPID: ...
    MESSAGE : PAGE OBJECT IDENTIFIERS:
    DATA #1 : String, 54 bytes
    Tablespace ID = 15, Object ID = 8737, Object Type = 0


    2006-06-17-11.32.59.964448+000 I236784A350 LEVEL: Severe
    PID : 9224396 TID : 1 PROC : db2agent (SAMPLE) 0
    INSTANCE: db2inst NODE : 000 DB : OB8
    APPHDL : 0-78 APPID: ...
    MESSAGE : PAGE NUMBERS:
    DATA #1 : String, 35 bytes
    Obj Page = 297, Pool Page = 787527


    In this case, the data page is 787527, pool id is 15 and object id is 8737.

    The commands that you need are:

    1. db2dart <dbname> /dd /tsi <pool id> /oi <object id> /ps <data page number>p /np 1 /v y /scr n /rptn dTsi<poolid>oi<objectid>.rpt

      ...where <data page number> is 787527p using the example above, "p" is used to indicate this is pool relative page which is important for DMS table space.

    2. db2dart <dbname> /di /tsi <pool id> /oi <object id> /ps 0 /np <large enough value to dump all index pages> /v y /scr n /rptn iTsi<poolid>oi<objectid>_0-<pagenum>.rpt.rpt


      Note: The command might take longer to run if a large /np value is specified. Ideally, you should collect as much data as possible. At minimum, it should be no less than 100 pages.

      If table is not too big, also dump the whole table. If the table is too big to dump, select a reasonably large number so that at least a part of the table can be dumped, for example:

      db2dart <dbname> /dd /tsi <pool id> /oi <object id> /ps <data page to start> /np <large enough number> /v y /scr n /rptn dTsi<pool id>oi<object id>_0-<page num>.rpt

      where <data page to start> would be "0" if you want to dump the whole table, or <data page number - 100>p if the table is too big to dump (using the example, that would be "787427p"). Replace the <pool id> and <object id> with the actual number.

  6. Run RUNSTATS to check for any index or data inconsistency. For example:


    db2stop
    db2set DB2_KEYDATACHECK=IXSTATDATADEBUG
    db2start
    db2 connect to <db>
    db2 -v "SELECT INDSCHEMA, INDNAME FROM SYSCAT.INDEXES WHERE TABSCHEMA='<TABLE SCHENAME>' AND TABNAME='<TABLENAME>' "


    Then use the index schema name and index name from the above SELECT output for the following RUNSTATS command:

    db2 -v "runstats on table <tableschema>.<tabname> and index <index schema>.<index name> allow read access"


    NOTE: You need to perform the RUNSTATS on all of the indexes defined on the offending table; after each RUNSTATS command, you need to save the contents of the sqllib/db2dump directory (or DIAGPATH, if you're not using the default path).


    RUNSTATS on a large table could take a while and the table will not be available for updates while RUNSTATS is running. In a multi-partition DPF environment, RUNSTATS is done on a per partition basis.


    If you had quiesced the table space at step 4, then unquiesce the table spaces before you terminate the database connection. You will need to use the same user id for the QUIESCE command in order to reset:


    db2 -v "QUIESCE TABLESPACES FOR TABLE <SCHEMA NAME>.<TABLE NAME> RESET" 


    Once all the RUNSTATS commands are completed, you need to collect the db2diag.log along with the content of sqllib/db2dump (or content of DIAGPATH).

  7. If it is determined that the index is corrupted (that is, if either RUNSTATS or db2dart /t inspection returns with an error), then proceed with rebuilding the index as follows:


    db2 "REORG INDEXES ALL FOR TABLE <SCHEMA NAME>.<TABLE NAME> ALLOW NO ACCESS"


    Applications cannot access your table while the above REORG is running. If you need the table to be available immediately, you can choose to run the above REORG INDEXES command with ALLOW READ ACCESS or ALLOW WRITE ACCESS options. Be aware, however, that the database is at risk of being brought down again if the previous failing application is run against the table before the REORG completes.


    If you are not concerned with root cause analysis of the problem, you do not need to collect any additional information and can skip the subsequent steps.

  8. Collect table or index DDLs. You can use the db2look utility to do so. For example: 

    db2look -d <database> -l -e -a -t <table name> -o table.ddl


  9. Collect transaction log files

    You will only know which log files to collect after a DB2 Support analyst examines the data collected thus far. In general, they will ask you to send a raw log file. In some special cases, they may ask you to format the file and only send the relevant log files. The number of log files required will depend on when the problem was introduced, so it might be necessary to retrieve older log files from archive. 

  10. Additional information that may be important to root cause analysis or known APAR identification. For example:
    • What type of workload is typically running against the table?
    • Did you perform any actions that you don't normally do on this table, for instance any REORG INDEXES/TABLE commands, load or import operations, a high utilities workload, or restore or rollforward operations?
    • Were there any other unusual occurrences? For example, if there were recent hardware problems, provide the operating system error log. This would involve collecting the errpt -a output on AIX® or /var/adm/messages file on Solaris.


http://www-01.ibm.com/support/docview.wss?uid=swg21244563

728x90
728x90


Problem(Abstract)

Tivoli Storage Manager crash

Symptom

Tivoli Storage Manager does not start after crash


Cause

Disk failure on DB2 database files

Diagnosing the problem

During Tivoli Storage Manager start up, the following errors are reported:

ANR0172I rdbdb.c(1465): Error encountered performing action 
ActivateDatabase. 
ANR0162W Supplemental database diagnostic information: -1224:**No State
Information Available (128)**:-1224 (**No Other Information Available 
(206)**). 
ANR0172I rdbdb.c(1009): Error encountered performing action 
InstanceStop. 
ANR0162W Supplemental database diagnostic information: -1032:**No State
Information Available (89)**:-1032 (**No Other Information Available 
(72)**). 

The db2diag.log reports: 

2010-02-19-15.29.08.326780+060 I289570185E438 LEVEL: Warning 
... 
MESSAGE : Crash Recovery is needed. 
2010-02-19-15.30.13.948634+060 I289572079E2547 LEVEL: Severe 
PID : 8492 TID : 47197773097280PROC : db2sysc 0 
INSTANCE: tsmb1 NODE : 000 DB : TSMDB1 
APPHDL : 0-7 APPID: *LOCAL.tsmb1.100219142908 
AUTHID : TSMB1 
EDUID : 65 EDUNAME: db2redow (TSMDB1) 0 
FUNCTION: DB2 UDB, buffer pool services, sqlbVerifyCBITS, probe:1110 
MESSAGE : ZRC=0x86020019=-2046689255=SQLB_CSUM "Bad Page, Checksum 
Error" 
DIA8426C A invalid page checksum was found for page "". 

DATA #1 : String, 64 bytes 
Error encountered trying to read a page - information follows : 
DATA #2 : String, 97 bytes 
CBIT verification error 
bitExpected is 0, userByte is 181, sector 63 (from head of page, 0 
based) 
DATA #3 : Page ID, PD_TYPE_SQLB_PAGE_ID, 4 bytes 
1196993 
DATA #4 : Object descriptor, PD_TYPE_SQLB_OBJECT_DESC, 72 bytes 
Obj: {pool:6;obj:5;type:1} Parent={5;5} 
... 


Resolving the problem

The db2diag messages indicate that the table ID 5 has corruption (see last message line: " {pool:6;obj:5;type:1} ".


You can do two different recoveries.

1) Restore the database to a point in time before the disk corruption occurred,

Or

2) Follow DB2 steps to determine if the corruption is only in the index tables and do a DB2 reorg.

Follow these steps to start the DB2 data collection:
$ db2stop 

SQL1064N DB2STOP processing was successful. 

Now run db2dart command for tablespaceid 6 or run for whole database. 
$ db2dart TSMDB1 /DB 
The requested DB2DART processing has completed successfully! 
Complete DB2DART report found in: 
/home/tsminst1/sqllib/db2dump/DART0000/TSMDB1.RPT 

Messages in RPT file:
Warning: The database state is not consistent.

Warning: Errors reported about reorg rows may be due to the inconsistent state of the database.
 

Error: Duplicate found at same slot in unique index. Lvl(1) Page,slot,rid current:2311036p,1008,x6000050319000000 prev:2311036p,1008,x5100AC5E180000
Error: Duplicate found at same slot in unique index. Lvl(1) Page,slot,rid current:2249254p,344,x0D00071D19000000 prev:2249254p,344,x5700AF5E18000000
Error: Duplicate found at same slot in unique index. Lvl(1) Page,slot,rid current:2248938p,951,x4C00FF7419000000 prev:2248938p,951,x4100BC5E18000000
Error: Duplicate found at same slot in unique index. Lvl(1) Page,slot,rid current:2223926p,957,x55002C6A19000000 prev:2223926p,957,x2A00B95E18000000
Error: Duplicate found at same slot in unique index. Lvl(1) Page,slot,rid current:2223926p,958,x81002C6A19000000 prev:2223926p,958,x2900B95E18000000
Error: Duplicate found at same slot in unique index. Lvl(1) Page,slot,rid current:2223926p,959,x17002C6A19000000 prev:2223926p,959,x2800B95E18000000
Error: Duplicate found at same slot in unique index. Lvl(1) Page,slot,rid current:2223926p,960,x18002C6A19000000 prev:2223926p,960,x2700B95E18000000

Index page corruption can be corrected by running the following command below :

Get the table name (This example is using the message output provided in the message: "{pool:6;obj:5;type:1} "):
db2 "select tabname from syscat.tables where tableid=5 and tbspaceid=6" 

Get the schema name:
db2 list tables 

Run db2 reorg command ( substituting value of schema name. tablename ) 

db2 " REORG INDEXES ALL FOR TABLE schemaname. table_ame ALLOW NO ACCESS"

If there is still an issue, DB2 support will need the full db2dart output for further analysis.


http://www-01.ibm.com/support/docview.wss?uid=swg21421841

http://www.ibm.com/developerworks/data/library/techarticle/dm-1208corruptiondb2/

728x90
728x90
Test scenario:
CREATE TABLE aaa.test( x integer not null, y integer not null, z integer not null )
DB20000I  The SQL command completed successfully.

alter table aaa.test pctfree 10 (테이블은 alter 작업필요)
DB20000I  The SQL command completed successfully.
create index aaa.ind on aaa.test(x,z) pctfree 40 (인덱스는 생성시 지정가능함)
DB20000I  The SQL command completed successfully.
select pctfree from syscat.indexes where indschema='AAA' and indname='IND'
PCTFREE
-------                      <<<<<<<<<<
     40
  1 record(s) selected.
insert into aaa.test with tmp(x,y,z) as ( values (1,1,1) union all select x+1, y+1, z+1 from tmp where x < 100 ) select * from tmp
DB20000I  The SQL command completed successfully.
runstats on table aaa.test with distribution and detailed indexes all
DB20000I  The RUNSTATS command completed successfully.
select pctfree from syscat.tables where tabschema='aaa' and tabname='TEST'
PCTFREE
-------
     10                      <<<<<<<<<<<<<
  1 record(s) selected.


http://www-01.ibm.com/support/docview.wss?uid=swg1LI74223

728x90
728x90

Question

What is the recommended way of running UPDATE STATISTICS in a database so that the optimizer will have the information it needs to run the most efficiently? This article includes a utility to produce an SQL command file that runs all of the UPDATE STATISTICS command recommended for a particular database.

Answer

You can make sure that the optimizer has all of the data it needs to make your queries more efficient by running the SQL command UPDATE STATISTICS on your database. 

    1. Run UPDATE STATISTICS LOW on all tables in the database. 

    2. Run UPDATE STATISTICS MEDIUM on all columns which are in an index, but are not the first column of any index. 

    3. Run UPDATE STATISTICS HIGH on all columns which are the first column in an index. 

    4. Run UPDATE STATISTICS on all stored procedures.

This should be done any time that there are significant changes made to the distribution of the data. 

To make the task of running all of these UPDATE STATISTICS statements easier you could put them into a single SQL command file. 


makeupdate.sql 

Here is a command file named makeupdate.sql that can be used to generate an SQL command file that runs the recommended UPDATE STATISTICS commands for your particular database. 

To use the makeupdate.sql script follow these steps: 
    1. Copy the file makeupdate.sql.txt to a working directory and change the name to makeupdate.sql

      makeupdate.sql.txt

    2. Run the makeupdate.sql command file using dbaccess.

      Example: 

      If your database is named mydb and the makeupdate.sql command file is in your current directory then you can run it by entering this at the command line:

        dbaccess mydb makeupdate.sql

The SQL commands in makeupdate.sql produce an SQL command file named update_stats.sql in the current directory. 

To complete the UPDATE STATISTICS process you must run this SQL command file using dbaccess. 

    Example: 

    If your database is named mydb and the update_stats.sql command file is in your current directory then you can run it by entering this at the command line:
      dbaccess mydb update_stats.sql

You may also consider the Auto Update Statistics (AUS) maintenance system available in IBM™ Informix Dynamic Server version 11.50 and later. Refer to the topic "Automatic statistics updating" in the System Administration section of the Informix 11.50 information center (see Related URL section)


출처:

http://www.ibm.com/support/docview.wss

728x90
728x90

Question

This article provided details of how to write an awk script that can collect information about all active SQL sessions running on an IBM® Informix® Dynamic Server 7.31 database.

Answer

INTRODUCTION

IBM® Informix® Dynamic Server (IDS) version 9.x introduced the ability to collect information for all active SQL sessions by using the command onstat -g sql 0. This functionality can be replicated for IDS version 7.31 databases by using the following awk script.

STEPS

Create an awk script that contains the following text:

BEGIN {system(":> onstat_g_sql_0")}
{
if ($NF > 0) {
my_string= onstat -g sql " $1 "  >> onstat_g_sql_0; echo \"----------------\" >> onstat_g_sql_0"
system(sprintf(my_string))
}
}
END {}


Note: This script directs the SQL information to a file called onstat_g_sql_0 in the current working directory. 

Run this script using the command 

onstat -g sql|tail +6|awk -f <scriptname> 

where scriptname is the name of the awk file created in the previous step. To improve usability, this command could be written as a shell script (with execute permissions) and located in a directory referenced by your PATH environment variable. 

Display the contents of the output file to view the details of all the sql in execution in the database. 

Example 

SQL running on database server
IBM Informix Dynamic Server Version 7.31.UD8     -- on-Line -- Up 00:10:54 -- 8912 Kbytes
Sess  SQL            Current            Iso Lock       SQL  ISAM F.E.
Id    Stmt type      Database           Lvl Mode       ERR  ERR  Vers
13    SELECT         informix_log       CR  Not Wait   0    0    7.31
11    -              informix_log       CR  Not Wait   0    0    7.31


Sample output from awk script

IBM Informix Dynamic Server Version 7.31.UD8     -- on-Line -- Up 00:10:20 -- 8912 Kbytes
Sess  SQL            Current            Iso Lock       SQL  ISAM F.E.
Id    Stmt type      Database           Lvl Mode       ERR  ERR  Vers
13    SELECT         informix_log       CR  Not Wait   0    0    7.31
Current statement name : slctcur
Current SQL statement :
  select * from test2
Last parsed SQL statement :
  select * from test2
----------------
IBM Informix Dynamic Server Version 7.31.UD8     -- on-Line -- Up 00:10:20 -- 8912 Kbytes
Sess  SQL            Current            Iso Lock       SQL  ISAM F.E.
Id    Stmt type      Database           Lvl Mode       ERR  ERR  Vers
11    -              informix_log       CR  Not Wait   0    0    7.31
Last parsed SQL statement :
  UPDATE   test2 set str1="bbb" where key=0
----------------


http://www-01.ibm.com/support/docview.wss?

728x90
728x90

Question

How to increase performance by monitoring when the optimizer chooses to sequential scan a table instead of another alternative access method and then changing the table so that the optimizer selects the optimal method.

Answer

INTRODUCTION

In some circumstances small mistake in managing an IBM® Informix® Dynamic Server™ (IDS) can generate significant performance problems. A common mistake is to not monitor the number of sequential scans in an instance.

Often the Database Administrator (DBA) analysis the tables when they are created but does not continue to monitor their usage, so new users or new applications can query the tables using a different WHERE condition that is not optimized. This can generate sequential scans and in some circumstances can create significant performance problems. The sequential scan is the slowest way to query a table. 

An example is an update or a delete with WHERE conditions. If the table involved in this operation uses an index scan, the rows will be read directly and a lock will be put only on the rows or pages that satisfies the conditions. 

If the optimizer, instead of using an index scan, chooses to perform a sequential scan for the rows that satisfy the conditions, the following problems can arise:

  • Unnecessary pages are read from disk. This mean a lot of I/O operations, loss of hardware resources that can impacts the instance performance.
  • Increase in the number of locks used. If the table is very large and this operation is executed during the peak time, the lock requests can rise until the maximum limit allowed is reached. Other users that are executing operations in different tables will not be able to execute operations that request locks and they will receive an error message.

The most common reasons that can force the optimizer to choose a sequential scan instead of an index scan are listed below: 
  • Lack of appropriate indexes on large tables.
  • Statistics are missing or are not updated correctly using UPDATE STATISTICS.

The command onstat -p can be used to monitor the number of sequential scans that occurred in the instance check the value of " seqscans". If you discover that the number of sequential scans is quite high you need to do the following performance tuning activities: 
  • Query the partition table to identify which tables have a large amount of sequential scans.
  • Understand why the optimizer is not choosing an index scan when accessing those tables.

BEFORE YOU BEGIN

  • If TBLSPACE_STATS configuration parameter in your ONCONFIG is set to 0, the partition profiles is disabled then all columns in the sysptntab will contain the value 0, therefore the methods shown above will not return any useful info.
  • The command onstat -z will reset all the statistical information. If this command was executed recently this can generate false results.
  • When the database instance is started or restarted all the statistical information is reset.


STEPS

To find the name of the tables with a high number of sequential scans and to improve the performance you follow the following steps:

1. Query the partition table to find the tables with a high number of sequential scans

From dbaccess connect to sysmaster then execute the following select:

      SELECT  dbsname,tabname,b.partnum,pf_dskreads,pf_dskwrites,pf_seqscans
      FROM    systabnames as a, sysptntab as b
      WHERE   pf_seqscans > 200 AND a.partnum=b.partnum



This select will display only the tables that had more than 200 sequential scans performed since the database instance was started or since the last onstat -zwas executed. 

Example


dbsname       databasename
tabname       tablename
partnum       2097154
pf_dskreads   265432456
pf_dskwrites  543678954
pf_seqscans   34000



2. Check pf_dskreadspf_dskwrites, this number represents the number of pages read and write from the disk per table. If those numbers are low then it could mean that it is of no great importance to optimize the access method for this table. 

3. If pf_dskreadspf_dskwrites,are quite high then the DBA need to analyse the activity on this table. Try to discover which users are using this table and analyse the SQL statements that they have submitted. 
The command onstat -g sql 0 > file.out can help the DBA to obtain all the sql queries that are being executed in a particular moment. In version 7.x the command onstat -g sql 0 doesn't exist. However you can have the same result executing an awk script, for more information regarding awk look at the Related Information section at the bottom of this article.

4. once you have found the query that you think may generate a sequential scan you can use the sql command SET EXPLAIN on to obtain the path that the optimizer has chosen to execute the query. If the explain output shows a sequential scan try to improve the performance with one of the following actions:

  • Create the appropriate indexes for these queries.
  • Execute UPDATE STATISTICS (medium or high) for these tables. To generate the proper update statistics for your database, have a look at the Article Update statistics script. There is a link to the article at the end of this page.

Alternative methoin Unix or Linux only

The DBA can use a different approach that will avoid part of the activity in the sysmaster. The following command will read directly from the shared memory reducing the impact of the previous select on sysmaster:

1. Execute the following command from prompt:

onstat -g ppf|awk '{ if ($12 > 200) print }' -

where $12 is the twelfth columns that in 7.31, 9.40 and 10.00 represent the column "seqsc" that contain the number of sequential scans executed by the partition. Note that in other informix versions the position of this column "seqsc" can change.

2. Check “isrd” “iswrt” that represent the number of pages read and write related to this table. If those numbers are low it could mean that it is not important to optimize the sequential scan for this table.

3. Transform the partnum into decimal form. 

4. To find the name of the table, from dbaccess connect to sysmaster then execute the following select:


SELECT dbsname, tabname 
FROM systabnames 
WHERE partnum= xxxx    
</code>
where xxxx is the partnum transformed in decimal. 


5. once you have found the query that you think may generate a sequential scan you can use the sql command  SET EXPLAIN on to obtain the path that the optimizer has chosen to execute the query. If the explain output shows a sequential scan try to improve the performance with one of the following actions:

  • Create the appropriate indexes for these queries.
  • Execute UPDATE STATISTICS (medium or high) for these tables.



http://www-01.ibm.com/support/docview.wss?uid=swg21156390

728x90
728x90

By specifying the CURSOR file type when using the LOAD command, you can load the results of an SQL query directly into a target table without creating an intermediate exported file.

Additionally, you can load data from another database by referencing a nickname within the SQL query, by using the DATABASE option within the DECLARE CURSOR statement, or by using the sqlu_remotefetch_entry media entry when using the API interface.

There are three approaches for moving data using the CURSOR file type. The first approach uses the Command Line Processor (CLP), the second the API, and the third uses the ADMIN_CMD procedure. The key differences between the CLP and the ADMIN_CMD procedure are outlined in the following table.

Table 1. Differences between the CLP and ADMIN_CMD procedure.
DifferencesCLPADMIN_CMD_procedure
SyntaxThe query statement as well as the source database used by the cursor are defined outside of the LOAD command using a DECLARE CURSOR statement.The query statement as well as the source database used by the cursor is defined within the LOAD command using the LOAD from (DATABASE database-alias query-statement)
User authorization for accessing a different databaseIf the data is in a different database than the one you currently connect to, the DATABASE keyword must be used in the DECLARE CURSOR statement. You can specify the user id and password in the same statement as well. If the user id and password are not specified in the DECLARE CURSOR statement, the user id and password explicitly specified for the source database connection are used to access the target database.If the data is in a different database than the one you are currently connected to, the DATABASE keyword must be used in the LOAD command before the query statement. The user id and password explicitly specified for the source database connection are required to access the target database. You cannot specify a userid or password for the source database. Therefore, if no userid and password were specified when the connection to the target database was made, or the userid and password specified cannot be used to authenticate against the source database, the ADMIN_CMD procedure cannot be used to perform the load.

To execute a LOAD FROM CURSOR operation from the CLP, a cursor must first be declared against an SQL query. once this is declared, you can issue the LOAD command using the declared cursor's name as the cursorname and CURSOR as the file type.

For example:

  1. Suppose a source and target table both reside in the same database with the following definitions:
    Table ABC.TABLE1 has 3 columns:
    • ONE INT
    • TWO CHAR(10)
    • THREE DATE
    Table ABC.TABLE2 has 3 columns:
    • ONE VARCHAR
    • TWO INT
    • THREE DATE
    Executing the following CLP commands will load all the data from ABC.TABLE1 into ABC.TABLE2:
    DECLARE mycurs CURSOR FOR SELECT TWO, onE, THREE FROM abc.table1
       LOAD FROM mycurs OF cursor INSERT INTO abc.table2
    Note: The above example shows how to load from an SQL query through the CLP. However, loading from an SQL query can also be accomplished through the db2Load API. Define the piSourceList of the sqlu_media_list structure to use the sqlu_statement_entry structure and SQLU_SQL_STMT media type and define the piFileType value as SQL_CURSOR.
  2. Suppose the source and target tables reside in different databases with the following definitions:
Table ABC.TABLE1 in database 'dbsource' has 3 columns:
  • ONE INT
  • TWO CHAR(10)
  • THREE DATE
Table ABC.TABLE2 in database 'dbtarget' has 3 columns:
  • ONE VARCHAR
  • TWO INT
  • THREE DATE
Provided that you have enabled federation and cataloged the data source ('dsdbsource'), you can declare a nickname against the source database, then declare a cursor against this nickname, and invoke the LOAD command with the FROM CURSOR option, as demonstrated in the following example:
CREATE NICKNAME myschema1.table1 FOR dsdbsource.abc.table1 
DECLARE mycurs CURSOR FOR SELECT TWO,ONE,THREE FROM myschema1.table1 
LOAD FROM mycurs OF cursor INSERT INTO abc.table2 
Or, you can use the DATABASE option of the DECLARE CURSOR statement, as demonstrated in the following example:
DECLARE mycurs CURSOR DATABASE dbsource USER dsciaraf USING mypasswd 
FOR SELECT TWO,ONE,THREE FROM abc.table1 
LOAD FROM mycurs OF cursor INSERT INTO abc.table2

Using the DATABASE option of the DECLARE CURSOR statement (also known as the remotefetch media type when using the Load API) has some benefits over the nickname approach:

Performance

Fetching of data using the remotefetch media type is tightly integrated within a load operation. There are fewer layers of transition to fetch a record compared to the nickname approach. Additionally, when source and target tables are distributed identically in a multi-partition database, the load utility can parallelize the fetching of data, which can further improve performance.

Ease of use

There is no need to enable federation, define a remote datasource, or declare a nickname. Specifying the DATABASE option (and the USER andUSING options if necessary) is all that is required.

While this method can be used with cataloged databases, the use of nicknames provides a robust facility for fetching from various data sources which cannot simply be cataloged.

To support this remotefetch functionality, the load utility makes use of infrastructure which supports the SOURCEUSEREXIT facility. The load utility spawns a process which executes as an application to manage the connection to the source database and perform the fetch. This application is associated with its own transaction and is not associated with the transaction under which the load utility is running.

Note:
  1. The previous example shows how to load from an SQL query against a cataloged database through the CLP using the DATABASE option of the DECLARE CURSOR statement. However, loading from an SQL query against a cataloged database can also be done through the db2LoadAPI, by defining the piSourceList and piFileTypevalues of the db2LoadStruct structure to use the sqlu_remotefetch_entry media entry and SQLU_REMOTEFETCH media type respectively.
  2. As demonstrated in the previous example, the source column types of the SQL query do not need to be identical to their target column types, although they do have to be compatible.

Restrictions

When loading from a cursor defined using the DATABASE option (or equivalently when using the sqlu_remotefetch_entry media entry with thedb2Load API), the following restrictions apply:
  1. The SOURCEUSEREXIT option cannot be specified concurrently.
  2. The METHOD N option is not supported.
  3. The usedefaults file type modifier is not supported.



http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.admin.dm.doc/doc/c0005437.html

728x90
728x90

SQL30082N Security processing failed with reason “26″


SQL Error [28000]: [jcc][t4][207][11243][3.59.81] Connection authorization failure occurred.  Reason: GSSAPI non-retryable error. ERRORCODE=-4214, SQLSTATE=28000


DB2 JDBC및 Native Client 연결 관련하여 다음과 같은 오류가 발생하여, 검색한 결과 유사한 내용을 찾을 수 있었습니다.

linux에서 설정하는 패스워드 알고리즘 관련 문제였습니다. 참고하시기 바랍니다.


If you are getting

SQL30082N Security processing failed with reason „15“ („PROCESSING FAILURE“)

when connecting to the db2 database using db2 CONNECT TO dbname USER username or

Connection authorization failure occurred. Reason: Local security service non-retryable error. ERRORCODE=-4214, SQLSTATE=28000

when connecting remotely (via JDBC driver) read on. I finally found what causes this error and a solution!

[ad]

Environment

Problem

Tho whole problem is in the format of the passwords in/etc/shadow. DB2 doesn't seem to like the passwords generated when changing password using the standard passwd command. In Fedora Core 10 the password is hashed using sha-512 and the entry for user username looks like:

username:$6$ef­WWOYRY$z5DNL1kLQ­U4AmPkFBqbQh6LOh­0Qjxq654dS9jE46iP­Np8Zces8I4bP8GLZ3G3RWLo/­6o.LYOV5neYSKxXbL­.M1:14375:0:99999:7:::

Solution

DB2 works fine with passwords hashed with standard crypt function. Password in the desired format can be obtained by callingopenssl passwd desiredPassword. The output of openssl can be passed to usermod --password The complete command to change user's password then look like:

usermod --password `openssl passwd desiredPassword`usename

Bigger image

I tried to hand-edit /etc/shadow and insert salted MD5 password, which can be obtained by openssl passwd -1 desiredPasswordand the connection was sucessfuly established. To sum it up, the whole problem in the end seems to be that DB2 doesn't like SHA-512 hashes in /etc/shadow. on the other hand, it works fine with hashes generated by crypt and MD5.

Changing default algorithm in Fedora Core

Fedora Core contains a nice tool authconfig. To change the default hashing algorithm to MD5 run

authconfig –passalgo md5 –update

All the passwords inserted in the password database will be stored in MD5 from now on. It will, of course, not change the hashes of the current passwords.

Ubuntu

Ubuntu ships with sha512 as default hash algorithm for passwords in /etc/shadow. The easiest way to change the default algorithm is to edit the file /etc/pam.d/common-password and change the line that reads

password [success=1 default=ignore] pam_unix.so obscure sha512

to

password [success=1 default=ignore] pam_unix.so obscure md5

The information about the algorith is also included in the file/etc/login.defs, which is used by chpasswd for example. Therefore change the line

ENCRYPT_METHOD SHA512

to

ENCRYPT_METHOD MD5



http://blog.stastnarodina.com/honza-en/spot/db2-sql30082n-security-processing-failed-with-reason-15/

http://www-01.ibm.com/support/docview.wss?uid=swg21623221

728x90
728x90

Problem(Abstract)

db2diag.log file may get filled with "Detected client termination" error messages.

Symptom

Following errors may be seen in db2diag.log file.

2012-10-07-03.31.44.562773+480 I559988E520 LEVEL: Error

    PID : 2160 TID : 140574011156224PROC : db2sysc 
    INSTANCE: db2inst1 NODE : 000 DB : SAMPLE 
    APPHDL : 0-4470 APPID: 202.27.30.1.2101.121006192554 
    AUTHID : PSOGALAG 
    EDUID : 568 EDUNAME: db2agent (SAMPLE) 
    FUNCTION: DB2 UDB, common communicati on, sqlcctest, probe:50 
    MESSAGE : sqlcctest RC 
    DATA #1 : Hexdump, 2 bytes 
    0x00007FD9EFFF6780 : 3600 

    2012-10-07-03.31.44.543149+480 I560509E538 LEVEL: Error 
    PID : 2160 TID : 140574002767616PROC : db2sysc 
    INSTANCE: db2inst1 NODE : 000 DB : SAMPLE 
    APPHDL : 0-4510 APPID: 202.27.30.1.2286.121006192634 
    AUTHID : PSOGALAD 
    EDUID : 570 EDUNAME: db2agent (SAMPLE) 
    FUNCTION: DB2 UDB, common communication, sqlcctcptest, probe:11 
    MESSAGE : Detected client termination 
    DATA #1 : Hexdump, 2 bytes 
    0x00007FD9EF7F6748 : 3600 


Resolving the problem

Function sqlcctcptest() tests if the client connection is active and function sqlcctest() tests whether the connection is still valid.


If you don't want such messages to be logged into db2diag.log file, you can set DB2CHECKCLIENTINTERVAL to zero.

For Example : Issue following:

    1) db2set DB2CHECKCLIENTINTERVAL=0 
    2) db2stop 
    3) db2start

Note : This variable specifies the frequency of TCP/IP client connection verifications during an active transaction. It permits early detection of client termination, instead of waiting until after the completion of the query. If this variable is set to 0, no verification is performed.


http://www-01.ibm.com/support/docview.wss?uid=swg21613530

728x90

+ Recent posts