Showing posts with label genstats. Show all posts
Showing posts with label genstats. Show all posts

Sunday, February 14, 2016

Netezza: view to monitor user run and logon statistics



Create user activity monitoring views. Views are useful to monitor user logons and Netezza  appliance usage:

Create view DDL.

SELECT 'DEV'                                                   as ENV
    ,username                                              AS USERNAME
    ,u.CREATEDATE                                           AS CREATEDATE
    ,timezone(MAX(LAST_LOGON), 'UTC','EST' )                as LAST_LOGON
    , CURRENT_DATE-timezone(MAX(LAST_LOGON), 'UTC','EST' )  as LAST_LOGON_DAYS
    ,SUM(ACCESS_COUNT)                                   as TOTAL_LOGIN_COUNT
--- List concatenation here: put all database on one line comma delimited.
--- Read: http://nz2nz.blogspot.com/2016/02/netezza-concatenate-rows-into-string.html
    ,trim (trailing ', ' from
            SQL_EXTENSIONS.. replace
               (SQL_EXTENSIONS.. replace
                   (SQL_EXTENSIONS..XMLserialize
                       (SQL_EXTENSIONS..XMLagg
                           (SQL_EXTENSIONS..XMLElement( 'X',dbname))),
               '<X>','' )
          , '</X>' ,',' )) AS DB_ACCESSED
FROM
(
     select username
              ,dbname
              , max( time) AS LAST_LOGON
              , count(* )  AS ACCESS_COUNT
     from QUERY_HISTORY.."$v_hist_log_events"
     where username not like 'ADMIN%'   --- not interested in ADMIN** users
       and username not like 'ZZ_%'     --- not interested in ZZ_** functional users
     group by username
          , dbname
) as LAST_LOGON_DAYS
left outer join _v_user u using (username)
GROUP BY 1 ,2 ,3
order by TOTAL_LOGIN_COUNT desc

;







SELECT  'DEV'                                   AS ENV
        , QP.USERNAME                            AS USERNAME
        , DATE_TRUNC('day' , QP.SUBMITTIME)     AS THEDAY
        , MIN(QP.SUBMITTIME)                     AS RUN_FROM
        , MAX(QE.FINISHTIME)                     AS RUN_TO
        , COUNT(*)                              AS QUERY_COUNT
        , SUM((QE.FINISHTIME - QP.SUBMITTIME))   AS TOTAL_ELAPSED
        , SUM(QE.RESULTROWS)                     AS TOTAL_ROWS
        , SUM(P.RESULTBYTES)                     AS TOTAL_BYTES
FROM  (       QUERY_HISTORY.QHIST_USER."$hist_query_prolog_3" QP
         JOIN QUERY_HISTORY.QHIST_USER."$hist_query_epilog_3" QE   
               USING (NPSID, NPSINSTANCEID, OPID) )
   JOIN (     QUERY_HISTORY.QHIST_USER."$hist_session_prolog_3" SP
         JOIN QUERY_HISTORY.QHIST_USER."$hist_session_epilog_3" SE 
               USING (NPSID, NPSINSTANCEID, SESSIONID))
  USING (NPSID, NPSINSTANCEID)
LEFT JOIN (
        SELECT PP.NPSID
       , PP.NPSINSTANCEID
       , PP.OPID
       , PP.SESSIONID
       , SUM(PE.RESULTBYTES) AS RESULTBYTES
       , SUM((PP.PREPTIME - PP.SUBMITTIME)) AS QUEUETIME
       , SUM((PP.GRATIME - PP.PREPTIME)) AS PREPTIME
       , SUM((PP.STARTTIME - PP.GRATIME)) AS GRATIME
       , COUNT(PP.PLANID) AS NUMPLANS
       , SUM(PP.QCRESTART) AS NUMRESTARTS
        FROM (QUERY_HISTORY.QHIST_USER."$hist_plan_prolog_3" PP
        JOIN QUERY_HISTORY.QHIST_USER."$hist_plan_epilog_3" PE 
        USING (NPSID, NPSINSTANCEID, OPID, SESSIONID, PLANID))
        GROUP BY PP.NPSID, PP.NPSINSTANCEID, PP.OPID, PP.SESSIONID
) P
 USING (NPSID, NPSINSTANCEID, OPID)
WHERE QP.SESSIONID = SP.SESSIONID
  AND QE.STATUS = 0
  AND QP.SUBMITTIME > current_timestamp - interval '60 days'
  AND UPPER(QP.QUERYTEXT) NOT IN ( 'COMMIT','BEGIN' , 'SELECT * FROM DUMMY WHERE 1=2')
  AND UPPER(QP.QUERYTEXT) not like 'SHOW %'
  AND UPPER(QP.QUERYTEXT) not like 'SET %'
  AND UPPER(QP.QUERYTEXT) not like 'SELECT VERSION%'
  AND UPPER(QP.QUERYTEXT) not like 'SELECT DB_ENCODING%'
  AND UPPER(QP.QUERYTEXT) not like 'SELECT NCHAR_ENCODING%'
  AND UPPER(QP.QUERYTEXT) not like 'SELECT CURRENT_SID%'
  AND UPPER(QP.QUERYTEXT) not like 'SELECT ''JDBC CLIENT VERSION''%'
  /* to be continued based on your system. This xclusion list is to be revised ...*/
GROUP BY ENV, QP.USERNAME, DATE_TRUNC( 'day', QP.SUBMITTIME)
order by THEDAY desc, TOTAL_ELAPSED desc
;



Aginity: visualize processing skew for running Netezza query

Aginity provides visualization tool to identify query processing skew.

Execute query as: 

Monday, February 8, 2016

Netezza: how TEMP tables GENERATE STATISTICS when created as CTAS

This runtime illustration how Netezza generates full table statistics automatically during CREATE TABLE AS (CTAS) operation. Running nz_responders yields output: 




Read more how Netezza generates statistics on tables in  Maintain table statistics automatically

The IBM® Netezza® system automatically maintains database statistics and estimated dispersion statistics, which are not as accurate as the statistics that the system maintains when you run the GENERATE STATISTICS command. These statistics are, however, generally better than no statistics.
The Netezza system maintains certain statistics when you perform database operations.
  • When you use the CREATE TABLE AS command, the system maintains the min/max, null, and estimated dispersion values automatically.
  • When you use the INSERT or UPDATE commands, the system maintains the min/max values for all non-character fields.
  • When you use the GROOM TABLE command to reclaim deleted records, the system leaves the min/max, null, and estimated dispersion values unchanged, and updates the zone map.
    Because the groom process merely physically removes records that were logically deleted, their removal has no effect on any statistics, though it does affect where in the table the remaining records are, hence the effect on zone maps.
The following table describes when the Netezza automatically maintains table statistics.
Table 1. Automatic Statistics
CommandRow countsMin/MaxNullDispersion (estimated)Zone maps
CREATE TABLE ASyesyesyesyesyes
INSERTyesyesnonoyes
DELETEnonononono
UPDATEyesyesnonoyes
GROOM TABLEnonononoyes
Parent topic: Database statistics