Saturday, 31 May 2014

How to create and use sequence on DB2

How to create and use sequence on DB2

Using Sequences

    CREATE SEQUENCE SEQ1 AS INTEGER
By default the sequence number starts at one and increments by one at a time and is of an INTEGER data type. The application needs to get the next value in the sequence by using the NEXT VALUE function. This function generates the next value for the sequence which can then be used for subsequent SQL statements:
VALUES NEXT VALUE FOR SEQ1
Instead of generating the next number with the VALUES function, the programmer could have used this function within an INSERT statement. For instance, if the first column of the customer table contained the customer number, an INSERT statement could be written as follows:
    INSERT INTO employee VALUES
      (NEXT VALUE FOR SEQ1, 'comment', ...)
If the sequence number needs to be used for inserts into other tables, the PREVIOUS VALUE function can be used to retrieve the previously generated value. For instance, if the customer number just created needs to be used for a subsequent invoice record, the SQL would include the PREVIOUS VALUE function:
    INSERT INTO invoices
      (34,PREVIOUS VALUE FOR SEQ1, 234.44, ...)
The PREVIOUS VALUE function can be used multiple times within the application and it will only return the last value generated by that application. It may be possible that subsequent transactions have already incremented the sequence to another value, but you will always see the last number that is generated


Dropping sequence

 DROP SEQUENCE <sequence_name>

Thursday, 29 May 2014

How to Create and Compile USER EXIT

How to Create and Compile USER EXIT

A user exit is an executable file that the DBMS calls for archive and retrieval of log files.
 Sample user exit are supplied in $HOME/sqllib/samples/c of the instance owner. At the beginning of each sample file is a good description on how DB2 uses the specific user exit and which parameters you should set. For Tivoli Storage Manager, the user exit sample is db2uext2.cadsm. Perform the following steps to create the user exit executable.

1. Become root, then copy the db2uext2.cadsm to your working directory and
rename it to db2uext2.c. Change file ownership and permissions so the
instance owner can modify the code.

2. Read the comments at the beginning of the source code to understand the
defined variables. Change the defined variables to suit your environment.
In our lab, we took the default setting and only change the path of the user
exit logfiles (AUDIT_ERROR_PATH).

3. As the instance owner, compile the C program. In our lab, we used the
Visual Age C Compiler V4.4. Check your compiler for the correct syntax.
The implementation of the use exit requires a full offline database backup
in order to become effective. Ensure that you allocate sufficient time for
doing this backup.
Note
#define BUFFER_SIZE 4096 /* transmit or receive the log */
/* file in 4k portions */
#define AUDIT_ACTIVE 1 /* enable audit trail logging */
#define ERROR_ACTIVE 1 /* enable error trail logging */
#define AUDIT_ERROR_PATH "/home/db2inst2/tsm/" /* path must en
d with a slash */
#define AUDIT_ERROR_ATTR "a" /* append to text file */
compilar 32bits:
$ cc -I/opt/tivoli/tsm/client/api/bin/samples -L/usr/lib -lApiDS -o db2uext2 db2uext2.c
compilar 64bits: (com o ususário root)
/usr/vacpp/bin/cc_r -o db2uext2 -q64 db2uext2.c /usr/tivoli/tsm/client/api/bin64/libApiTSM64.a -I/usr/tivoli/tsm/client/api/bin64/sample

4. Copy the db2uext2 file into the $HOME/sqllib/adm directory of the
instance owner. We do not recommend that you copy the file to the
$HOME/sqllib/bin directory, because this directory is only a link to a
directory in the /opt/IBMdb2/V7.1/bin directory. Make sure the instance
owner has execute permission for this file.

How to create an instance on Unix

How to create an instance on Unix

A more detailed explanation over creating an instance on unix systems

How to create an instance

To create an instance you should go to the directory where db2icrt can be found:
On DB2 8 the default path is:
/usr/opt/db2_08_01/instance
Then run the command ./db2icrt –u <instance_name> <instance_name> as root.
Example:
./db2icrt -u instdb2 instdb2
[YOU HAVE NEW MAIL]
DBI1070I Program db2icrt completed successfully.
The next thing you should do is to check and configure the ports used by the  instance on the /etc/services file.
To do that add these lines to the /etc/services files:
<instance_name> + c    <port number>      #connection port
<instance_name> + i     <port number+1>  #interrupt port
Note 1: to edit the /etc/services file use the command:
sudo vi /etc/services
Note 2: make sure you are using available and  that you have permission to use the port you are using with your system admin
Example:
instdb2c      3708/tcp           #connection port
instdb2i       3709/tcp           #interrupt port
After that log on the instance user and configure the DB2COMM variable:
# su - <instance user>$ db2set DB2COMM=tcpip
Now set the AUTHENTICATION and SVCNAME parameters on DBM CFG:
$ db2 update dbm cfg using AUTHENTICATION <auth_type>
$ db2 update dbm cfg using svcename <instance_name> + c
Exemplo:
$ db2 update dbm cfg using AUTHENTICATION SERVER
$ db2 update dbm cfg using svcename instdb2c
And start the instance:
$ db2start
Check your instance with the db2level and db2ilist commands:
Example:
db2level 
DB21085I  Instance "instdb2" uses "32" bits and DB2 
code release "SQL08021" with level identifier"03020106".
Informational tokens are "DB2 v8.1.1.82","OD_14081", 
U803799_14081", and FixPak "8". Product is installed at
"/usr/opt/db2_08_01".

Wednesday, 28 May 2014

How to create an event monitor

How to create an event monitor

Event monitors are database objects, and as such, they are created and manipulated using SQL statements

Event monitor life cycle

The steps listed below represent a typical life cycle of an event monitor.

1. Create an event monitor.
2. Activate the newly created event monitor to enable it to collect information.
3. Read event monitor output.
4. If you don’t want to collect event information for some time, you can deactivate the event monitor.
5. To eliminate an event monitor object, use the DROP EVENT MONITOR

Note: By default, all databases have an event monitor named DB2DETAILDEADLOCK defined, which keeps track of DEADLOCKS WITH DETAILS. The DB2DETAILDEADLOCK
event monitor starts automatically when the database starts.

CREATE EVENT MONITOR
CREATE EVENT MONITOR event_monitor_name FOR
{DATABASE |
TABLES |
DEADLOCKS [WITH DETAILS] |
TABLE SPACES |
BUFFERPOOLS |
CONNECTIONS [WHERE event_condition] |
STATEMENTS [WHERE event_condition] |
TRANSACTIONS [WHERE event_condition] }
WRITE TO FILE file_path [{APPEND | REPLACE}]
[{MANUAL START | AUTOSTART}]


CREATE EVENT MONITOR parameters


  • DEADLOCKS WITH DETAILS specifies that the event monitor is to generate more detailed information for each application that is involved in a deadlock. This additional detail includes:
    - Information about the statement that the application was executing when the 
      deadlock occurred, such as the statement text
    - The locks held by the application when the deadlock occurred.

  • WHERE event_condition defines a filter that determines which connections cause a CONNECTION, STATEMENT or TRANSACTION event to occur. The following comparison options are available: APPL_ID (application ID), AUTH_ID (authorization ID), and APPL_NAME (name of application). Multiple conditions can be combined with AND / OR. For example: WHERE APPL_NAME = 'PAYROLL' AND AUTH_ID = 'JSMITH'.
  • WRITE TO FILE file_path Indicates that the target for the event monitor data is a file. The event monitor writes out the stream of data as a series of 8 character numbered files, with the extension "evt". Path-name specifies the name of the directory in which the event monitor should write the event files data.
  • APPEND specifies that if event data files already exist when the event monitor is turned on, then the event monitor will append the new event data to the existing stream of data files. APPEND is the default option.
  • REPLACE specifies that if event data files already exist when the event monitor is turned on, then the event monitor will erase all of the event files and start writing data to file 00000000.evt.
  • MANUALSTART specifies that the event monitor not be started automatically each time the database is started. Event monitors with the MANUALSTART option must be activated manually using the SET EVENT MONITOR STATE statement. This is the default option.
  • AUTOSTART specifies that the event monitor be started automatically each time the database is started.

Creating Event Monitor Examples



  • Creates an event monitor called SMITHPAY. This event monitor, will collect event data for the database as well as for the SQL statements performed by the PAYROLL application owned by the JSMITH authorization ID. The data will be appended to the absolute path /home/jsmith/event/smithpay/.
CREATE EVENT MONITOR SMITHPAY
FOR DATABASE, STATEMENTS WHERE APPL_NAME = 'PAYROLL' AND AUTH_ID = 'JSMITH'
WRITE TO FILE '/home/jsmith/event/smithpay' APPEND

  • Creates an event monitor called DEADLOCKS_EVTS. This event monitor will collect deadlock events and will write them to the relative path DLOCKS. The file will be replaced. The event monitor will be started each time the database is started.
CREATE EVENT MONITOR DEADLOCK_EVTS
FOR DEADLOCKS
WRITE TO FILE '/home/jsmith/event/dlocks' REPLACE AUTOSTART

  • Creates an event monitor called DB_APPLS. This event monitor collects connection events, and writes the data to the path /home/jsmith/appl.
CREATE EVENT MONITOR DB_APPLS
FOR CONNECTIONS
WRITE TO FILE '/home/jsmith/appl'



Activating and Deactivating Event Monitors



  • When event monitors are created with AUTOSTART they will start collecting data when the database they are associated with is activated. If the MANUAL START option was used instead or if no option was specified, an event monitor will not begin collecting data until it is activated.
  • Event monitors are activated/deactivated with the SET EVENT MONITOR statement:
SET EVENT MONITOR event_monitor_name STATE [0 | 1]

0 indicates that the specified event monitor should be deactivated.
1 indicates that the specified event monitor should be activated.

  • Example: Starting the event SMITHPAY
SET EVENT MONITOR SMITHPAY STATE 1


Flushing an event monitor



  • Because some events do not happen as frequently as others, it may be desirable to force an event monitor to collect monitor data and write it to its target location before a monitor triggering event takes place.
  • In such situations, an event monitor can be made to collect information early by executing the FLUSH EVENT MONITOR SQL statement.
FLUSH EVENT MONITOR [event_monitor_name]

Example:
FLUSH EVENT MONITOR DB_APPLS

Checking Event Monitors States



  • To see if an event monitor is active or inactive, issue the SQL function EVENT_MON_STATE in a query against the table, SYSCAT.EVENTMONITORS:
SELECT evmonname, EVENT_MON_STATE(evmonname) FROM syscat.eventmonitors

  • A list of all existing event monitors will be listed, along with their status. A returned value of 0 indicates that the specified event monitor is inactive, and 1 indicates that it is active.

Example:

SELECT evmonname, EVENT_MON_STATE(evmonname) FROM syscat.eventmonitors EVMONNAME 2
------------------------------- ----
DB2DETAILDEADLOCK 1


Viewing Event Monitor Data


  • To format the event monitor files use the db2evmon tool.
db2evmon -db database-alias -evm event-monitor-name
or
db2evmon -path event-monitor-target
  1. db database-alias specifies the database whose data is to be displayed. This parameter is case sensitive.
  2. evm event-monitor-name the one-part name of the event monitor. An ordinary or delimited SQL identifier. This parameter is case sensitive.
  3. path event-monitor-target specifies the directory containing the eventmonitor trace files.


Example:
db2evmon -db sample -evm DB_APPLS > db_appls.out

Dropping an event monitor



When the event monitor is no longer needed it can be dropped:

drop event monitor event-monitor-name

Example:

drop event monitor DB_APPLS

Monday, 26 May 2014

How to create a view without dirty reads

How to create a view without dirty reads

use the option "with no row movement" to create views dirty reads

Example how to create a view without dirty reads:

db2 create view teste_view as "select EMPNO from employee where FIRSTNME='MICHAEL' WITH NO ROW MOVEMENT"

How to create a table with identity column

How to create a table with identity column

   Execute the statement below:

db2 "CREATE TABLE <table_name> (dep INT, name char(35), cod INT NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 10, INCREMENT BY 3))"

Sunday, 25 May 2014

How to create a simple trigger on DB2

How to create a simple trigger on DB2

a little example how to create a simple trigger on DB2

See the example below, how to create a trigger, and check how it works.

db2 "create table table_1 (cod int)"
db2 "create table table_2 (cod2 int)"
db2 "create trigger trig1 after insert on table_1 for each row update table_2  set cod2 = cod2 +1  where cod2 > 0"
db2 "insert into table_2 values (1)"
db2 "insert into table_2 values (2)"
db2 "insert into table_2 values (3)"
db2 "insert into table_2 values (4)"
db2 "insert into table_2 values (5)"
db2 "insert into table_2 values (5)"
 db2 "select * from table_2"
Output:

COD2      
-----------
          1
          2
          3
          4
          5
          6

  6 record(s) selected.

db2 "insert into table_1 values (1)"

 db2 "select * from table_2"
Output:

COD2      
-----------
          2
          3
          4
          5
          6
          7
  6 record(s) selected.
If the table_1 is 10 values, example:

 db2 "select * from table_1"

COD      
-----------

          1
          2
          3
          4
          5
          6
          7
          8
          9
         10

  10  record(s) selected.

and the values of table_2 is:


 db2 "select * from table_2"

COD2      
-----------

          1
          2
          3
          4
          5
          6  
     6  record(s) selected.

db2 "insert into table table_1 (select * from table_1 )

After the statement above, we have:

 db2 "select * from table_2"

COD2      
-----------
          11
          12
          13
          14
          15
          16  

       6  record(s) selected.


If you are using the clause "for each statement" instead of "for each row", you will have the results below:


COD2      
-----------
          2
          3
          4
          5
          6
          7  

       6  record(s) selected.

This trigger will be:

db2 "create trigger trig1 after insert on table_1 for each statement update table_2  set cod2 = cod2 +1  where cod2 > 0"

Friday, 23 May 2014

How to convert milliseconds, seconds, minutes to DATE on DB2

How to convert milliseconds, seconds, minutes to DATE on DB2

converting milliseconds, seconds, minutes, days to date on DB2


Milliseconds to DATE:


Where, 1970-01-01, is the start date to calculate this function. The date 1970-01-01is defined as "THE EDGE".

db2 "SELECT( date('1970-01-01')  + (millisecondsfield / 86400000) days   ) as date"

Example:

Creating the table to pratice our examples:
db2 "create table mili (miliseconds bigint)"
db2 "insert into mili (miliseconds) values (1233291600000)"
Performing the select
db2 "SELECT( date('1970-01-01')  + (milliseconds / 86400000) days   ) as date"
Output:

DATE      
----------
01/30/2009

  1 record(s) selected.

Seconds to DATE:


Where, 1970-01-01, is the start date to calculate this function. The date 1970-01-01is defined as "THE EDGE".

db2 "SELECT( date('1970-01-01')  + (seconds / 86400) days   ) as date"

Example:

Creating the table to pratice our examples:
db2 "create table mili (seconds bigint)"
db2 "insert into mili (seconds) values (1233291600)"
Performing the select
db2 "SELECT( date('1970-01-01')  + (seconds / 86400) days   ) as date"
Output:

DATE      
----------
01/30/2009

  1 record(s) selected.

Minutes to DATE:


Where, 1970-01-01, is the start date to calculate this function. The date 1970-01-01is defined as "THE EDGE".

db2 "SELECT( date('1970-01-01')  + (minites / 1140) days   ) as date"

Example:

Creating the table to pratice our examples:
db2 "create table mili (minutes bigint)"
db2 "insert into mili (minutes) values (20554860)"
Performing the select
db2 "SELECT( date('1970-01-01')  + (minitues / 1440) days   ) as date"
Output:

DATE      
----------
01/30/2009

  1 record(s) selected.

Hours to DATE:


Where, 1970-01-01, is the start date to calculate this function. The date 1970-01-01is defined as "THE EDGE".

db2 "SELECT( date('1970-01-01')  + (hours / 24) days   ) as date"

Example:

Creating the table to practice our examples:
db2 "create table mili (hours bigint)"
db2 "insert into mili (hours) values (342581)"
Performing the select
db2 "SELECT( date('1970-01-01')  + (hours / 24) days   ) as date"
Output:

DATE      
----------
01/30/2009

  1 record(s) selected.

Thursday, 22 May 2014

How to convert data types on DB2

How to convert data types on DB2

cast functions to convert data type or db2 functions to convert data types
On DB2 you have two ways to convert DATA TYPES: 
We are going to use the table below for our examples:
db2 describe table example
Output:                                                             
Column name                     schema    Data type name      Column Length     Scale      Nulls
----------------------------------- ------------ ----------------------- ----------------------------- --------- --------
COD                                     SYSIBM      INTEGER                             4                        0        Yes   
NAME                                  SYSIBM      VARCHAR                         40                        0        Yes   
ENTRANCE                       SYSIBM      DATE                                    4                         0        Yes   
VALUE                                SYSIBM      DOUBLE                               8                        0        Yes   

Data:

db2 select * from example
COD         NAME                                                   ENTRANCE    VALUE                  
----------- ---------------------------------------------- --------------------- ------------------------
     1                                              William                   10/15/2009   +3.22900000000000E+002
     2                                                       38                   12/23/2009   +4.59000000000000E+001
     3                                             Barbara                  02/03/2009   +1.43000000000000E+000
234                                                        40                  02/30/2009   +2.30000000000000E+001



FIRST WAY - USING FUNCTION CAST


Example A
db2 "select cod, cast(name as int) as name from example where name in ('38','40')"

Example B
db2 "select cast(cod as char) from example"


SECOND WAY



Example A
db2 "select cod, int(name) as name from example where name in ('38','40')"

Example B

db2 "select char(cod) from example"

Wednesday, 21 May 2014

How to convert columns to rows and rows to columns

How to convert columns to rows and rows to columns

unsing pivot and unpivot query

Pivoting



The first will convert rows into columns.

Let's assume that we have the following table definition
CREATE TABLE Sales (Year INT, Quarter INT, Results INT)

Which contains the following data
YEAR        QUARTER     RESULTS
----------- ----------- -----------
       2004           1          20
       2004           2          30
       2004           3          15
       2004           4          10
       2005           1          18
       2005           2          40
       2005           3          12
       2005           4          27


What I want is a query that shows one row per year with each column being the results of the sales by quarter (i.e. one column per quarter). This is the result I want to see

YEAR        Q1          Q2          Q3          Q4
----------- ----------- ----------- ----------- -----------
       2004          20          30          15          10
       2005          18          40          12          27


Here is the query that gives this to you.

SELECT Year,
       MAX(CASE WHEN Quarter = 1
           THEN Results END) AS Q1,
       MAX(CASE WHEN Quarter = 2
           THEN Results END) AS Q2,
       MAX(CASE WHEN Quarter = 3
           THEN Results END) AS Q3,
       MAX(CASE WHEN Quarter = 4
           THEN Results END) AS Q4
FROM Sales
GROUP BY Year


In this query we scan the SALES table and return the Year followed by 4 other columns. If we ignore the GROUP BY for one moment, the value of the 4 columns will be either the value in the RESULTS column if the Quarter is equal to the Quarter in the CASE expression or it will be NULL if it doesn't match. Here is what the results would look like if there was no GROUP BY clause (and no MAX function).

YEAR        Q1          Q2          Q3          Q4
----------- ----------- ----------- ----------- -----------
       2004          20           -           -           -
       2004           -          30           -           -
       2004           -           -          15           -
       2004           -           -           -          10
       2005          18           -           -           -
       2005           -          40           -           -
       2005           -           -          12           -
       2005           -           -           -          27


Then we use the MAX function and group by YEAR. This results in one row per year with the RESULTS in each of the 4 quarter columns. The MAX function is used here as it works with all compatible data types including strings.



Unpivoting


CREATE TABLE SalesAgg
(  year INTEGER,
   q1 INTEGER,
   q2 INTEGER,
   q3 INTEGER,
   q4 INTEGER );


With the following data in it:

YEAR        Q1          Q2          Q3          Q4
----------- ----------- ----------- ----------- -----------
       2004          20          30          15          10
       2005          18          40          12          27


But what I want is to produce one row for each Year/Quarter combination with the 3rd column being the results that appear in the year/quarter cell above. Here are the results I'm looking for:

YEAR        QUARTER     RESULTS
----------- ----------- -----------
       2004           1          20
       2004           2          30
       2004           3          15
       2004           4          10
       2005           1          18
       2005           2          40
       2005           3          12
       2005           4          27


Here is the query that will produce these results very efficiently:

SELECT S.Year, Q.Quarter, Q.Results
FROM SalesAgg AS S,
     TABLE (VALUES(1, S.q1),
                  (2, S.q2),
                  (3, S.q3),
                  (4, S.q4))
            AS Q(Quarter, Results);


What is this query doing? The first thing it does is pull out the Year from the SALESAGG table (S.YEAR) then we pull out the Q.Quarter and Q.Results columns. But what is this Q table? This refers to the table function listed in the FROM clause. This table function uses that multi line VALUES clause that I referred to in my previous posting which creates a table out of nowhere. But in this case we are actually using a correlated query. Within the values clause you can see a reference to the columns of S (S.q1, S.q2, S.q3, S.q4).
What is happening here is that for every row we pull out of SalesAgg we get the year value and then combine that with the quarter number (1,2,3,4 which is the first value in the VALUES clause) and then the results which is the value of S.Q1, S.Q2, S.Q3 and S.Q4. But instead of showing then as separate columns this VALUES clause shows them as 4 separate rows. And all with only one pass of the data.


Author: Chris Eaton (Product Manager, IBM)

how to compress a db2diag file

how to compress a db2diag file

How to compress and create a new db2diag.log
If you need to compress the db2diag and create a new one follow the steps below:
1-  Finding the db2diag.log path
at the prompting command type:
db2 get dbm cfg | grep -i diag
You will see something like this:
server :# db2 get dbm cfg | grep -i diag
 Diagnostic error capture level              (DIAGLEVEL) = 3
 Diagnostic data directory path             (DIAGPATH) = /db2/instance1/sqllib/db2dump
2 -  Going to db2diag.log path
at the promptig command type:
cd /db2/instance1/sqllib/db2dump
ls - ltr | grep -i diag
You will see something like this:
-rw-r-----   1 sample  db2iadm1    6291344 Mar 11 16:30 db2eventlog.000.crash
-rw-rw-rw-   1 sample  db2iadm1   19745333 Apr 07 15:53 db2diag.log.old.gz
-rw-rw-rw-   1 sample  db2iadm1      19580 Apr 23 06:50 sample.nfy
-rw-r-----   1 sample  db2iadm1    6291344 Jun 23 23:41 db2eventlog.000
-rw-r--r--   1 sample  db2iadm1  688961095 Jun 23 23:53 db2diag.log
3 - Creating a new one db2diag.log
at the prompting command type:
db2diag -A
You will see something like this:
/usr/local/db2/sample/sqllib/db2dump>db2diag -A
db2diag: Moving "/usr/local/db2/sample/sqllib/db2dump/db2diag.log"                     to     "/usr/local/db2/sample/sqllib/db2dump/db2diag.log_2008-06-24-21.13.31"
4-  Compressing the old db2diag.log
at the prompting command type:
compress db2diag.log

Monday, 19 May 2014

How to ckeck the application priority

How to ckeck the application priority

db2pd -agents | get snapshot for applications

Using db2pd


db2pd -agents

Database Partition 4294967295 -- Active -- Up 0 days 00:04:43

Agents:
Current agents:      7
Idle agents:         0
Active coord agents: 7
Active agents total: 7
Pooled coord agents: 0
Pooled agents total: 0

Address    AppHandl [nod-index] AgentEDUID Priority   Type     State       ClientPid  Userid   ClientNm Rowsread   Rowswrtn   LkTmOt DBName  
0x10466890 204      [000-00204] 18                   Coord    Inst-Active 9732       db2inst1 db2bp    0          0          NotSet n/a     
0x1046DE60 235      [000-00235] 34      -10         Coord    Inst-Active 9732       db2inst1 db2bp    59497      0          NotSet SAMPLE  
0x10467A60 236      [000-00236] 45         0           Coord    Inst-Active 9732       db2inst1 db2stmm  0          0          NotSet SAMPLE  
0x10468C30 237      [000-00237] 46                   Coord    Inst-Active 9732       db2inst1 db2taskd 2          0          NotSet SAMPLE  
0x10469E00 238      [000-00238] 47         0           Coord    Inst-Active 9732       db2inst1 db2wlmd  0          0          NotSet SAMPLE  
0x1046AFD0 239      [000-00239] 48         0           Coord    Inst-Active 9732       db2inst1 db2evmg_ 0          0          3           SAMPLE  
0x1046CC90 257      [000-00257] 33         0           Coord    Inst-Active 9623       db2inst1 db2govd  0          0          0           n/a 

db2pd -agents 34
Database Partition 4294967295 -- Active -- Up 0 days 01:23:54

Agents:
Current agents:      9
Idle agents:         1
Active coord agents: 7
Active agents total: 7
Pooled coord agents: 1
Pooled agents total: 1

Address    AppHandl [nod-index] AgentEDUID Priority   Type     State       ClientPid  Userid   ClientNm Rowsread   Rowswrtn   LkTmOt DBName  
0x1046DE60 235      [000-00235] 34         -10         Coord    Inst-Active 9732       db2inst1 db2bp    2145470    0          NotSet SAMPLE 

Using snapshot for applications


db2 get snapshot for application agentid 235 | grep -i prioriry

Priority at which application agents work  = -10
Priority type                              = Dynamic

Sunday, 18 May 2014

How to check when was executed the last runstats in a specific table

How to check when was executed the last runstats in a specific table

How to check when was executed the last runstats in a specific table

Check the column STATS_TIME in the table syscat.table to get when was executed the last runstats



TABLE NAME:
 TABLE_X
SCHEMA NAME: SCHEMA_X


Checking  when was executed the last runstats for all tables in a specific schema 
 db2 "select substr(tabname,1,30), STATS_TIME from syscat.tables where tabschema='SCHEMA_X'"


Checking  when was executed the last runstats in a specific table 
 db2 "select substr(tabname,1,30), STATS_TIME from syscat.tables where tabname='TABLE_X'"


Checking  when was executed the last runstats for all tables in the whole database
db2 "select substr(tabname,1,30), STATS_TIME from syscat.tables