sysmaster of informix

{ ************************************************************************* } 
{                                       } 
{              INFORMIX SOFTWARE, INC.              } 
{                                       } 
{   Title:  sysmaster.sql                           } 
{   Sccsid:     @(#)sysmaster.sql   9.35     12/3/93  18:06:28      } 
{   Description:                                } 
{       create sysmaster database and SMI tables            } 
{                                       } 
{  NOTE: Ensure that any changes in the schema of the "sysmaster" database  } 
{    OR changes in the corresponding shared memory structure  defns     } 
{    are reflected *appropriately* in ALL the files below:          } 
{       rsam/sysmaster.sql.IUS,                     } 
{       rsam/sysmaster.sql.ODS,                     } 
{       rsam/rsmem.h,                           } 
{       rsam/rspseudo.h and                     } 
{       rsam/rspseudo.c                         } 
{                                       } 
{ ************************************************************************* }

 
{ Create Pseudo Tables } 
 
set lock mode to wait; 
 
create database sysmaster with log; 
 
database sysmaster exclusive; 
 
{ databases } 
    create table sysdbspartn 
    ( 
    partnum     integer,    { table id for systables    } 
    created     integer,    { date created          } 
    owner       char(32),   { user name of creator      } 
    name        char(128),  { database name         } 
    flags       smallint    { flags indicating logging  } 
    ); 
    create unique index sysdbs_nameix on sysdbspartn(name); 
    revoke all on sysdbspartn from public; 
    grant select on sysdbspartn to public; 
 
{ join for partnums to table names } 
    create table systabnames 
    ( 
    partnum     integer,    { table id for table        } 
    dbsname     char(128),  { database name         } 
    owner       char(32),   { table owner           } 
    tabname     char(128),  { table name            } 
    collate         char(32)        { collation assoc with database } 
    ); 
    create unique index systabs_pnix on systabnames(partnum); 
    revoke all on systabnames from public; 
    grant select on systabnames to public; 
 
{ Raw Disk } 
    create table sysrawdsk      { Internal Use Only     } 
    ( 
    pagenum     integer,    { physical page address     } 
    offset      smallint,   { bytes into page       } 
    loc     char(14),   { location representation   } 
    hexdata         char(40),   { 16 bytes hexdumped from offset} 
    ascdata     char(16)    { 16 bytes ascii-dumped         } 
    ); 
    create unique index sysrawdskidx on sysrawdsk (pagenum, offset); 
    revoke all on sysrawdsk from public; 
 
{ Page Headers } 
    create table syspaghdr 
    ( 
    pg_partnum  integer,    { partition number of page  } 
    pg_pagenum  integer,    { logical page number in partn  } 
    pg_physaddr     integer,    { pg_addr           } 
    pg_stamp    integer,    { pg_stamp          } 
    pg_stamp2   integer,    { pg_stamp2         } 
    pg_nslots   smallint,   { pg_nslots         } 
    pg_flags    smallint,   { pg_flags          } 
    pg_frptr    smallint,   { pg_frptr          } 
    pg_frcnt    smallint,   { pg_frcnt          } 
    pg_next     integer,    { pg_pgnext         } 
    pg_prev     integer     { pg_pgprev         } 
    ); 
    create unique index syspaghdridx on syspaghdr (pg_partnum, pg_pagenum); 
    revoke all on syspaghdr from public; 
    grant select on syspaghdr to public; 
 
{ Slot Tables } 
    create table sysslttab      { Internal Use Only     } 
    ( 
    partnum     integer,    { partition number of page  } 
    pagenum     integer,    { logical page number in partn  } 
    slotnum     smallint,   { slot number on page       } 
    slotptr     smallint,   { slot pointer          } 
    slotlen     smallint,   { slot length           } 
    slotflg     smallint    { slot flag         } 
    ); 
    create unique index sysslttabidx on sysslttab (partnum, pagenum, slotnum); 
    revoke all on sysslttab from public; 
    grant select on sysslttab to public; 
 
{ Slot Data } 
    create table syssltdat      { Internal Use Only     } 
    ( 
    partnum     integer,    { partition number of page  } 
    pagenum     integer,    { logical page number in partn  } 
    slotnum     smallint,   { slot number on page       } 
    slotoff     smallint,   { slot offset           } 
    loc         char(20),   { location representation   } 
    hexdata     char(40),   { 16 bytes hexdumped from offset} 
    ascdata     char(16)    { 16 bytes ascii dumped         } 
    ); 
    create unique index syssltdatidx on  
    syssltdat (partnum, pagenum, slotnum, slotoff); 
    revoke all on syssltdat from public; 
 
{ Chunk Free List } 
    create table syschfree 
    ( 
    chknum      integer,    { chunk number          } 
    extnum      integer,    { extent number in chunk    } 
    start       integer,    { physical addr of start    } 
    leng        integer     { length of extent      } 
    ); 
    create unique index syschfreeidx on syschfree (chknum, extnum); 
    revoke all on syschfree from public; 
    grant select on syschfree to public; 
 
{ Partition Headers } 
    create table sysptnhdr 
    ( 
    partnum     integer,    { table's partnum                   } 
    flags       integer,    { partition flags           } 
    rowsize     integer,    { rowsize (max for variable)        } 
    ncols       smallint,   { number of varchar or blob columns } 
    nkeys       smallint,   { number of indexes                 } 
    nextns      smallint,   { number of extents         } 
    created     integer,    { date created              } 
    serialv     integer,    { current serial value          } 
    fextsiz     integer,    { first extent size ( in pages )    } 
    nextsiz     integer,    { next extent size ( in pages )     } 
    nptotal     integer,    { number of pages allocated     } 
    npused      integer,    { number of pages used          } 
    npdata      integer,    { number of data pages          } 
    octptnm         integer,    { OCT partnum (optical blobs only)  } 
        lockid          integer,        { table lock id             } 
    nrows           integer     { number of data rows           } 
    ); 
    create unique index sysptnhdridx on sysptnhdr (partnum); 
    revoke all on sysptnhdr from public; 
    grant select on sysptnhdr to public; 
 
{ Partition Key Descriptions } 
    create table sysptnkey      { Internal Use Only     } 
    ( 
    partnum     integer,    { partnum for partition     } 
    keynum      smallint,   { keynumber for key     } 
    flags       smallint,   { key flags         } 
    rootnode    integer,    { logical pagenum for root node } 
    nparts      smallint,   { number of parts in key    } 
    keylen      smallint,   { key length            } 
    kpartno     smallint,   { partno for this part      } 
    kpstart     smallint,   { offset into row of the part   } 
    kpleng      smallint,   { length of this part       } 
    kptype      smallint    { type of this part         } 
    ); 
    create unique index sysptnkeyidx on sysptnkey (partnum, keynum, kpartno); 
    revoke all on sysptnkey from public; 
    grant select on sysptnkey to public; 
 
{ Partition Extent Descriptions } 
    create table sysptnext      { Internal Use Only     } 
    ( 
    pe_partnum  integer,    { partnum for this partition    } 
    pe_extnum   smallint,   { extent number         } 
    pe_phys     integer,    { physical addr for this extent } 
    pe_size     integer,    { size of this extent       } 
    pe_log      integer     { logical page for start    } 
    ); 
    create unique index sysptnextidx on sysptnext (pe_partnum, pe_extnum); 
    revoke all on sysptnext from public; 
    grant select on sysptnext to public; 
 
{ Partition Column Descriptions } 
    create table sysptncol      { Internal Use Only     } 
    ( 
    partnum     integer,    { partnum for this partition    } 
    colnum      smallint,   { column number         } 
    coloff      smallint,   { offset into row       } 
    colblob     smallint,   { blobspace num if blob     } 
    colsize     smallint,   { column size           } 
    colflags    smallint,   { flags for column      } 
    coltype     smallint    { data type of column       } 
    ); 
    create unique index sysptncolidx on sysptncol (partnum, colnum); 
    revoke all on sysptncol from public; 
    grant select on sysptncol to public; 
 
{ Partition Bit Maps } 
    create table sysptnbit 
    ( 
    pb_partnum  integer,    { partnum for this partition    } 
    pb_pagenum  integer,    { logical pagenum represented   } 
    pb_bitmap   integer     { bitmap value for page     } 
    ); 
    create unique index sysptnbitidx on sysptnbit (pb_partnum, pb_pagenum); 
    revoke all on sysptnbit from public; 
    grant select on sysptnbit to public; 
 
 
{ rsam thread control blocks } 
    create table sysrstcb       { Internal Use Only     } 
    ( 
    indx        integer,    { index into rstcb table (rs_number) } 
    address     integer,    { addr of rstcb structure   } 
    txp     integer,    { addr of txp           } 
    localtxp    integer,    { addr of local txp (XA only)   } 
        tmptxp          integer,        { addr of temp file txp         } 
        savetxp         integer, 
    next        integer,    { addr of next on active or free list } 
        tmpdepth        integer,        { depth of temp file ops        } 
        rmid            integer,        { XA Resource Manager ID        } 
        xrecvrpos       smallint, 
    iserrno     integer,    { rsam errno number     } 
    isrecnum    integer,    { current rowid         } 
    isfragnum   integer,    { current fragment number   } 
    flags       integer,    { flags for rstcb       } 
    uid     smallint,   { user id           } 
    asyncerr    integer,    { address of async error    } 
    username    char(32),   { user name         } 
    timeout     smallint,   { lock timeout counter      } 
    nxtthread   integer,    { addr of next if >1 threads    } 
    sid     integer,    { session id            } 
    scb     integer,    { addr of scb           } 
    ostcb       integer,    { addr of ostcb         } 
    gentcb      integer,    { addr of gentcb        } 
    tid     integer,    { thread id         } 
        join            smallint,       { thread will join others       } 
    mttcb       integer,    { addr of mt thread cb      } 
    aio     integer,    { addr of aio request struct    } 
    mirror_aio  integer,    { addr of mirror req struct } 
    lkwait      integer,    { waiting for this lock     } 
        lkwttype        integer,        { lock type waiting for         } 
    bfwait      integer,    { waiting for this buffer   } 
    bfwtflag    smallint,   { buffer wait type flag     } 
    txwait      integer,    { waiting for this transaction  } 
    txsusp      integer,    { suspended transaction     } 
    wtlist      integer,    { addr of next waiter on lock   } 
    wtthrlist   integer,    { addr of next thread in trans  } 
    bflist      integer,    { addr of next waiter on buff   } 
    txlist      integer,    { addr of next waiter on tx } 
    lbufwake    integer,    { addr of log buffer for wake up} 
    nreads      integer,    { number of reads       } 
    nwrites     integer,    { number of writes      } 
    tolist      integer,    { addr of next in timeout list  } 
    nopens      integer,    { size of open table        } 
    nfiles      integer,    { size of file table        } 
    opentab     integer,    { open table            } 
        opfree          integer, 
        nextopen        integer, 
    filetab     integer,    { file table            } 
        hfiles          integer, 
        flfree          integer, 
        nextfile        integer, 
    tmprow      integer,    { temp space for row        } 
    tmpsize     integer,    { size of tmprow space      } 
    cmprow      integer,    { temp space for compressed row } 
    rcmprow     integer,    { temp space for reading cmprow } 
    rowupdatep  integer,    { address of row update info ** } 
    isbisfd     integer,    { isfd for isb* routines    } 
    blobptr     integer,    { ptr to current open blob  } 
    blobrarea   integer,    { blobpage buffer read area } 
    blobrszbuf  integer,    { size of blob buffer read area } 
    blobrbufp   integer,    { addr of blob buffer read  } 
    blobwarea   integer,    { blobpage buffer write area    } 
    blobwszbuf  integer,    { size of blob buffer write area} 
    blobwbufp   integer,    { addr of blob buffer write } 
    blobcarea   integer,    { blobpage buffer copy area } 
    blobcszbuf  integer,    { size of blob buffer copy area } 
    blobcbufp   integer,    { addr of blob buffer copy  } 
    blobpiecesp integer,    { addr of blobpieces struct **  } 
        affp            integer, 
        afid            integer, 
        afcnt           smallint, 
    operrno     integer,    { error in optical subsystem    } 
    dolinkchk   integer,    { do link checks in btchknode   } 
    nnode       integer,    { next node for link check  } 
    pnode       integer,    { prev node for link check  } 
    rsamdebug   integer,    { do rsam debugging checks  } 
    lastlock    integer,    { last lock granted     } 
    bufferlogging   integer,    { do buffered logging       } 
    abcpytab    integer,    { auxiliary bcpy table      } 
    abcpytabmult    integer,    { size multiple for aux bcpy tab} 
    logbuff     integer,    { normal log buffer     } 
        logbuff_beg     integer, 
    undologbuff integer,    { undo log buffer       } 
        tmplogrec       integer, 
    btp     integer,    { addr of current bt struct **  } 
        rkeysfree       integer, 
        turbonum        integer, 
    lastrsfd    integer,    { longest rsfd open     } 
    svptnum     integer,    { savepoint number      } 
    numsorts    integer,    { number of open sorts allowed  } 
    srttab      integer,    { addr of sort table        } 
    srttmpdir   integer,    { ptr to sort temp dir pathname } 
    srtfileid   integer,    { file id for sort file     } 
    privdata    integer,    { generic pointer to private mem} 
        precnum         integer, 
    rootaddr    integer,    { root node of idx being built  } 
    relocking   integer,    { relock on recovery        } 
        pitstop         integer, 
        pitaction       integer, 
        debugerrno      integer, 
        bfheld_count    integer, 
        logbu           integer, 
        arcbu           integer, 
        physrecvr       integer, 
        logrecvr        integer, 
        recvryflag      integer, 
        nlogs           integer, 
        logs            integer, 
        auditp          integer, 
        nexttrace       integer, 
        ntraces         integer, 
        traces          integer, 
        trflags         integer, 
        opsubbuf        integer, 
        opbuf           integer, 
        opbufsize       integer, 
        blobtxtabp      integer, 
        nblobtxs        integer, 
        maxnbtxs        integer, 
        onut_bufflist   integer, 
        onut_cb         integer, 
    upf_rqlock  integer,    { number of locks requested } 
    upf_wtlock  integer,    { ... lock waits        } 
    upf_deadlk  integer,    { ... deadlocks detected    } 
    upf_lktouts integer,    { ... lock timeouts     } 
    upf_lgrecs  integer,    { ... log records written   } 
    upf_isread  integer,    { ... reads         } 
    upf_iswrite integer,    { ... writes            } 
    upf_isrwrite    integer,    { ... rewrites          } 
    upf_isdelete    integer,    { ... deletes           } 
    upf_iscommit    integer,    { ... commits           } 
    upf_isrollback  integer,    { ... rollbacks         } 
    upf_longtxs integer,    { ... long transactions     } 
    upf_bufreads    integer,    { ... buffer reads      } 
    upf_bufwrites   integer,    { ... buffer writes     } 
    upf_logspuse    integer,    { % log space currently used    } 
    upf_logspmax    integer,    { max % of logspace ever used   } 
    upf_seqscans    integer,    { number of sequential scans    } 
        upf_totsorts    integer, 
        upf_dsksorts    integer, 
        upf_srtspmax    integer, 
    nlocks      integer,    { number of locks currently held} 
        lktout          smallint,       { lock timeout counter          } 
        lkthreadlist    integer        { next thread in same tx wtg    } 
    ); 
    create unique index sysrstcbidx  on sysrstcb (indx); 
    create unique index sysrstcbaddr on sysrstcb (address); 
    revoke all on sysrstcb from public; 
    grant select on sysrstcb to public; 
 
{ Transactions } 
    create table systxptab      { Internal Use Only     } 
    ( 
    indx        integer,    { index into transaction table  } 
    address     integer,    { address of transaction struct } 
    latchp      integer,    { address of transaction latch  } 
    next        integer,    { addr of next on active or free list } 
    gtridp      integer,    { address of gtrid      } 
    txid        integer,    { id of transaction     } 
    flags       integer,    { transaction flags     } 
    logbeg      integer,    { loguniq containing BEGIN  } 
    loguniq     integer,    { loguniq of last record    } 
    logpos      integer,    { logpos of last record     } 
    dlklist     integer,    { used for deadlk detection } 
    deadflag    smallint,   { flag for deadlock detection   } 
    mgmquery    integer,    { tx_query          } 
    lkwaitcnt   smallint,   { # of threads waiting on locks } 
    lklist      integer,    { list of locks held        } 
    lklatchp    integer,    { addr of private lock latch ** } 
    owner       integer,    { addr of owner (rstcb_t *) } 
    wtlist      integer,    { users waiting for this tx } 
    ptlist      integer,    { list of partitions dropped    } 
    nlocks      integer,    { number of locks held      } 
    lkwait      smallint,   { lock wait timeout     } 
    splevel     smallint,   { savepoint level       } 
    isolevel    smallint,   { isolation level       } 
    locktablep  integer,    { addr of table locks table **  } 
    svptcnt     integer,    { number of savepoints alloc'ed } 
    svuniqp     integer,    { addr of savepoint loguniqs ** } 
    svposp      integer,    { addr of savepoint logpos's ** } 
    longtx      smallint,   { this is long transaction  } 
    nsusp       smallint,   { number of suspends for tx } 
    stamp       integer,    { activity time stamp       } 
    istar_coord char(128),  { istar coordinator     } 
    sblock      integer,    { ptr to dynamic shm block  } 
    sqlptr      integer,    { ptr to first ismalloc piece   } 
        nremotes        smallint,       { # of rem thread activations   }   
        begstamp        integer         { stamp at time of BEGIN WORK   }   
    ); 
    create unique index systxpidx  on systxptab (indx); 
    create unique index systxpaddr on systxptab (address); 
    revoke all on systxptab from public; 
    grant select on systxptab to public; 
 
 
{ Locks } 
    create table syslcktab      { Internal Use Only     } 
    ( 
    indx        integer,    { index into lock table     } 
    address         integer,    { addr of lock structure    } 
    hash        integer,    { addr of next in hash bucket   } 
    same        integer,    { list of same locks        } 
    wtlist          integer,    { list of waiters (rstcb *) } 
    owner           integer,    { owner of lock (rtx *)     } 
    list            integer,    { list of owner's locks     } 
    type        smallint,   { type of lock          } 
    flags           smallint,   { lock flags            } 
    bsize           smallint,   { size of bytes key     } 
    keynum          smallint,   { keynum of item lock       } 
    rowidr          integer,    { real rowid if key lock    } 
    partnum         integer,    { partnum lock is on            } 
    rowidn          integer,    { key value locked      } 
        dipnum          integer,        { pagenum if deleted item       } 
        grtime          integer         { time lock was granted         } 
    ); 
    create unique index syslckidx  on syslcktab (indx); 
    create unique index syslckaddr on syslcktab (address); 
    revoke all on syslcktab from public; 
    grant select on syslcktab to public; 
 
{ Buffer Headers } 
    create table sysbufhdr      { Internal Use Only     } 
    ( 
    indx        integer,    { index into buffer table   } 
    address     integer,    { address of buffer structure   } 
    latchp      integer,    { ptr to buffer latch       } 
    bhforw      integer,    { forward pointer in hash list  } 
    bhback      integer,    { backward pointer in hash list } 
    blforw      integer,    { forward pointer in lru list   } 
    blback      integer,    { backward pointer in lru list  } 
    bflags      smallint,   { buffer flags          } 
    berror      smallint,   { i/o error         } 
    reusecnt    smallint,   { how often buff is reused  } 
    lrunum      smallint,   { last lru this buff was on } 
    pagenum     integer,    { physical page addr on disk    } 
    pagemem     integer,    { ptr to page in shared memory  } 
    owner       integer,    { owner with lock (rstcb *)     } 
    wtlist      integer,    { list of waiters for buff lock } 
    sharecnt    smallint,   { count of users sharing buff   } 
    xflags      smallint    { type of lock on buffer    } 
    ); 
    create unique index sysbufhdridx  on sysbufhdr (indx); 
    create unique index sysbufhdraddr on sysbufhdr (address); 
    revoke all on sysbufhdr from public; 
    grant select on sysbufhdr to public; 
 
{ Dbspace Table } 
    create table sysdbstab      { Internal Use Only     } 
    ( 
        address         integer,        { address of dbspace structure  } 
        dbsnum          integer,        { dbspace number                } 
        flags           integer,        { dbspace flags                 } 
        fchunk          integer,        { first chunk in dbspace        } 
        nchunks         integer,        { number of chunks in dbspace   } 
        created         integer,        { date created                  } 
        prtpage         integer,        { partition partition starts at } 
        partp           integer,        { ptr to partp in partition tab } 
        bpagesize       integer,        { BLOB page size                } 
        bcolcnt         integer,        { number of blob columns ref    } 
        level0          integer,        { time of last level 0 archive  } 
        stamp0          integer,        { timestamp last level 0 archive} 
        logid0          integer,        { logid for last level 0 archive} 
        logpos0         integer,        { log pos last level 0 archive  } 
        level1          integer,        { time of last level 1 archive  } 
        stamp1          integer,        { timestamp last level 1 archive} 
        logid1          integer,        { logid for last level 1 archive} 
        logpos1         integer,        { log pos last level 1 archive  } 
        level2          integer,        { time of last level 2 archive  } 
        stamp2          integer,        { timestamp last level 2 archive} 
        logid2          integer,        { logid for last level 2 archive} 
        logpos2         integer,        { log pos last level 2 archive  } 
        logid           integer,        { log id (for logical restore)  } 
        logpos          integer,        { log pos (for logical restore) } 
        oldlogid        integer,        { oldest log id (for log resto) } 
        lastlogid       integer,        { last log id (for log resto)   } 
        rest_time       integer,        { time of last physical restore } 
        arc_pit         integer,        { PIT to terminate log replay   } 
        name            char(128),      { dbspace name                  } 
        owner           char(32)        { dbspace owner                 } 
    ); 
    create unique index sysdbstab_dbsnum on sysdbstab (dbsnum); 
    revoke all on sysdbstab from public; 
    grant select on sysdbstab to public; 
 
{ Chunk Table } 
    create table syschktab      { Internal Use Only     } 
    ( 
    address     integer,    { address of chunk structure    } 
    chknum      smallint,   { chunk number          } 
    nxchunk     smallint,   { number of next chunk in dbsp  } 
    offset      integer,    { pages offset into device  } 
    chksize     integer,    { pages in chunk        } 
    nfree       integer,    { free pages in chunk       } 
    mdsize      integer,    { metadata pages in chunk   } 
    udsize      integer,    { user data pages in chunk  } 
    udfree      integer,    { free user data pages in chunk } 
    dbsnum      smallint,   { dbspace number        } 
    overhead    smallint,   { blob freemap overhead     } 
    flags       smallint,   { chunk flags           } 
    namlen      smallint,   { length of device pathname } 
    fname       char(256),  { device pathname       } 
    reads       integer,    { number of read ops        } 
    writes      integer,    { number of write ops       } 
    pagesread   integer,    { number of pages read      } 
    pageswritten    integer,    { number of pages written   } 
    readtime    float,      { time spent reading (usecs)    } 
    writetime   float       { time spent writing (usecs)    } 
    ); 
    create unique index syschktab_chknum on syschktab (chknum); 
    revoke all on syschktab from public; 
    grant select on syschktab to public; 
 
{ Mirror Chunk Table } 
    create table sysmchktab     { Internal Use Only     } 
    ( 
    address     integer,    { address of chunk structure    } 
    chknum      smallint,   { chunk number          } 
    nxchunk     smallint,   { number of next chunk in dbsp  } 
    offset      integer,    { pages offset into device  } 
    chksize     integer,    { pages in chunk        } 
    nfree       integer,    { free pages in chunk       } 
    mdsize      integer,    { metadata pages in chunk   } 
    udsize      integer,    { user data pages in chunk  } 
    udfree      integer,    { free user data pages in chunk } 
    dbsnum      smallint,   { dbspace number        } 
    overhead    smallint,   { blob freemap overhead     } 
    flags       smallint,   { chunk flags           } 
    namlen      smallint,   { length of device pathname } 
    fname       char(256),  { device pathname       } 
    reads       integer,    { number of read ops        } 
    writes      integer,    { number of write ops       } 
    pagesread   integer,    { number of pages read      } 
    pageswritten    integer,    { number of pages written   } 
    readtime    float,      { time spent reading (usecs)    } 
    writetime   float       { time spent writing (usecs)    } 
    ); 
    create unique index sysmchktab_chknum on sysmchktab (chknum); 
    revoke all on sysmchktab from public; 
    grant select on sysmchktab to public; 
 
{ Log file info } 
    create table syslogfil      { Internal Use Only     } 
    ( 
    indx        integer,    { index into log table      } 
    address     integer,    { address of logfile structure  } 
    number      smallint,   { logfile number        } 
    flags       smallint,   { logfile flags         } 
    fillstamp   integer,    { stamp when last filled    } 
    filltime    integer,    { time when last filled     } 
    uniqid      integer,    { logfile uniqid        } 
    physloc     integer,    { physical address of start } 
    size        integer,    { pages in logfile      } 
    used        integer     { pages used in logfile     } 
    ); 
    create unique index syslogfilidx on syslogfil (indx); 
    create unique index syslogfiladdr on syslogfil (address); 
    revoke all on syslogfil from public; 
    grant select on syslogfil to public; 
 
{ Btclean Request info } 
    create table sysbtcreq      { Internal Use Only     } 
    ( 
    indx        integer,    { index into btcreq table   } 
    address     integer,    { address of btclean structure  } 
    hash        integer,    { next in hash list     } 
    next        integer,    { next in busy/free list    } 
    partnum     integer,    { partnum of request        } 
    pagenum     integer,    { pagenum of request        } 
    keynum      smallint,   { keynum of request     } 
    putcnt      smallint    { count of puts for this req    } 
    ); 
    create unique index sysbtcreqidx on sysbtcreq (indx); 
    revoke all on sysbtcreq from public; 
    grant select on sysbtcreq to public; 
 
{ Trace buffer } 
    create table systraces      { Internal Use Only     } 
    ( 
    type        char(8),    { event type            } 
    file        char(14),   { source file trace is from } 
    lineno      integer,    { line # in source file     } 
    stamp       integer,    { stamp when traced     } 
    time        integer,    { time when traced      } 
    userp       integer,    { user who traced (rstcb *) } 
    trans       integer,    { tx who traced (rtx *)     } 
    data1       integer,    { data value 1          } 
    data2       integer,    { data value 2          } 
    data3       integer,    { data value 3          } 
    data4       integer,    { data value 4          } 
    data5       integer     { data value 5          } 
    ); 
    create index systrac_stampidx on systraces (stamp); 
    revoke all on systraces from public; 
    grant select on systraces to public; 
 
{ Open Partition Table } 
    create table sysptntab      { Internal Use Only     } 
    ( 
    address     integer,    { address of partition structure} 
    condp       integer,    { ptr to condition struct   } 
    latchp      integer,    { ptr to latch struct **    } 
    flags       smallint,   { partition flags       } 
    ucount      smallint,   { usage count           } 
    partnum     integer,    { partition number      } 
    tablock     integer,    { table lock id         } 
    physaddr    integer,    { physical addr of partition pg } 
    lastrowszp  integer,    { size of last alloc'ed row } 
    lastrowpnp  integer,    { last page alloc'ed for row    } 
    lastidxpn   integer,    { last page alloc'ed for index  } 
    extnsp      integer,    { extent list address       } 
    badkeys     integer,    { badkey bitmap         } 
    ptlist      integer,    { next in list of dropped tables } 
    altstmp     integer,    { time stamp of last alter  } 
    ocount      smallint,   { open count            } 
    skstamp     integer,    { stamp of last table update    } 
    glscollname char(32),   { GLS collation name        } 
    localep     integer,    { locale pointer        } 
    pf_rqlock   integer,    { lock requests         } 
    pf_wtlock   integer,    { lock waits            } 
    pf_deadlk   integer,    { deadlocks             } 
    pf_lktouts  integer,    { lock timeouts         } 
        pf_dskreads     integer,        { disk reads                    } 
    pf_isread   integer,    { reads             } 
        pf_dskwrites    integer,        { disk writes                   } 
    pf_iswrite  integer,    { writes            } 
    pf_isrwrite integer,    { rewrites          } 
    pf_isdelete integer,    { deletes           } 
    pf_bfcread  integer,    { buffer reads          } 
    pf_bfcwrite integer,    { buffer writes         } 
    pf_seqscans integer     { sequential scans      } 
    ); 
    create unique index sysptntab_pnix on sysptntab (partnum); 
    revoke all on sysptntab from public; 
    grant select on sysptntab to public; 
 
{ Shared Memory } 
    create table sysshmem       { Internal Use Only     } 
    ( 
    address     integer,    { address in shmem to dump  } 
    loc     char(10),   { location representation   } 
    hexdata     char(40),   { 16 bytes hexdumped from addr  } 
    ascdata     char(16)    { 16 bytes ascii-dumped         } 
    ); 
    create unique index sysshmemidx on sysshmem (address); 
    revoke all on sysshmem from public; 
 
{ Shared Memory Header } 
    create table sysshmhdr      { Internal Use Only     } 
    ( 
    number      integer,    { unique identifier for element } 
    name        char(16),   { name of rhead_t element   } 
    value       integer     { value of rhead_t element  } 
    ); 
    create unique index sysshmhdr_numix on sysshmhdr(number); 
    revoke all on sysshmhdr from public; 
    grant select on sysshmhdr to public; 
 
{ Configuartion parameters } 
    create table syscfgtab 
    ( 
    cf_id       integer,    { unique numeric identifier } 
    cf_name     char(128),  { config parameter name     } 
    cf_flags    integer,    { flags             } 
    cf_original char(256),  { value in ONCONFIG at boottime } 
    cf_effective    char(256),  { value effectively in use  } 
    cf_default  char(256)   { value by default      } 
    ); 
    create unique index syscfgtabix1 on syscfgtab(cf_id); 
    revoke all on syscfgtab from public; 
    grant select on syscfgtab to public; 
 
{ Session control blocks } 
    create table sysscblst      { Internal Use Only     } 
    ( 
    sid     integer,    { session id            } 
    address     integer,    { address of session structure  } 
    currheap    integer,    { ptr to memory heap        } 
    poolp       integer,    { ptr to private session pool   } 
    breakflag   integer,    { stop current processing   } 
    urgent      integer,    { message from tbmode       } 
    killflag    integer,    { stop all processing       } 
    neterrno    integer,    { network error number      } 
    flags       integer,    { session flags         } 
    local       smallint,   { user is local if set      } 
    tlatchp     integer,    { latch protecting thread list  } 
    threadlist  integer,    { ptr to first thread in list   } 
    next        integer,    { next session in list      } 
    uid     smallint,   { user id           } 
    username    char(32),   { user name         } 
    gid     smallint,   { primary group id      } 
    nsuppgids   integer,    { number of supplementary gids  } 
    suppgidsp   integer,    { ptr to suppl'ry gids table    } 
    clienttype  integer,    { client type           } 
    pid     integer,    { process id of fe program  } 
    progname    char(16),   { fe program name       } 
    ttyin       char(16),   { tty name for users stdin  } 
    ttyout      char(16),   { tty name for users stdout } 
    ttyerr      char(16),   { tty name for users stderr } 
    cwd     char(32),   { users cwd         } 
    hostname    char(16),   { users host name       } 
    connected   integer,    { time that user connected  } 
    argc        integer,    { count of args sent        } 
    argvp       integer,    { ptr to arg table      } 
    envvarp     integer,    { ptr to env var table      } 
    numenvvars  integer,    { number of env vars        } 
    sizeenvtab  integer,    { size of env var table     } 
    sqscb       integer,    { ptr to sql control block  } 
    netscb      integer,    { ptr to net control block  } 
    class       integer     { VP class          } 
    ); 
    create unique index sysscblst_sidix on sysscblst(sid DESC); 
    revoke all on sysscblst from public; 
    grant select on sysscblst to public; 
 
{ Thread control blocks } 
    create table systcblst      { Internal Use Only     } 
    ( 
    tid     integer,    { thread id         } 
    address     integer,    { address of thread structure   } 
    stackp      integer,    { ptr to threads stack      } 
    tnext       integer,    { next thread in global list    } 
    tprev       integer,    { prev thread in global list    } 
    lock        integer,    { thread struct protection  } 
    next        integer,    { next thread in special list   } 
    prev        integer,    { prev thread in special list   } 
    joinlist    integer,    { head of joined threads list   } 
    joinnext    integer,    { next in joined threads list   } 
    joinee      integer,    { thread this thread joined } 
    joinresult  integer,    { result of join        } 
    initialroutine  integer,    { initial thread procedure  } 
    initialarg  integer,    { initial arg           } 
    name        char(12),   { thread name           } 
    self        integer,    { this thread's address     } 
    state       integer,    { thread state          } 
    flags       integer,    { flags             } 
    wait_time   integer,    { wait time accumulator     } 
    detach      integer,    { thread detach mode        } 
    priority    integer,    { thread priority       } 
    class       integer,    { user defined thread class     } 
    vpid        integer,    { vpid where thread is running  } 
    bind_vp     integer,    { vp on which thread must run   } 
    bind_priv   integer,    { thread has been bound     } 
    private_data    integer,    { ptr to private data       } 
    wtmutexp    integer,    { ptr to mutex waiting on   } 
    wtcondp     integer,    { ptr to condition waiting on   } 
    sleep_time  integer,    { seconds slept + start time    } 
    start_wait  integer,    { sleep start time      } 
    pcount      integer,    { number of valid p elements    } 
    padrp       integer,    { ptr to padr table     } 
    pvalp       integer,    { ptr to pval table     } 
    run_time    integer,    { total time thread has run } 
    wakeup_count    integer,    { number of stacked wakeups } 
    tstatp      integer,    { ptr to thread TSTAT_T struct  } 
    wstatp      integer     { ptr to thread WSTAT_T struct  } 
    ); 
    create unique index systcblst_tidix on systcblst(tid); 
    revoke all on systcblst from public; 
    grant select on systcblst to public; 
 
{ VP info } 
    create table sysvplst       { Internal Use Only     } 
    ( 
    vpid        integer,    { VP id             } 
    address     integer,    { address of VP struct      } 
    pid     integer,    { unix process id       } 
    usecs_user  float,      { number of usecs of user time  } 
    usecs_sys   float,      { number of usecs of system time} 
    scputimep   integer,    { ptr to saved cputime (tms)    } 
    rcputimep   integer,    { ptr to reset cputime (tms)    } 
    class       integer,    { class of VP           } 
    readyqueue  integer,    { ptr to ready queue tab (TCB_Q)} 
    num_ready   integer,    { number of ready threads   } 
    flags       integer,    { VP flags          } 
    next        integer,    { next in idle list     } 
    prev        integer,    { prev in idle list     } 
    semid       integer,    { semid for this VP     } 
    lock        integer     { VP protection         } 
    ); 
    create unique index sysvplst_vpidix on sysvplst(vpid); 
    revoke all on sysvplst from public; 
    grant select on sysvplst to public; 
 
{ Data Replication control block } 
    create table sysdrcb        { Internal Use Only     } 
    ( 
    address     integer,    { address of drcb structure } 
    version     integer,    { drcb version          } 
    lock        integer,    { drcb lock         } 
    type        integer,    { drcb server type      } 
    name        char(128),  { drcb server name;128=IDENTSIZE} 
    intvl       integer,    { dr buffer flush interval  } 
    timeout     integer,    { dr network timeout        } 
    drauto      integer,    { dr auto           } 
    lostfound   char(256),  { dr lost+found pathname    } 
    state       integer,    { dr server state       } 
    failrecvr   integer,    { dr failure recovery flags } 
    pingtime    integer,    { dr last ping time     } 
    sessiontid  integer,    { dr session thread     } 
    pingtid     integer,    { dr ping thread        } 
    applytid    integer,    { dr apply thread       } 
    recvrtid    integer,    { logcial recovery thread   } 
    scb     integer,    { dr scb            } 
    client_type integer,    { dr client type        } 
    no_kill     integer,    { dr no_kill flag       } 
    no_clients  integer,    { dr no_clients flag        } 
    lgr_scb     integer,    { logcical recovery scb     } 
    lgr_rstcb   integer,    { logcical recovery rstcb   } 
    lgr_bufsize integer,    { logical recovery buffer size  } 
    lgr_numbufs integer,    { number logcial recovery buffers} 
    ckptaddr    integer,    { dr last ckpt address      } 
    cpflag      integer,    { dr cpflag         } 
    bufflag     integer,    { dr bufflag            } 
    lg_offs     integer,    { dr lg_offs            } 
    ll      integer,    { dr logical log info       } 
    bufcur      integer,    { dr current buffer     } 
    bqempty     integer,    { dr empty q            } 
    bqfull      integer     { dr full q         } 
    ); 
    revoke all on sysdrcb from public; 
    grant select on sysdrcb to public; 
 
{ CDR queued info table } 
    create table syscdrq              { Internal Use Only } 
    ( 
    srvid           integer,        { CDR server id } 
    repid           integer,        { CDR replicate id } 
    srcid           integer,        { CDR source server id } 
    srvname         char(128),      { target server name } 
    replname    char(128),  { collection or replicate name } 
    srcname     char(128),  { source server name } 
    bytesqued       integer     { number of bytes queued } 
    ); 
 
    create unique index syscdrq_idx on syscdrq(srvid,repid,srcid); 
    revoke all on syscdrq from public; 
    grant select on syscdrq to public; 
 
{ CDR trans. processed info table } 
    create table syscdrtx             { Internal Use Only } 
    ( 
    srvid       integer,    { CDR server id } 
    srvname     char(128),  { target server name } 
    txprocssd   integer,    { number of trans. processed } 
    txcmmtd     integer,    { number of trans. committed } 
    txabrtd     integer,    { number of trans. aborted } 
    rowscmmtd   integer,    { number of rows committed } 
    rowsabrtd   integer,    { number of rows aborted } 
    txbadcnt    integer     { number of trans. bad commit time } 
    ); 
 
    create unique index syscdrtx_idx on syscdrtx(srvid); 
    revoke all on syscdrtx from public; 
    grant select on syscdrtx to public; 
 
{ CDR server } 
    create table syscdrs              { Internal Use Only } 
    ( 
    servid          integer,        { server id } 
    servname        char(128),      { server name } 
    cnnstate        char(1),        { connection state } 
    cnnstatechg     integer,        { time connection status changed } 
    servstate       char(1),        { server state } 
    ishub           char(1),        { hub flag } 
    isleaf          char(1),        { leaf flag } 
    rootserverid    integer,        { root server id } 
    forwardnodeid   integer,        { forward node server id } 
    timeout         integer         { idle connection timeout } 
    ); 
 
    create unique index syscdrs_idx on syscdrs(servid); 
    revoke all on syscdrs from public; 
    grant select on syscdrs to public; 
 
{ CDR in memory send progress table } 
    create table syscdrprog     { Internal Use Only } 
    ( 
    dest_id     integer, 
    group_id    integer, 
    source_id   integer, 
    key_acked_srv   integer, 
    key_acked_lgid  integer, 
    key_acked_lgpos integer, 
    key_acked_seq   integer, 
    tx_stamp_1  integer, 
    tx_stamp_2  integer 
    ); 
    create unique index syscdrprog_idx 
     on syscdrprog(dest_id, group_id, source_id); 
    revoke all on syscdrprog from public; 
 
{ CDR in memory queues } 
    create table syscdrsend_txn     { Internal Use Only } 
    ( 
    ctkeyserverid   integer, 
    ctkeyid     integer, 
    ctkeypos    integer,  
    ctkeysequence   integer, 
    ctstamp1    integer, 
    ctstamp2    integer, 
    ctcommittime    integer, 
    ctuserid    integer, 
    ctfromid    integer  
    ); 
    create unique index syscdrsend_tidx on syscdrsend_txn(ctstamp1,ctstamp2); 
    revoke all on syscdrsend_txn from public; 
 
    create table syscdrack_txn      { Internal Use Only } 
    ( 
    ctkeyserverid   integer, 
    ctkeyid     integer, 
    ctkeypos    integer,  
    ctkeysequence   integer, 
    ctstamp1    integer, 
    ctstamp2    integer, 
    ctcommittime    integer, 
    ctuserid    integer, 
    ctfromid    integer  
    ); 
    create unique index syscdrack_tidx  on syscdrack_txn(ctstamp1,ctstamp2); 
    revoke all on syscdrack_txn from public; 
 
    create table syscdrctrl_txn     { Internal Use Only } 
    ( 
    ctkeyserverid   integer, 
    ctkeyid     integer, 
    ctkeypos    integer,  
    ctkeysequence   integer, 
    ctstamp1    integer, 
    ctstamp2    integer, 
    ctcommittime    integer, 
    ctuserid    integer, 
    ctfromid    integer  
    ); 
    create unique index syscdrctrl_tidx on syscdrctrl_txn(ctstamp1,ctstamp2); 
    revoke all on syscdrctrl_txn from public; 
 
    create table syscdrsync_txn     { Internal Use Only } 
    ( 
    ctkeyserverid   integer, 
    ctkeyid     integer, 
    ctkeypos    integer,  
    ctkeysequence   integer, 
    ctstamp1    integer, 
    ctstamp2    integer, 
    ctcommittime    integer, 
    ctuserid    integer, 
    ctfromid    integer  
    ); 
    create unique index syscdrsync_tidx on syscdrsync_txn(ctstamp1,ctstamp2); 
    revoke all on syscdrsync_txn from public; 
 
    create table syscdrrecv_txn     { Internal Use Only } 
    ( 
    ctkeyserverid   integer, 
    ctkeyid     integer, 
    ctkeypos    integer,  
    ctkeysequence   integer, 
    ctstamp1    integer, 
    ctstamp2    integer, 
    ctcommittime    integer, 
    ctuserid    integer, 
    ctfromid    integer  
    ); 
    create unique index syscdrsrecv_tidx on syscdrrecv_txn(ctstamp1,ctstamp2); 
    revoke all on syscdrrecv_txn from public; 
 
    create table syscdrsend_buf     { Internal Use Only } 
    ( 
    cbflags     integer, 
    cbsize      integer, 
    cbkeyserverid   integer, 
    cbkeyid     integer, 
    cbkeypos    integer,  
    cbkeysequence   integer, 
    cbgroupid   integer, 
    cbcommittime    integer 
    ); 
    create unique index syscdrsend_bidx 
    on syscdrsend_buf(cbkeyserverid, cbkeyid, cbkeypos, cbkeysequence); 
    revoke all on syscdrsend_buf from public; 
 
    create table syscdrack_buf      { Internal Use Only } 
    ( 
    cbflags     integer, 
    cbsize      integer, 
    cbkeyserverid   integer, 
    cbkeyid     integer, 
    cbkeypos    integer,  
    cbkeysequence   integer, 
    cbgroupid   integer, 
    cbcommittime    integer 
    ); 
    create unique index syscdrack_bidx  
    on syscdrack_buf(cbkeyserverid, cbkeyid, cbkeypos, cbkeysequence); 
    revoke all on syscdrack_buf from public; 
 
    create table syscdrctrl_buf     { Internal Use Only } 
    ( 
    cbflags     integer, 
    cbsize      integer, 
    cbkeyserverid   integer, 
    cbkeyid     integer, 
    cbkeypos    integer,  
    cbkeysequence   integer, 
    cbgroupid   integer, 
    cbcommittime    integer 
    ); 
    create unique index syscdrctrl_bidx 
    on syscdrctrl_buf(cbkeyserverid, cbkeyid, cbkeypos, cbkeysequence); 
    revoke all on syscdrctrl_buf from public; 
 
    create table syscdrsync_buf     { Internal Use Only } 
    ( 
    cbflags     integer, 
    cbsize      integer, 
    cbkeyserverid   integer, 
    cbkeyid     integer, 
    cbkeypos    integer,  
    cbkeysequence   integer, 
    cbgroupid   integer, 
    cbcommittime    integer 
    ); 
    create unique index syscdrsync_bidx  
    on syscdrsync_buf(cbkeyserverid, cbkeyid, cbkeypos, cbkeysequence); 
    revoke all on syscdrsync_buf from public; 
 
    create table syscdrrecv_buf     { Internal Use Only } 
    ( 
    cbflags     integer, 
    cbsize      integer, 
    cbkeyserverid   integer, 
    cbkeyid     integer, 
    cbkeypos    integer,  
    cbkeysequence   integer, 
    cbgroupid   integer, 
    cbcommittime    integer 
    ); 
    create unique index syscdrrecv_bidx  
    on syscdrrecv_buf(cbkeyserverid, cbkeyid, cbkeypos, cbkeysequence); 
    revoke all on syscdrrecv_buf from public; 
    grant select on syscdrrecv_buf to public; 
 
{ Physical Log } 
    create table sysplog 
    ( 
    pl_mutex    integer,    { physical log mutex        } 
    pl_b1mutex  integer,    { buf1's mutex          } 
    pl_b1condition  integer,    { buf1's condition for wait/signal } 
    pl_b1used   smallint,   { buf1's log buffer used    } 
    pl_b1copied smallint,   { buf1's log pages actually bcopied } 
    pl_b1buffer integer,    { buf1's log buffer     } 
    pl_b1wtlist integer,    { buf1's waiting for used = copied } 
    pl_b2mutex  integer,    { buf2's mutex          } 
    pl_b2condition  integer,    { buf2's condition for wait/signal } 
    pl_b2used   smallint,   { buf2's log buffer used    } 
    pl_b2copied smallint,   { buf2's log pages actually bcopied } 
    pl_b2buffer integer,    { buf2's log buffer     } 
    pl_b2wtlist integer,    { buf2's waiting for used = copied } 
    pl_curbp    integer,    { current bp            } 
    pl_otherbp  integer,    { other bp          } 
    pl_bufsize  smallint,   { log buffer size in pages  } 
    pl_stamp    integer,    { log flush timestamp       } 
    pl_physaddr integer,    { log file disk address     } 
    pl_physize  integer,    { log file size in pages    } 
    pl_phypos   integer,    { log file position in pages    } 
    pl_phyused  integer,    { log file used in pages    } 
    pl_phyarch  integer     { on-line archive position  } 
    ); 
    revoke all on sysplog from public; 
    grant select on sysplog to public; 
 
{ Thread Wait Stats } 
    create table systwaits      { Internal Use Only     } 
    ( 
    tid     integer,    { thread id of these stats  } 
    starttime   integer,    { start time of current wait    } 
    startrtime  integer,    { start reset time of current   } 
    reason      integer,    { reason for current wait   } 
    wreason     smallint,   { reason for wstats     } 
    wnum        integer,    { number of waits for wreason   } 
    wcumtime    float,      { cumulative time for wreason   } 
    wmaxtime    integer     { maximum time for wreason  } 
    ); 
    create unique index systwaits_tid on systwaits(tid, wreason); 
    revoke all on systwaits from public; 
    grant select on systwaits to public; 
 
{ Mutexes } 
    create table sysmtxlst      { Internal Use Only     } 
    ( 
    mtx_id      integer,    { id of this mutex      } 
    mtx_address integer,    { address of this mutex     } 
    mtx_next    integer,    { pointer to next mutex in list } 
    mtx_prev    integer,    { pointer to prev mutex in list } 
    mtx_lock    integer,    { mutex lock 0=avail, 1=held    } 
    mtx_wtlock  integer,    { protects wait list        } 
    mtx_holder  integer,    { thread holding lock       } 
    mtx_wtlist  integer,    { address of first thread on list} 
    mtx_type    smallint,   { type of mutex         } 
    mtx_flags   smallint,   { flags             } 
    mtx_lkcnt   smallint,   { count of locks by same thread } 
    mtx_name    char(12),   { name of mutex         } 
    mtx_nwaits  integer,    { number of waits on this mutex } 
    mtx_nservs  integer,    { number of services        } 
    mtx_curlen  integer,    { current length        } 
    mtx_totlen  integer,    { total queue length        } 
    mtx_maxlen  integer,    { maximum queue length      } 
    mtx_waittime    float,      { cumulative wait time (usecs)  } 
    mtx_servtime    float,      { cumulative service time (usecs)} 
    mtx_maxwait integer     { maximum wait time (usecs) } 
    ); 
    create unique index sysmtxlstix1 on sysmtxlst(mtx_id); 
    create unique index sysmtxlstix2 on sysmtxlst(mtx_address);      
    revoke all on sysmtxlst from public; 
    grant select on sysmtxlst to public; 
 
{ Conditions } 
    create table sysconlst      { Internal Use Only     } 
    ( 
    con_id      integer,    { id of this condition      } 
    con_address integer,    { address of this condition     } 
    con_next    integer,    { pointer to next condition in list} 
    con_prev    integer,    { pointer to prev condition in list} 
    con_lock    integer,    { condition lock 0=avail, 1=held} 
    con_wtlist  integer,    { address of first thread on wait list} 
    con_type    integer,    { type of condition (const) } 
    con_name    char(12),   { name of condition     } 
    con_nwaits  integer,    { number of waits on this mutex } 
    con_nservs  integer,    { number of services        } 
    con_curlen  integer,    { current length        } 
    con_totlen  integer,    { total queue length        } 
    con_maxlen  integer,    { maximum queue length      } 
    con_waittime    float,      { cumulative wait time (usecs)  } 
    con_servtime    float,      { cumulative service time (usecs)} 
    con_maxwait integer     { maximum wait time (usecs) } 
    ); 
    create unique index sysconlstix1 on sysconlst(con_id); 
    create unique index sysconlstix2 on sysconlst(con_address);      
    revoke all on sysconlst from public; 
    grant select on sysconlst to public; 
 
{ Pools } 
    create table syspoollst     { Internal Use Only     } 
    ( 
    po_id       smallint,   { id of this pool       } 
    po_address  integer,    { address of this pool      } 
    po_next     integer,    { pointer to next pool in list  } 
    po_prev     integer,    { pointer to prev pool in list  } 
    po_lock     integer,    { lock to synchronise       } 
    po_name     char(12),   { name of pool          } 
    po_class    smallint,   { pool class 1=resident, 2=virtual, 3=message} 
    po_flags    smallint,   { notify if forget to free  } 
    po_freeamt  integer,    { total amount in free list } 
    po_usedamt  integer,    { total amount in used list } 
    po_freelist integer,    { address of free block list    } 
    po_list     integer     { address of pools block list   } 
    ); 
    create unique index syspoollstix1 on syspoollst(po_id); 
    create unique index syspoollstix2 on syspoollst(po_address);     
    revoke all on syspoollst from public; 
    grant select on syspoollst to public; 
 
{ Segments } 
    create table sysseglst      { Internal Use Only     } 
    ( 
    seg_address integer,    { address of segment structure  } 
    seg_next    integer,    { pointer to next segment   } 
    seg_prev    integer,    { pointer to prev segment   } 
    seg_class   smallint,   { segment class         } 
    seg_size    integer,    { size of this segment      } 
    seg_osshmid integer,    { id of this OS segment in this seg} 
    seg_osmaxsize   integer,    { size of maximum OS segment in this seg} 
    seg_osshmkey    integer,    { shmkey for first OS segment   } 
    seg_procid  integer,    { process id of creator     } 
    seg_userid  smallint,   { usr id of creator     } 
    seg_shmaddr integer,    { address of segment        } 
    seg_ovhd    integer,    { amount of overhead bytes  } 
    seg_lock    integer,    { lock to synchronise bitmap access} 
    seg_nextid  integer,    { segment id of next seg    } 
    seg_bmapsz  integer,    { size of block bitmap      } 
    seg_blkused integer,    { no. of used blocks in segment } 
    seg_blkfree integer     { no. of free blocks in segment } 
    ); 
    revoke all on sysseglst from public; 
    grant select on sysseglst to public; 
 
{ Dictionary Hash } 
    create table sysdic         { Internal Use Only     } 
    ( 
    dic_hashno  smallint,   { hash-value            } 
    dic_chainno     smallint,   { position in hash chain    } 
    dic_partnum     integer,    { partition number      } 
    dic_fextsize    integer,    { first extent size         } 
    dic_nextsize    integer,    { next extent size      } 
    dic_locklevel   smallint,   { lock level            } 
    dic_flags   integer,    { table flags           } 
    dic_ps      integer,    { table permissions     } 
    dic_heapptr     integer,    { struct heap *DD memory heap   } 
    dic_altcount    smallint,   { alt count             } 
    dic_ncols   smallint,   { number of columns         } 
    dic_rowsize     smallint,   { row size in bytes         } 
    dic_nindexes    smallint,   { number of indexes         } 
    dic_type    char(1),    { table type            } 
    dic_nrows   integer,    { number of rows        } 
    dic_npused  integer,    { # pages in table      } 
    dic_tabid   integer,    { dictionary table id       } 
    dic_majversion  integer,    { table major version number    } 
    dic_minversion  integer,    { table minor version number    } 
    dic_refcount    integer,    { # of references to this entry } 
    dic_servername  char(128),  { like ddt_servername       } 
    dic_dbname  char(128),  { like ddt_dbname       } 
    dic_ownername   char(32),   { like ddt_owner        } 
    dic_tabname     char(128)   { like ddt_name         } 
    ); 
    create unique index sysdicidx on sysdic(dic_hashno, dic_chainno); 
    revoke all on sysdic from public; 
    grant select on sysdic to public; 
 
{ Distribution Hash } 
    create table sysdsc         { Internal Use Only         } 
    ( 
    dis_hashno  integer,    { hash values of name       } 
    dis_chainno     smallint,   { position in chain         } 
    dis_id      integer,    { id - other than name      } 
    dis_refcnt  integer,    { number of users using entry   } 
    dis_delete  integer,    { marked for delete         } 
    dis_heapptr     integer,    { heap for entry        } 
    dis_heapsz  integer,    { soze of heap          } 
    dis_servername  char(128),  { get  ce_name.fn_servername    } 
    dis_dbname  char(128),  { get  ce_name.fn_dbname    } 
    dis_ownername   char(32),   { get  ce_name.fn_ownername     } 
    dis_name    char(257)   { get  ce_name.fn_name      } 
    ); 
    create unique index sysdscidx on sysdsc(dis_hashno, dis_chainno); 
    revoke all on sysdsc from public; 
    grant select on sysdsc to public; 
 
{ Procedure Hash } 
    create table sysprc         { Internal Use Only         } 
    ( 
    prc_hashno  integer,    { hash values of name       } 
    prc_chainno     smallint,   { position in chain         } 
    prc_id      integer,    { id - other than name      } 
    prc_refcnt  integer,    { number of users using entry   } 
    prc_delete  integer,    { marked for delete         } 
    prc_heapptr     integer,    { heap for entry        } 
    prc_heapsz  integer,    { soze of heap          } 
    prc_servername  char(128),  { get  ce_name.fn_servername    } 
    prc_dbname  char(128),  { get  ce_name.fn_dbname    } 
    prc_ownername   char(32),   { get  ce_name.fn_ownername     } 
    prc_name    char(257)   { get  ce_name.fn_name      } 
    ); 
    create unique index sysprcidx on sysprc(prc_hashno, prc_chainno); 
    revoke all on sysprc from public; 
    grant select on sysprc to public; 
 
{ Sqscb } 
    create table syssqscb       { Internal Use Only         } 
    ( 
    scb_sessionid   integer,    { session id            } 
    scb_address integer,    { self address          } 
    scb_feversion   char(4),    { see sqscb.fevers      } 
    scb_lockmode    smallint,   { -1: wait, 0: not wait, else: # sec } 
                    { see sqscb.waitflag and sqscb.waitsec } 
    scb_sqerrno smallint,   { see sqtcb.sqerrno         } 
    scb_iserrno smallint    { see sqtcb.sqiserrno       } 
    ); 
    create unique index syssqscbidx on syssqscb ( scb_sessionid DESC ); 
    revoke all on syssqscb from public; 
    grant select on syssqscb to public; 
 
{ Sdblock } 
    create table syssdblock             { Internal Use Only             } 
    ( 
    sdb_sessionid       integer,    { session id                        } 
    sdb_sdbno       integer,    { position in array             } 
    sdb_iscurrent       char(1),    { current statement?            } 
    sdb_name        char(128),  { front-end's name for statement    } 
    sdb_id          smallint,   { back-end's id for statement       } 
    sdb_flags       integer,    { defined below             } 
    sdb_executions      integer,    { total # of executions         } 
    sdb_cumtime     float,      { total cumulative execution time   } 
    sdb_bufreads        integer,    { total # of buffers read       } 
    sdb_pagereads       integer,    { total # of pages read from disk   } 
    sdb_bufwrites       integer,    { total # of buffers written        } 
    sdb_pagewrites      integer,    { total # of pages written      } 
    sdb_totsorts        integer,    { total # of sorts performed        } 
    sdb_dsksorts        integer,    { total # of sorts requiring disk io    } 
    sdb_sortspmax       integer,    { max disk space required by a sort     } 
    sdb_cb          integer,    { conblock for statement        } 
    sdb_cblist      integer,    { list of all cb's in statement     } 
    sdb_heap        integer,    { memory heap for this statement    } 
    sdb_partnum         integer,    { part num for temp blob table      } 
    sdb_isfd        smallint,   { file descriptor for the table     } 
    sdb_recnum      integer,    { row for blob descriptors      } 
    sdb_sqerrno         smallint,   { for fetching, if rows need to be  } 
    sdb_sqiserrno       smallint,   { returned to the user first, but   } 
    sdb_sqoffset        smallint,   { need to set the error in the next     } 
    sdb_errstr      char(64),   { fetch statement           } 
    sdb_ntables         integer,    { number of table descriptors       } 
    sdb_sqttab      integer,    { thread specific tab info      } 
    sdb_asynch_sqerrno  integer,    { error reported by asynch thread   } 
    sdb_asynch_sqiserr  integer,    { error reported by asynch thread   } 
    sdb_pool        integer,    { statement memory pool         } 
    sdb_mutex       integer,    { misc lock (to check sd_sqerrno)   } 
    sdb_tgcblist        integer,    { list of cbs to be use to build    } 
    sdb_pdq_prio_req    smallint,   { requested priority            } 
    sdb_pdq_priority    smallint,   { currently allowed pdq_priority    } 
    sdb_max_scans       integer     { currently allowd # scans      } 
    ); 
    create unique index syssdblockidx on syssdblock (sdb_sessionid DESC, sdb_sdbno); 
    revoke all on syssdblock from public; 
    grant select on syssdblock to public; 
 
{ Conblock } 
    create table sysconblock        { Internal Use Only         } 
    ( 
    cbl_sessionid   integer,    { session id                    } 
    cbl_sdbno   integer,    { position in sdblock array     } 
    cbl_conbno  smallint,   { position in conblock list     } 
    cbl_ismainblock char(1),    { main block for statement?     } 
    cbl_selflag smallint,   { see cb_selflag (SQ_*)     } 
    cbl_estcost integer,    { see cb_estcost        } 
    cbl_estrows integer,    { see cb_estsize        } 
    cbl_flags   integer,    { see cb_flags          } 
    cbl_flags2  integer,    { see cb_flags2         } 
    cbl_seqscan smallint,   { # of SEQUENTIAL SCANs     } 
    cbl_srtscan smallint,   { # of SORT SCANs       } 
    cbl_autoindex   smallint,   { # of AUTOINDEX PATHs      } 
    cbl_index   smallint,   { # of INDEX PATHs      } 
    cbl_remsql  smallint,   { # of REMOTE PATHs         } 
    cbl_mrgjoin smallint,   { # of MERGE JOINs      } 
    cbl_dynhashjoin smallint,   { # of DYNAMIC HASH JOINs   } 
    cbl_keyonly smallint,   { # of (Key-Only)s      } 
    cbl_tempfile    smallint,   { # of Temporary Files      } 
    cbl_tempview    smallint,   { # of Temp Tables For View     } 
    cbl_secthreads  smallint,   { # of Secondary Threads    } 
    cbl_stmt    char(32000) { current statement         } 
    ); 
    create unique index sysconblockidx on sysconblock ( cbl_sessionid DESC, cbL_sdbno, cbl_conbno); 
    revoke all on sysconblock from public; 
    grant select on sysconblock to public; 
 
{ Opendb } 
    create table sysopendb          { Internal Use Only         } 
    ( 
    odb_sessionid   integer,    { session id                    } 
    odb_odbno   integer,    { position in opendb array  } 
    odb_dbname      char(128),  { database name         } 
    odb_iscurrent   char(1),    { no==sdb_current ? 'Y' : 'N'   } 
    odb_islog   char(1),    { !logflg ? 'Y' : 'N'       } 
    odb_isansi  char(1),    { ansiflg ? 'Y' : 'N'       } 
    odb_isolation   smallint,   { isolation level see xtype     } 
    odb_usrtype     char(1),    { user type (DBA, CONNECT ..    } 
    odb_prior   smallint,   { priority          } 
    odb_tmstamp     integer,    { timestamp for last access     } 
    odb_lc_collate  char(36),   { value for LC_COLLATE      } 
    odb_dbflags     smallint    { 1 if DB_EXCLUSIVE         } 
    ); 
    create unique index sysopendbidx on sysopendb (odb_sessionid DESC, odb_odbno); 
    revoke all on sysopendb from public; 
    grant select on sysopendb to public; 
 
{ SQL state and statement } 
    create table syssqlstat     { Internal Use Only             } 
    ( 
    sqs_sessionid   integer,    { session id            } 
    sqs_dbname  char(128),  { database name         } 
    sqs_iso     smallint,   { Isolation level       } 
    sqs_lockmode    smallint,   { lock mode         } 
    sqs_sqlerror    smallint,   { sql error of last SQL stmt    } 
    sqs_isamerror   smallint,   { isam error of last SQL stmt   } 
    sqs_feversion   char(4),    { FE Version            } 
    sqs_statement   char(200)   { last SQL statement        } 
    ); 
    revoke all on syssqlstat from public; 
    grant select on syssqlstat to public; 
 
 
{ LRU buffers } 
    create table syslrus 
      ( 
        lru_num     int,                { Number of Lru Queue           } 
        lru_nfree   int,                { Free Buffers in Lru Queue     } 
        lru_nmod    int                 { Modified Buffers in Lru Queue } 
      ); 
    create unique index syslrusix1 on syslrus(lru_num); 
    revoke all on syslrus from public; 
    grant select on syslrus to public; 
 
  
{ Shared memory values }    
    create table sysshmvals 
      ( 
         sh_mode           int,         { turbo mode number             } 
         sh_boottime       int,         { boot time of day              } 
         sh_pfclrtime      int,         { time profilers were last clr  } 
         sh_curtime        int,         { current mt_time               } 
         sh_bootstamp      int,         { boot time stamp               }  
         sh_stamp          int,         { current time stamp            } 
         sh_mainlooptcb    int,         { address of main daemon thread } 
         sh_sysflags       int,         { system operating flags        } 
         sh_maxchunks      int,         { size of chunk table           } 
         sh_maxdbspaces    int,         { size of dbspace table         } 
         sh_maxuserthreads int,         { max # of user structures      } 
         sh_maxtrans       int,         { max # of trans structures     } 
         sh_maxlocks       int,         { # of locks total              } 
         sh_maxlogs        int,         { size of log table             } 
         sh_nbuffs         int,         { # of buffers total            } 
         sh_pagesize       int,         { buffer size in bytes          } 
         sh_nlrus          int,         { # of lru queues               } 
         sh_maxdirty       int,         { LRU can have this % dirty pages } 
         sh_mindirty       int,         { LRU has % dirty pages after clean } 
         sh_ncleaners      int,         { # of cleaning/flushing procs  }  
         sh_longtx         int,         { the long transaction flag     } 
         sh_optstgbsnum    int,         { Subsystem Staging Blobspace   } 
         sh_cpflag         int,         { TRUE => doing checkpoint      } 
         sh_rapages        int,         { Number of pages to read ahead } 
         sh_rathreshold    int,         { When to start next read ahead } 
         sh_lastlogfreed   int,         { last log (id) written to tape } 
         sh_rmdlktout      int,         { max timeout when distributed  } 
         sh_narchivers     int,         { number of active archives     } 
         sh_maxpdqpriority int );       { max pdqpriority               } 
    revoke all on sysshmvals from public; 
    grant select on sysshmvals to public; 
 
 
{ C2 Audit info } 
  create table sysadtinfo       { Internal Use Only     } 
    ( 
    adtmode     integer,    { Current audit level       } 
    adterr      integer,    { Action on errors      } 
    adtsize     integer,    { Max size of audit trail } 
    adtpath     char(256),  { Dir to send audit records to  } 
    adtfile     integer     { File within dir to write to   } 
    ); 
    revoke all on sysadtinfo from public; 
 
{ C2 Audit call } 
    create table syscrtadt      { Internal Use Only     } 
    ( 
    event       integer,    { Event to audit        } 
    result      integer,    { Success or Failure        } 
    data        char(256)   { Additional data to audit  } 
    ); 
    revoke all on syscrtadt from public; 
 
{ get info out of catalogs and save it } 
 
select tabid from systables 
where tabname in ( 
'sysdbspartn', 'systabnames',   'sysrawdsk',    'syspaghdr', 
'sysslttab',    'syssltdat',    'syschfree',    'sysptnhdr', 
'sysptnkey',    'sysptnext',    'sysptncol',    'sysptnbit', 
'sysrstcb',     'systxptab',    'syslcktab',    'sysbufhdr', 
'sysdbstab',    'syschktab',    'sysmchktab',   'syslogfil', 
'sysbtcreq',    'systraces',    'sysptntab',    'sysshmem', 
'sysshmhdr',    'sysscblst',    'systcblst',    'sysvplst', 
'systwaits',    'sysdrcb',  'sysadtinfo',   'syscrtadt', 
'sysmtxlst',    'sysconlst',    'syspoollst',   'sysseglst', 
'sysdic',   'sysprc',   'sysdsc',   'syssqscb', 
'syssdblock',   'sysconblock',  'sysopendb',    'syssqlstat', 
'syslrus',  'sysshmvals',   'sysplog',  'syscfgtab', 
'syscdrs',  'syscdrq',  'syscdrtx',     'syscdrprog', 
'syscdrsend_txn', 'syscdrack_txn','syscdrctrl_txn', 'syscdrsync_txn', 
'syscdrrecv_txn', 'syscdrsend_buf','syscdrack_buf', 'syscdrctrl_buf', 
'syscdrsync_buf', 'syscdrrecv_buf') 
into temp temptabid with no log; 
 
select * from systables  where tabid in (select tabid from temptabid) 
into temp tempsystab with no log; 
 
select * from syscolumns where tabid in (select tabid from temptabid) 
into temp tempsyscol with no log; 
 
select * from sysindices where tabid in (select tabid from temptabid) 
into temp tempsysidx with no log; 
 
select * from systabauth where tabid in (select tabid from temptabid) 
into temp tempsysauth with no log; 
 
select * from sysobjstate where tabid in (select tabid from temptabid) 
into temp tempsysobj with no log; 
 
 
{ reset partnums so internally we recognize these as pseudo tables, also 
  update nrows to clue in the optimizer } 
 
update tempsystab set (partnum,nrows) = (257,10) where tabname = 'sysdbspartn'; 
 
update tempsystab set (partnum,nrows) = (1,100000)  where tabname = 'sysrawdsk'; 
update tempsystab set (partnum,nrows) = (2,100000)  where tabname = 'syspaghdr'; 
update tempsystab set (partnum,nrows) = (3,1000000) where tabname = 'sysslttab'; 
update tempsystab set (partnum,nrows) = (4,1000000) where tabname = 'syssltdat'; 
update tempsystab set (partnum,nrows) = (5,100)     where tabname = 'syschfree'; 
update tempsystab set (partnum,nrows) = (6,100)     where tabname = 'syscfgtab'; 
 
update tempsystab set (partnum,nrows) = (10,1000)  where tabname = 'sysptnhdr'; 
update tempsystab set (partnum,nrows) = (11,1000)  where tabname = 'sysptnkey'; 
update tempsystab set (partnum,nrows) = (12,1000)  where tabname = 'sysptnext'; 
update tempsystab set (partnum,nrows) = (13,1000)  where tabname = 'sysptncol'; 
update tempsystab set (partnum,nrows) = (14,10000) where tabname = 'sysptnbit'; 
update tempsystab set (partnum,nrows) = (15,1000)  where tabname = 'systabnames'; 
 
update tempsystab set (partnum,nrows) = (20,100)   where tabname = 'sysptntab'; 
update tempsystab set (partnum,nrows) = (21,10000) where tabname = 'syslcktab'; 
update tempsystab set (partnum,nrows) = (22,1000)  where tabname = 'sysbufhdr'; 
update tempsystab set (partnum,nrows) = (23,10)    where tabname = 'sysdbstab'; 
update tempsystab set (partnum,nrows) = (24,10)    where tabname = 'syschktab'; 
update tempsystab set (partnum,nrows) = (25,10)    where tabname = 'sysmchktab'; 
update tempsystab set (partnum,nrows) = (26,100)   where tabname = 'sysrstcb'; 
update tempsystab set (partnum,nrows) = (27,100)   where tabname = 'systxptab'; 
update tempsystab set (partnum,nrows) = (28,10)    where tabname = 'syslogfil'; 
update tempsystab set (partnum,nrows) = (29,100)   where tabname = 'sysbtcreq'; 
 
update tempsystab set (partnum,nrows) = (30,100)   where tabname = 'sysshmem'; 
update tempsystab set (partnum,nrows) = (31,100)   where tabname = 'sysshmhdr'; 
update tempsystab set (partnum,nrows) = (32,1000)  where tabname = 'systraces'; 
update tempsystab set (partnum,nrows) = (33,1)     where tabname = 'sysdrcb'; 
update tempsystab set (partnum,nrows) = (34,100)   where tabname = 'syslrus'; 
update tempsystab set (partnum,nrows) = (35,1)     where tabname = 'sysplog'; 
update tempsystab set (partnum,nrows) = (38,1)     where tabname = 'sysshmvals'; 
 
update tempsystab set (partnum,nrows) = (40,100)   where tabname = 'sysscblst'; 
update tempsystab set (partnum,nrows) = (41,100)   where tabname = 'systcblst'; 
update tempsystab set (partnum,nrows) = (42,100)   where tabname = 'sysvplst'; 
update tempsystab set (partnum,nrows) = (43,100)   where tabname = 'systwaits'; 
 
update tempsystab set (partnum,nrows) = (44,100000) where tabname = 'sysmtxlst'; 
update tempsystab set (partnum,nrows) = (45,1000)  where tabname = 'sysconlst'; 
update tempsystab set (partnum,nrows) = (46,10000) where tabname = 'syspoollst'; 
update tempsystab set (partnum,nrows) = (47,10)    where tabname = 'sysseglst'; 
 
update tempsystab set (partnum,nrows) = (60,100)   where tabname = 'sysdic'; 
update tempsystab set (partnum,nrows) = (61,10)    where tabname = 'sysprc'; 
update tempsystab set (partnum,nrows) = (62,10)    where tabname = 'sysdsc'; 
update tempsystab set (partnum,nrows) = (63,100)   where tabname = 'syssqscb'; 
update tempsystab set (partnum,nrows) = (64,1000)  where tabname = 'syssdblock'; 
update tempsystab set (partnum,nrows) = (65,1000)  where tabname = 'sysconblock'; 
update tempsystab set (partnum,nrows) = (66,100)   where tabname = 'sysopendb'; 
update tempsystab set (partnum,nrows) = (69,100)   where tabname = 'syssqlstat'; 
 
update tempsystab set (partnum,nrows) = (70,100)   where tabname = 'syscdrs'; 
update tempsystab set (partnum,nrows) = (71,100)   where tabname = 'syscdrq'; 
update tempsystab set (partnum,nrows) = (72,100)   where tabname = 'syscdrtx'; 
update tempsystab set (partnum,nrows) = (73,100)   where tabname = 'syscdrprog'; 
 
update tempsystab set (partnum,nrows) = (74,100)   where tabname = 'syscdrsend_txn'; 
update tempsystab set (partnum,nrows) = (75,100)   where tabname = 'syscdrack_txn'; 
update tempsystab set (partnum,nrows) = (76,100)   where tabname = 'syscdrctrl_txn'; 
update tempsystab set (partnum,nrows) = (77,100)   where tabname = 'syscdrsync_txn'; 
update tempsystab set (partnum,nrows) = (78,100)   where tabname = 'syscdrrecv_txn'; 
update tempsystab set (partnum,nrows) = (79,100)   where tabname = 'syscdrsend_buf'; 
update tempsystab set (partnum,nrows) = (80,100)   where tabname = 'syscdrack_buf'; 
update tempsystab set (partnum,nrows) = (81,100)   where tabname = 'syscdrctrl_buf'; 
update tempsystab set (partnum,nrows) = (82,100)   where tabname = 'syscdrsync_buf'; 
update tempsystab set (partnum,nrows) = (83,100)   where tabname = 'syscdrrecv_buf'; 
 
update tempsystab set (partnum,nrows) = (1025, 1)  where tabname = 'sysadtinfo'; 
update tempsystab set (partnum,nrows) = (1026, 1)  where tabname = 'syscrtadt'; 
 
drop table sysdbspartn; 
drop table sysrawdsk; 
drop table syspaghdr; 
drop table sysslttab; 
drop table syssltdat; 
drop table syschfree; 
drop table sysptnhdr; 
drop table sysptnkey; 
drop table sysptnext; 
drop table sysptncol; 
drop table sysptnbit; 
drop table systabnames; 
drop table sysptntab; 
drop table syslcktab; 
drop table sysbufhdr; 
drop table sysdbstab; 
drop table syschktab; 
drop table sysmchktab; 
drop table sysrstcb; 
drop table systxptab; 
drop table syslogfil; 
drop table sysbtcreq; 
drop table sysshmem; 
drop table sysshmhdr; 
drop table syscfgtab; 
drop table systraces; 
drop table sysscblst; 
drop table systcblst; 
drop table sysvplst; 
drop table systwaits; 
drop table sysdrcb; 
drop table sysplog; 
drop table sysadtinfo; 
drop table syscrtadt; 
drop table sysmtxlst; 
drop table sysconlst; 
drop table syspoollst; 
drop table sysseglst; 
drop table sysdic; 
drop table sysprc; 
drop table sysdsc; 
drop table syssqscb; 
drop table syssdblock; 
drop table sysconblock; 
drop table sysopendb; 
drop table syssqlstat; 
drop table syslrus; 
drop table sysshmvals; 
drop table syscdrs; 
drop table syscdrq; 
drop table syscdrtx; 
drop table syscdrprog; 
drop table syscdrsend_txn; 
drop table syscdrack_txn; 
drop table syscdrctrl_txn; 
drop table syscdrsync_txn; 
drop table syscdrrecv_txn; 
drop table syscdrsend_buf; 
drop table syscdrack_buf; 
drop table syscdrctrl_buf; 
drop table syscdrsync_buf; 
drop table syscdrrecv_buf; 
 
{ reinsert modified catalog info into catalogs } 
 
insert into systables  select * from tempsystab; 
insert into syscolumns select * from tempsyscol; 
insert into sysindices select * from tempsysidx; 
insert into systabauth select * from tempsysauth; 
insert into sysobjstate select * from tempsysobj; 
 
drop table tempsystab; 
drop table tempsyscol; 
drop table tempsysidx; 
drop table tempsysauth; 
drop table tempsysobj; 
 
{ create a table to associate strings wither various tables' flags/types 
  columns } 
 
    create table flags_text (tabname char(128), flags int, txt char(50)); 
    create unique index flags_text_ix1 on flags_text(tabname, flags); 
 
{ Session waits reasons } 
    insert into flags_text values ('systwaits', 0, 'unspecified'); 
    insert into flags_text values ('systwaits', 1, 'buffer'); 
    insert into flags_text values ('systwaits', 2, 'lock'); 
    insert into flags_text values ('systwaits', 3, 'aio'); 
    insert into flags_text values ('systwaits', 4, 'mt yield 0'); 
    insert into flags_text values ('systwaits', 5, 'mt yield n'); 
    insert into flags_text values ('systwaits', 6, 'mt yield'); 
    insert into flags_text values ('systwaits', 7, 'checkpoint'); 
    insert into flags_text values ('systwaits', 8, 'log i/o'); 
    insert into flags_text values ('systwaits', 9, 'log copy'); 
    insert into flags_text values ('systwaits', 10, 'condition'); 
    insert into flags_text values ('systwaits', 11, 'lock mutex'); 
    insert into flags_text values ('systwaits', 12, 'lockfree mutex'); 
    insert into flags_text values ('systwaits', 13, 'deadlock mutex'); 
    insert into flags_text values ('systwaits', 14, 'lrus mutex'); 
    insert into flags_text values ('systwaits', 15, 'tblsp mutex'); 
    insert into flags_text values ('systwaits', 16, 'log mutex'); 
    insert into flags_text values ('systwaits', 17, 'ckpt mutex'); 
    insert into flags_text values ('systwaits', 18, 'mutex'); 
    insert into flags_text values ('systwaits', 19, 'mt ready'); 
    insert into flags_text values ('systwaits', 20, 'mt yield x'); 
    insert into flags_text values ('systwaits', 21, 'running'); 
 
{ VP Classes } 
    insert into flags_text values ('sysvplst', 0, 'cpu'); 
    insert into flags_text values ('sysvplst', 1, 'aio'); 
    insert into flags_text values ('sysvplst', 2, 'tli'); 
    insert into flags_text values ('sysvplst', 3, 'shm'); 
    insert into flags_text values ('sysvplst', 4, 'lio'); 
    insert into flags_text values ('sysvplst', 5, 'pio'); 
    insert into flags_text values ('sysvplst', 6, 'adm'); 
    insert into flags_text values ('sysvplst', 7, 'opt'); 
    insert into flags_text values ('sysvplst', 8, 'soc'); 
    insert into flags_text values ('sysvplst', 9, 'msc'); 
    insert into flags_text values ('sysvplst', 10, 'adt'); 
    insert into flags_text values ('sysvplst', 11, 'kio'); 
    insert into flags_text values ('sysvplst', 12, 'str'); 
    insert into flags_text values ('sysvplst', 13, 'csm'); 
    insert into flags_text values ('sysvplst', 14, 'ntk'); 
 
{ Lock types } 
    insert into flags_text values ('syslcktab', 0, 'NONE'); 
    insert into flags_text values ('syslcktab', 1, 'BYTE'); 
    insert into flags_text values ('syslcktab', 2, 'IS'); 
    insert into flags_text values ('syslcktab', 3, 'S'); 
    insert into flags_text values ('syslcktab', 4, 'SR'); 
    insert into flags_text values ('syslcktab', 5, 'U'); 
    insert into flags_text values ('syslcktab', 6, 'UR'); 
    insert into flags_text values ('syslcktab', 7, 'IX'); 
    insert into flags_text values ('syslcktab', 8, 'SIX'); 
    insert into flags_text values ('syslcktab', 9, 'X'); 
    insert into flags_text values ('syslcktab', 10,'XR'); 
 
{ Data Replication } 
 
    insert into flags_text values ('sysdrcb', 0, 'Not Initialized'); 
    insert into flags_text values ('sysdrcb', 1, 'Standard'); 
    insert into flags_text values ('sysdrcb', 2, 'Primary'); 
    insert into flags_text values ('sysdrcb', 3, 'Secondary'); 
    insert into flags_text values ('sysdrcb', 16, 'Off'); 
    insert into flags_text values ('sysdrcb', 32, 'On'); 
    insert into flags_text values ('sysdrcb', 64, 'Connecting'); 
    insert into flags_text values ('sysdrcb', 128, 'Failed'); 
    insert into flags_text values ('sysdrcb', 288, 'Read-Only'); 
 
{ Isolation Level } 
 
    insert into flags_text values ('sysopendb', 0, 'NOTRANS'); 
    insert into flags_text values ('sysopendb', 1, 'DIRTY READ'); 
    insert into flags_text values ('sysopendb', 2, 'COMMITTED READ'); 
    insert into flags_text values ('sysopendb', 3, 'CURSOR STABILITY'); 
    insert into flags_text values ('sysopendb', 5, 'REPEATABLE READ'); 
    insert into flags_text values ('sysopendb', 7, 'DIRTY READ RETAIN UPDATE LOCKS'); 
    insert into flags_text values ('sysopendb', 8, 'COMMITTED READ RETAIN UPDATE LOCKS'); 
    insert into flags_text values ('sysopendb', 9, 'CURSOR STABILITY RETAIN UPDATE LOCKS'); 
 
{ SQL statement types: see incl/sqlstype } 
 
    insert into flags_text values ('sqltype',  1, 'SQ_DATABASE'); 
    insert into flags_text values ('sqltype',  2, 'SQ_SELECT'); 
    insert into flags_text values ('sqltype',  3, 'SQ_SELINTO'); 
    insert into flags_text values ('sqltype',  4, 'SQ_UPDATE'); 
    insert into flags_text values ('sqltype',  5, 'SQ_DELETE'); 
    insert into flags_text values ('sqltype',  6, 'SQ_INSERT'); 
    insert into flags_text values ('sqltype',  7, 'SQ_UPDCURR'); 
    insert into flags_text values ('sqltype',  8, 'SQ_DELCURR'); 
    insert into flags_text values ('sqltype',  9, 'SQ_LDINSERT'); 
    insert into flags_text values ('sqltype', 10, 'SQ_LOCK'); 
    insert into flags_text values ('sqltype', 11, 'SQ_UNLOCK'); 
    insert into flags_text values ('sqltype', 12, 'SQ_CREADB'); 
    insert into flags_text values ('sqltype', 13, 'SQ_DROPDB'); 
    insert into flags_text values ('sqltype', 14, 'SQ_CRETAB'); 
    insert into flags_text values ('sqltype', 15, 'SQ_DRPTAB'); 
    insert into flags_text values ('sqltype', 16, 'SQ_CREIDX'); 
    insert into flags_text values ('sqltype', 17, 'SQ_DRPIDX'); 
    insert into flags_text values ('sqltype', 18, 'SQ_GRANT'); 
    insert into flags_text values ('sqltype', 19, 'SQ_REVOKE'); 
    insert into flags_text values ('sqltype', 20, 'SQ_RENTAB'); 
    insert into flags_text values ('sqltype', 21, 'SQ_RENCOL'); 
    insert into flags_text values ('sqltype', 22, 'SQ_CREAUD'); 
    insert into flags_text values ('sqltype', 23, 'SQ_STRAUD'); 
    insert into flags_text values ('sqltype', 24, 'SQ_STPAUD'); 
    insert into flags_text values ('sqltype', 25, 'SQ_DRPAUD'); 
    insert into flags_text values ('sqltype', 26, 'SQ_RECTAB'); 
    insert into flags_text values ('sqltype', 27, 'SQ_CHKTAB'); 
    insert into flags_text values ('sqltype', 28, 'SQ_REPTAB'); 
    insert into flags_text values ('sqltype', 29, 'SQ_ALTER'); 
    insert into flags_text values ('sqltype', 30, 'SQ_STATS'); 
    insert into flags_text values ('sqltype', 31, 'SQ_CLSDB'); 
    insert into flags_text values ('sqltype', 32, 'SQ_DELALL'); 
    insert into flags_text values ('sqltype', 33, 'SQ_UPDALL'); 
    insert into flags_text values ('sqltype', 34, 'SQ_BEGWORK'); 
    insert into flags_text values ('sqltype', 35, 'SQ_COMMIT'); 
    insert into flags_text values ('sqltype', 36, 'SQ_ROLLBACK'); 
    insert into flags_text values ('sqltype', 37, 'SQ_SAVEPOINT'); 
    insert into flags_text values ('sqltype', 38, 'SQ_STARTDB'); 
    insert into flags_text values ('sqltype', 39, 'SQ_RFORWARD'); 
    insert into flags_text values ('sqltype', 40, 'SQ_CREVIEW'); 
    insert into flags_text values ('sqltype', 41, 'SQ_DROPVIEW'); 
    insert into flags_text values ('sqltype', 42, 'SQ_DEBUG'); 
    insert into flags_text values ('sqltype', 43, 'SQ_CREASYN'); 
    insert into flags_text values ('sqltype', 44, 'SQ_DROPSYN'); 
    insert into flags_text values ('sqltype', 45, 'SQ_CTEMP'); 
    insert into flags_text values ('sqltype', 46, 'SQ_WAITFOR'); 
    insert into flags_text values ('sqltype', 47, 'SQ_ALTIDX'); 
    insert into flags_text values ('sqltype', 48, 'SQ_ISOLATE'); 
    insert into flags_text values ('sqltype', 49, 'SQ_SETLOG'); 
    insert into flags_text values ('sqltype', 50, 'SQ_EXPLAIN'); 
    insert into flags_text values ('sqltype', 51, 'SQ_SCHEMA'); 
    insert into flags_text values ('sqltype', 52, 'SQ_OPTIM'); 
    insert into flags_text values ('sqltype', 53, 'SQ_CREPROC'); 
    insert into flags_text values ('sqltype', 54, 'SQ_DRPPROC'); 
    insert into flags_text values ('sqltype', 55, 'SQ_CONSTRMODE'); 
    insert into flags_text values ('sqltype', 56, 'SQ_EXECPROC'); 
    insert into flags_text values ('sqltype', 57, 'SQ_DBGFILE'); 
    insert into flags_text values ('sqltype', 58, 'SQ_CREOPCL'); 
    insert into flags_text values ('sqltype', 59, 'SQ_ALTOPCL'); 
    insert into flags_text values ('sqltype', 60, 'SQ_DRPOPCL'); 
    insert into flags_text values ('sqltype', 61, 'SQ_OPRESERVE'); 
    insert into flags_text values ('sqltype', 62, 'SQ_OPRELEASE'); 
    insert into flags_text values ('sqltype', 63, 'SQ_OPTIMEOUT'); 
    insert into flags_text values ('sqltype', 64, 'SQ_PROCSTATS'); 
    insert into flags_text values ('sqltype', 65, 'SQ_GRANTGRP'); 
    insert into flags_text values ('sqltype', 66, 'SQ_REVOKGRP'); 
    insert into flags_text values ('sqltype', 67, 'SQ_SKINHIBIT'); 
    insert into flags_text values ('sqltype', 68, 'SQ_SKSHOW'); 
    insert into flags_text values ('sqltype', 69, 'SQ_SKSMALL'); 
    insert into flags_text values ('sqltype', 70, 'SQ_CRETRIG'); 
    insert into flags_text values ('sqltype', 71, 'SQ_DRPTRIG'); 
    insert into flags_text values ('sqltype', 72, 'SQ_UNKNOWN'); 
    insert into flags_text values ('sqltype', 73, 'SQ_SETDATASKIP'); 
    insert into flags_text values ('sqltype', 74, 'SQ_PDQPRIORITY'); 
    insert into flags_text values ('sqltype', 75, 'SQ_ALTFRAG'); 
    insert into flags_text values ('sqltype', 76, 'SQ_SETOBJMODE'); 
    insert into flags_text values ('sqltype', 77, 'SQ_START'); 
    insert into flags_text values ('sqltype', 78, 'SQ_STOP'); 
    insert into flags_text values ('sqltype', 79, 'SQ_SETMAC'); 
    insert into flags_text values ('sqltype', 80, 'SQ_SETDAC'); 
    insert into flags_text values ('sqltype', 81, 'SQ_SETTBLHI'); 
    insert into flags_text values ('sqltype', 82, 'SQ_SETLVEXT'); 
    insert into flags_text values ('sqltype', 83, 'SQ_CREATEROLE'); 
    insert into flags_text values ('sqltype', 84, 'SQ_DROPROLE'); 
    insert into flags_text values ('sqltype', 85, 'SQ_SETROLE'); 
    insert into flags_text values ('sqltype', 86, 'SQ_PASSWD'); 
    insert into flags_text values ('sqltype', 87, 'SQ_RENDB'); 
    insert into flags_text values ('sqltype', 88, 'SQ_CREADOM'); 
    insert into flags_text values ('sqltype', 89, 'SQ_DROPDOM'); 
    insert into flags_text values ('sqltype', 90, 'SQ_CREANRT'); 
    insert into flags_text values ('sqltype', 91, 'SQ_DROPNRT'); 
    insert into flags_text values ('sqltype', 92, 'SQ_CREADT'); 
    insert into flags_text values ('sqltype', 93, 'SQ_CREACT'); 
    insert into flags_text values ('sqltype', 94, 'SQ_DROPCT'); 
    insert into flags_text values ('sqltype', 95, 'SQ_CREABT'); 
    insert into flags_text values ('sqltype', 96, 'SQ_DROPTYPE'); 
    insert into flags_text values ('sqltype', 97, 'SQ_ALTERROUTINE'); 
    insert into flags_text values ('sqltype', 98, 'SQ_CREATEAM'); 
    insert into flags_text values ('sqltype', 99, 'SQ_DROPAM'); 
    insert into flags_text values ('sqltype', 100, 'SQ_ALTERAM'); 
    insert into flags_text values ('sqltype', 101, 'SQ_CREATEOPC'); 
    insert into flags_text values ('sqltype', 102, 'SQ_DROPOPC'); 
    insert into flags_text values ('sqltype', 103, 'SQ_CREACST'); 
    insert into flags_text values ('sqltype', 104, 'SQ_SETRES'); 
    insert into flags_text values ('sqltype', 105, 'SQ_CREAGG'); 
    insert into flags_text values ('sqltype', 106, 'SQ_DRPAGG'); 
    insert into flags_text values ('sqltype', 107, 'SQ_PLOADFILE'); 
    insert into flags_text values ('sqltype', 108, 'SQ_CHKIDX'); 
    insert into flags_text values ('sqltype', 109, 'SQ_SCHEDULE'); 
    insert into flags_text values ('sqltype', 110, 'SQ_SETENV'); 
    insert into flags_text values ('sqltype', 111, 'SQ_XPS_RES2'); 
    insert into flags_text values ('sqltype', 112, 'SQ_XPS_RES3'); 
    insert into flags_text values ('sqltype', 113, 'SQ_XPS_RES4'); 
    insert into flags_text values ('sqltype', 114, 'SQ_XPS_RES5'); 
    insert into flags_text values ('sqltype', 116, 'SQ_RENIDX'); 
 
 
 
{ Page Header } 
    
    insert into flags_text values ('syspaghdr', 
    1,'Data Page'); 
    insert into flags_text values ('syspaghdr', 
    2,'Partition Descriptor Page');  
    insert into flags_text values ('syspaghdr', 
    4,'Partition Free List Page');  
    insert into flags_text values ('syspaghdr', 
    8,'Chunk Free List Page');  
    insert into flags_text values ('syspaghdr', 
    9,'Remainder Data Page');  
    insert into flags_text values ('syspaghdr', 
    11,'Partition Resident BLOB Page');  
    insert into flags_text values ('syspaghdr', 
    12,'Blobspace Resident BLOB Page');  
    insert into flags_text values ('syspaghdr', 
    13,'BLOB Chunk Free List Bit Page');  
    insert into flags_text values ('syspaghdr', 
    14,'BLOB Chunk BLOB Map Page');  
    insert into flags_text values ('syspaghdr', 
    16,'B-Tree Node Page');  
    insert into flags_text values ('syspaghdr', 
    32,'B-Tree Root Node');  
    insert into flags_text values ('syspaghdr', 
    64,'B-Tree Twig Node');  
    insert into flags_text values ('syspaghdr', 
    128,'B-Tree Leaf Node');  
    insert into flags_text values ('syspaghdr', 
    256,'Logical Log Page');  
    insert into flags_text values ('syspaghdr', 
    512,'Last Page of Log Log');  
    insert into flags_text values ('syspaghdr', 
    1024,'Sync Page of Log Log');  
    insert into flags_text values ('syspaghdr', 
    2048,'Physical Log Page');  
    insert into flags_text values ('syspaghdr', 
    4096,'Reserved Page');  
    insert into flags_text values ('syspaghdr', 
    8192,'Temporarily no physical logging required');  
    insert into flags_text values ('syspaghdr', 
    16384,'Temporarily no physical logging required');  
    insert into flags_text values ('syspaghdr', 
    32768,'B-Tree Leaf Page containing deleted Items');  
 
 
{ Partition Header } 
 
    insert into flags_text values ('sysptnhdr', 1, 'Page Level Locking'); 
    insert into flags_text values ('sysptnhdr', 2, 'Row Level Locking'); 
    insert into flags_text values ('sysptnhdr', 32,'System created Temp Table'); 
    insert into flags_text values ('sysptnhdr', 64,'User created Temp Table'); 
    insert into flags_text values ('sysptnhdr', 128,'Sort File'); 
    insert into flags_text values ('sysptnhdr', 256,'Contains Varchar Data Type'); 
    insert into flags_text values ('sysptnhdr', 512,'Contains BLOBSpace BLOBS'); 
    insert into flags_text values ('sysptnhdr', 1024,'Contains TBLSpace BLOBS'); 
    insert into flags_text values ('sysptnhdr', 2048,'Contains either Varchars,BLOBS or Rows > PAGESIZE-32'); 
    insert into flags_text values ('sysptnhdr', 4096,'Contains optical Sub-System BLOBS'); 
    insert into flags_text values ('sysptnhdr', 8192,'Permanent System created Table ( undroppable )'); 
    insert into flags_text values ('sysptnhdr', 16384,'Special Function Temp Tables, no Bitmap Maintenance'); 
 
 
{ Bitmap } 
 
    insert into flags_text values ('sysptnbit',0,'Free Page'); 
    insert into flags_text values ('sysptnbit',1,'Remainder Page - free Space = Pagesize'); 
    insert into flags_text values ('sysptnbit',2,'PBLOB Page - free Space = Pagesize'); 
    insert into flags_text values ('sysptnbit',4,'Data Page with Room for another Row'); 
    insert into flags_text values ('sysptnbit',5,'Remainder Page - free Space between Pagesize and 2/3*Pagesize'); 
    insert into flags_text values ('sysptnbit',6,'PBLOB Page - free Space between Pagesize and 2/3*Pagesize'); 
    insert into flags_text values ('sysptnbit',8,'Index Page or Bitmap Page'); 
    insert into flags_text values ('sysptnbit',9,'Remainder Page - free Space between 2/3*Pagesize and 1/10*Pagesize'); 
    insert into flags_text values ('sysptnbit',10,'PBLOB Page - free Space between 2/3*Pagesize and 1/10*Pagesize'); 
    insert into flags_text values ('sysptnbit',12,'Data Page without Room for another Row'); 
    insert into flags_text values ('sysptnbit',13,'Remainder Page full - free Space < 1/10*Pagesize'); 
    insert into flags_text values ('sysptnbit',14,'PBLOB Page full - free Space < 1/10*Pagesize'); 
 
{ Create a table where the build status for 'sysutils' and any other system 
  activity associated with building 'sysmaster' can be recorded } 
  
    create table smi_build_status (message_num integer); 
 
{ Create a table where conversion messages can be entered by front end 
  shell scripts for displaying into the logmessage file } 
  
    create table logmessage (message_num integer); 
 
 
{ Stored procedure for setting boolean 'columns' in views for flags values } 
    create procedure bitval ( bitset int, bitmask int) returning int; 
    if (bitset < 0) then 
        if (bitmask < 0) then 
        return 1; 
        end if; 
        let bitset = bitset + 2147483648; 
    end if; 
    if (bitset > 1073741824) then 
        if (bitmask = 1073741824) then 
        return 1; 
        end if; 
    end if 
    if (mod(bitset,2*bitmask) >= bitmask) then 
        return 1; 
    end if 
    return 0; 
    end procedure; 
    grant execute on bitval to public; 
 
{ Stored procedure for converting unix time() long to date } 
    create procedure l2date ( l int ) returning date; 
    return trunc((l/86400) + 25568 ); 
    end procedure; 
    grant execute on l2date to public; 
 
 
create procedure physchunk( physaddr int ) returning int; 
  return trunc(physaddr/1048576); 
end procedure; 
grant execute on physchunk to public; 
 
 
create procedure physpage( physaddr int ) returning int; 
  return(mod(physaddr,1048576)); 
end procedure; 
grant execute on physpage to public; 
 
 
create procedure physaddr(chunknum int, pagenum int) returning int; 
  return((chunknum*1048576)+pagenum); 
end procedure; 
grant execute on physaddr to public; 
 
 
create procedure partdbsnum (partnum int ) returning int; 
  return trunc(partnum/1048576); 
end procedure; 
grant execute on partdbsnum to public; 
 
 
create procedure partpagenum(partnum int) returning int; 
  return(mod(partnum,1048576)); 
end procedure; 
grant execute on partpagenum to public; 
 
 
create procedure partaddr(dbspnum int, pagenum int) returning int; 
  return((dbspnum*1048576)+pagenum); 
end procedure; 
grant execute on partaddr to public; 
 
 
{ Session Waits profile } 
    create view sysseswts (sid, reason, numwaits, cumtime, maxtime) 
    as 
    select a.sid, c.txt, b.wnum, b.wcumtime, b.wmaxtime 
      from sysrstcb a, systwaits b, flags_text c 
     where a.tid = b.tid 
       and b.wreason = c.flags 
       and c.tabname = 'systwaits'; 
    grant select on sysseswts to public; 
 
 
{ Chunk Free List } 
    create view syschkextents ( ce_chknum, ce_extnum, ce_physaddr, ce_size ) 
    as select chknum, extnum, start, leng  from syschfree; 
    grant select on syschkextents to public; 
 
{ Partition Bit Maps } 
    create view systabpagtypes ( tp_partnum, tp_pagenum, tp_type ) 
    as select pb_partnum, pb_pagenum, pb_bitmap  from sysptnbit; 
    grant select on systabpagtypes to public; 
 
{ Logical Logs } 
    create view syslogs (number, uniqid, size, used,  
             is_used, is_current, is_backed_up,  
             is_new, is_archived, is_temp, flags) 
    as 
    select number, uniqid, size, used,  
           bitval(flags, '0x1'), bitval(flags, '0x2'), bitval(flags, '0x4'), 
           bitval(flags, '0x8'), bitval(flags, '0x10'),  
           bitval(flags, '0x20'), flags 
      from syslogfil 
     where number > 0; 
    grant select on syslogs to public; 
 
{ Chunks } 
    create view syschunks(chknum, dbsnum, nxchknum, chksize, offset, nfree, 
              mdsize, udsize, udfree, 
              is_offline, is_recovering, is_blobchunk, is_sbchunk, 
              is_inconsistent, flags, fname,  
              mfname, moffset, mis_offline, mis_recovering, mflags) 
    as 
    select a.chknum, a.dbsnum, a.nxchunk, a.chksize, a.offset, a.nfree, 
        a.mdsize, a.udsize, a.udfree, 
        bitval(a.flags, '0x20'), bitval(a.flags, '0x80'),  
        bitval(a.flags, '0x200'), bitval(a.flags, '0x4000'), 
        bitval(a.flags, '0x1000'), a.flags, a.fname, b.fname, b.offset,  
        bitval(b.flags, '0x20'), bitval(b.flags, '0x80'), b.flags 
      from syschktab a, outer sysmchktab b 
     where a.chknum = b.chknum 
       and a.chknum > 0; 
    grant select on syschunks to public; 
 
{ Dbspaces } 
    create view sysdbspaces(dbsnum, name, owner, fchunk, nchunks, is_mirrored,  
                is_blobspace, is_sbspace, is_temp, flags) 
    as 
    select dbsnum, name, owner, fchunk, nchunks, 
        bitval(flags, '0x2'), bitval(flags, '0x10'),  
        bitval(flags, '0x8000'), bitval(flags, '0x2000'), flags 
      from sysdbstab 
     where dbsnum > 0; 
    grant select on sysdbspaces to public; 
 
{ Locks (keep for 6.0 compatibility) } 
    create view syslocks (dbsname, tabname, rowidlk, keynum, type, 
              owner, waiter) 
    as 
    select dbsname, b.tabname, rowidr, keynum, e.txt[1,4], d.sid, f.sid 
      from syslcktab a, systabnames b, systxptab c, sysrstcb d,  
           flags_text e, outer sysrstcb f 
     where a.partnum = b.partnum 
       and a.owner = c.address 
       and c.owner = d.address 
       and a.wtlist = f.address 
       and e.tabname = 'syslcktab' 
       and e.flags = a.type; 
    grant select on syslocks to public; 
 
{ Locks } 
    create view syslocktab ( lk_id, lk_addr, lk_same, lk_wtlist, lk_owner, 
                             lk_list, lk_type, lk_flags, lk_bsize, lk_keynum, 
                             lk_rowid, lk_partnum, lk_kvobj, lk_dipnum,  
                             lk_grtime ) 
    as select indx, address, same, wtlist, owner, list, type, flags, bsize, 
    keynum, rowidr, partnum, rowidn, dipnum, grtime from syslcktab; 
    grant select on syslocktab to public; 
 
{ Active sessions } 
    create view syssessions ( sid, username, uid, pid, 
                  hostname, tty, connected, feprogram, 
                              pooladdr, 
                  is_wlatch, is_wlock, is_wbuff, is_wckpt, 
                  is_wlogbuf, is_wtrans, is_monitor, is_incrit, 
                  state 
                  ) 
    as 
    select a.sid, a.username, a.uid, a.pid, 
        a.hostname, a.ttyerr, a.connected, a.progname, a.poolp, 
        bitval(b.flags, '0x2'), bitval(b.flags, '0x4'), 
        bitval(b.flags, '0x8'), bitval(b.flags, '0x10'),  
        bitval(b.flags, '0x1000'), bitval(b.flags, '0x40000'),  
        bitval(b.flags, '0x80'), bitval(b.flags, '0x100'), b.flags 
      from sysscblst a, sysrstcb b 
     where a.address = b.scb 
       and bitval(b.flags, '0x80000') = 1;  { primary thread } 
    grant select on syssessions to public; 
 
{ Session activity profile } 
    create view syssesprof(sid, lockreqs, locksheld, lockwts,  
               deadlks, lktouts, logrecs, isreads,  
               iswrites, isrewrites, isdeletes, iscommits,  
               isrollbacks, longtxs, bufreads, bufwrites,  
               seqscans, pagreads, pagwrites, total_sorts,  
                           dsksorts, max_sortdiskspace, logspused, maxlogsp ) 
    as 
        select sid,sum( upf_rqlock),sum(nlocks),sum(upf_wtlock),sum(upf_deadlk), 
                   sum(upf_lktouts),sum(upf_lgrecs),sum(upf_isread), 
                   sum(upf_iswrite),sum(upf_isrwrite),sum(upf_isdelete), 
                   sum(upf_iscommit),sum(upf_isrollback),sum(upf_longtxs), 
                   sum(upf_bufreads),sum(upf_bufwrites),sum(upf_seqscans), 
                   sum(nreads), sum(nwrites), sum(upf_totsorts), 
                   sum(upf_dsksorts),sum(upf_srtspmax),sum(upf_logspuse), 
                   sum(upf_logspmax) 
          from sysrstcb  
             where sid > 0 
                group by sid; 
 
    grant select on syssesprof to public; 
 
{ User and system time by VP } 
    create view sysvpprof ( vpid, class, usercpu, syscpu) 
    as 
    select a.vpid, b.txt, a.usecs_user, a.usecs_sys 
      from sysvplst a, flags_text b 
     where a.flags != 6 
       and a.class = b.flags 
       and b.tabname = 'sysvplst'; 
    grant select on sysvpprof to public; 
 
{ Partition profile } 
    create view sysptprof (dbsname, tabname, partnum, 
                   lockreqs, lockwts, deadlks, lktouts,  
               isreads, iswrites, isrewrites, isdeletes, 
                           bufreads, bufwrites, seqscans, pagreads, 
                           pagwrites ) 
    as 
    select a.dbsname, a.tabname, b.partnum, 
        b.pf_rqlock, b.pf_wtlock, b.pf_deadlk, b.pf_lktouts,  
        b.pf_isread, b.pf_iswrite, b.pf_isrwrite, b.pf_isdelete, 
                b.pf_bfcread, b.pf_bfcwrite, b.pf_seqscans, b.pf_dskreads, 
                b.pf_dskwrites  
      from systabnames a, sysptntab b 
     where a.partnum = b.partnum; 
    grant select on sysptprof to public; 
 
{ Profile listing } 
    create view sysprofile ( name, value ) 
    as 
    select name[4,16], value 
      from sysshmhdr 
     where name matches 'pf_*'; 
    grant select on sysprofile to public; 
 
{ Listing of supported configuration parameters } 
    create view sysconfig ( cf_id, cf_name, cf_flags, cf_original, cf_effective, cf_default ) 
        as    
        select cf_id, cf_name, cf_flags, cf_original, cf_effective, cf_default 
          from syscfgtab 
         where cf_flags = 0; 
    grant select on sysconfig to public; 
 
{ Extent listings (keep for 6.0 compatibility) } 
    create view sysextents ( dbsname, tabname, start, size) 
    as 
    select dbsname, tabname, pe_phys, pe_size 
      from systabnames a, sysptnext b 
     where a.partnum = b.pe_partnum; 
    grant select on sysextents to public; 
 
{ Extent listings } 
    create view systabextents ( te_partnum, te_extnum, te_physaddr, 
                                te_size, te_pagenum ) 
    as select pe_partnum, pe_extnum, pe_phys, pe_size, pe_log   
    from sysptnext; 
    grant select on systabextents to public; 
 
{ Data Replication info } 
    create view sysdri (type, state, name, intvl, timeout, lostfound) 
    as 
    select b.txt, d.txt, a.name, a.intvl, a.timeout, a.lostfound 
      from sysdrcb a, flags_text b, sysdrcb c, flags_text d 
     where a.type = b.flags 
       and b.tabname = 'sysdrcb' 
       and c.state = d.flags 
       and d.tabname = 'sysdrcb'; 
    grant select on sysdri to public; 
 
{ Databases } 
    create view sysdatabases (name, partnum, owner, created, 
                  is_logging, is_buff_log, is_ansi,  
                  is_nls, flags) 
    as 
    select name, partnum, owner, date(dbinfo('UTC_TO_DATETIME', created)), 
           bitval(flags, 1), bitval(flags, 2), bitval(flags, 4), 
           bitval(flags, 16), flags 
      from sysdbspartn; 
    grant select on sysdatabases to public; 
 
{ Threads view } 
    create view systhreads (th_id, th_addr, th_joinlist, th_joinnext, 
        th_joinee, th_name, th_state, th_priority, th_class, th_vpid, 
        th_mtxwait, th_conwait, th_waketime, th_startwait, 
        th_startrun ) 
    as 
    select  tid,  address,  joinlist, joinnext, joinee, name, state, 
        priority, class, vpid, wtmutexp, wtcondp, sleep_time,  
        start_wait, run_time 
      from  systcblst; 
    grant select on systhreads to public; 
 
{ Mutexes view } 
    create view sysmutexes (mtx_id, mtx_address, mtx_lock, mtx_holder,  
            mtx_wtlist, mtx_name ) 
    as 
    select  mtx_id, mtx_address, mtx_lock, mtx_holder, mtx_wtlist, 
        mtx_name 
      from  sysmtxlst; 
    grant select on sysmutexes to public; 
 
{ Conditions view } 
    create view sysconditions (con_id, con_address, con_lock,  
            con_wtlist, con_name ) 
    as 
    select  con_id, con_address, con_lock, con_wtlist, con_name 
      from  sysconlst; 
    grant select on sysconditions to public; 
 
{ Pools view } 
    create view syspools (po_id, po_address, po_name, po_class,  
            po_freeamt, po_usedamt ) 
    as 
    select  po_id, po_address, po_name, po_class, po_freeamt, po_usedamt 
      from  syspoollst; 
    grant select on syspools to public; 
 
{ Segments view } 
    create view syssegments (seg_address, seg_class, seg_size, seg_osshmid, 
            seg_osshmkey, seg_shmaddr, seg_ovhd, 
            seg_blkused, seg_blkfree) 
    as 
    select  seg_address, seg_class, seg_size, seg_osshmid,seg_osshmkey, 
        seg_shmaddr, seg_ovhd, seg_blkused, seg_blkfree 
      from  sysseglst; 
    grant select on syssegments to public; 
 
{ Threads Wait Stats view } 
    create view systhreadwaits (tw_tid, tw_reason, tw_num, tw_cumtime, 
            tw_maxtime)  
    as 
    select tid, wreason, wnum, wcumtime, wmaxtime 
      from  systwaits; 
    grant select on systhreadwaits to public; 
 
{ Mutex queue view } 
    create view sysmutq (mq_mtxid, mq_nwaits, mq_nservs, mq_curlen, mq_totlen, 
            mq_maxlen, mq_waittime, mq_servtime, mq_maxwait) 
    as 
    select mtx_id, mtx_nwaits, mtx_nservs, mtx_curlen, mtx_totlen,  
        mtx_maxlen, mtx_waittime, mtx_servtime, mtx_maxwait 
      from  sysmtxlst; 
    grant select on sysmutq to public; 
 
{ Condition queue view } 
    create view sysconq (cq_conid, cq_nwaits, cq_nservs, cq_curlen, cq_totlen, 
            cq_maxlen, cq_waittime, cq_servtime, cq_maxwait) 
    as 
    select con_id, con_nwaits, con_nservs, con_curlen, con_totlen, 
        con_maxlen, con_waittime, con_servtime, con_maxwait 
      from  sysconlst; 
    grant select on sysconq to public; 
 
 
{ Userthreads } 
 
  create view sysuserthreads ( 
    us_indx, us_address, us_txp, us_txwait, us_txlist, us_iserrno, 
    us_isrecnum, us_isfragnum, us_uid, us_name, us_sid, 
    us_scb, us_tid, us_mttcb, us_nxtthread, us_flags,  
    us_nlocks, us_lastlktype, us_lktout, us_lkwait, us_lklist, 
    us_lkwttype, us_lkthreadlist, us_lktolist, us_bfwait, us_bflist, 
    us_bfwtflag, us_bfheldcnt, us_lbufwake, us_lgbuffered, us_rqlock, 
    us_wtlock, us_deadlk, us_lktouts, us_lgrecs, us_isread, us_iswrite, 
    us_isrwrite, us_isdelete, us_iscommit, us_isrollback, us_longtxs, 
    us_bufreads, us_bufwrites, us_pagreads, us_pagwrites, us_seqscans,  
    us_totsorts, us_dsksorts, us_srtspmax, us_logspuse, us_logspmax 
    ) as select 
     indx, address, txp, txwait, txlist, iserrno, isrecnum, isfragnum,  
     uid, username, sid, scb, tid, mttcb, nxtthread, flags, nlocks, 
     lastlock, lktout, lkwait, wtlist, lkwttype, lkthreadlist, tolist, 
     bfwait, bflist, bfwtflag, bfheld_count, lbufwake, bufferlogging, 
     upf_rqlock, upf_wtlock, upf_deadlk, upf_lktouts, upf_lgrecs, 
     upf_isread, upf_iswrite, upf_isrwrite, upf_isdelete, upf_iscommit, 
     upf_isrollback, upf_longtxs, upf_bufreads, upf_bufwrites, nreads, 
     nwrites, upf_seqscans, upf_totsorts, upf_dsksorts, upf_srtspmax,  
     upf_logspuse, upf_logspmax from sysrstcb; 
 
     grant select on sysuserthreads to public; 
 
{ systrans } 
 
  create view systrans ( 
    tx_id, tx_addr, tx_flags, tx_mutex, tx_logbeg, tx_loguniq, tx_logpos, 
    tx_lklist, tx_lkmutex, tx_owner, tx_wtlist, tx_ptlist, tx_nlocks, 
    tx_lktout, tx_isolevel, tx_longtx, tx_coordinator, tx_nremotes ) 
    as select 
    indx, address, flags, latchp, logbeg, loguniq, logpos, lklist, 
        lklatchp, owner, wtlist, ptlist, nlocks, lkwait, isolevel, longtx, 
    istar_coord, nremotes 
    from systxptab; 
 
    grant select on systrans to public; 
  
 
{ Partition Headers } 
    create view systabinfo  
    ( 
    ti_partnum, ti_flags, ti_rowsize, ti_ncols, ti_nkeys, ti_nextns, 
    ti_created, ti_serialv, ti_fextsiz, ti_nextsiz, ti_nptotal, 
    ti_npused, ti_npdata, ti_octptnm, ti_nrows  
    ) 
        as select 
    partnum, flags, rowsize, ncols, nkeys, nextns, created, serialv, 
    fextsiz, nextsiz, nptotal, npused, npdata, octptnm, nrows 
        from sysptnhdr; 
 
        grant select on systabinfo to public; 
 
{ Page Headers } 
    create view systabpaghdrs  
    ( pg_partnum, pg_pagenum, pg_physaddr, pg_stamp, pg_stamp2, 
    pg_nslots, pg_flags, pg_frptr, pg_frcnt, pg_next, pg_prev ) 
        as select * from syspaghdr where 
        pg_partnum > 1048576; 
 
        grant select on systabpaghdrs to public; 
 
 
{ Page Headers } 
    create view sysphyspaghdrs 
    ( pg_pagenum, pg_physaddr, pg_stamp, pg_stamp2, 
    pg_nslots, pg_flags, pg_frptr, pg_frcnt, pg_next, pg_prev ) 
        as select 
    pg_pagenum, pg_physaddr, pg_stamp, pg_stamp2, 
    pg_nslots, pg_flags, pg_frptr, pg_frcnt, pg_next, pg_prev  
        from syspaghdr where 
        pg_partnum = 0; 
 
        grant select on sysphyspaghdrs to public; 
 
{ C2 Audit mask table } 
  create table sysaudit 
        ( 
        username        char(32),       { user name                     } 
        succ1           integer,        { success bitmask 1             } 
        succ2           integer,        { success bitmask 2             } 
        succ3           integer,        { success bitmask 3             } 
        succ4           integer,        { success bitmask 4             } 
        succ5           integer,        { success bitmask 5             } 
        fail1           integer,        { failure bitmask 1             } 
        fail2           integer,        { failure bitmask 2             } 
        fail3           integer,        { failure bitmask 3             } 
        fail4           integer,        { failure bitmask 4             } 
        fail5           integer         { failure bitmask 5             } 
        ) lock mode row; 
    create unique index sysaudit_ix1 on sysaudit(username) in table; 
    revoke all on sysaudit from public; 
 
{ Chunk io stats } 
    create view syschkio (chunknum,  
                reads, pagesread, 
                writes, pageswritten, 
                mreads, mpagesread, 
                mwrites, mpageswritten) 
    as 
        select a.chknum,  
        a.reads, a.pagesread, 
        a.writes, a.pageswritten, 
        b.reads, b.pagesread, 
        b.writes, b.pageswritten 
      from syschktab a, outer sysmchktab b 
     where a.chknum > 0 
       and a.chknum = b.chknum; 
    grant select on syschkio to public; 
 
{ Locale in which the database was created in } 
    create view sysdbslocale (dbs_dbsname, dbs_collate) 
    as 
        select b.name, a.collate 
      from systabnames a, sysdbspartn b 
     where a.partnum = b.partnum; 
    grant select on sysdbslocale to public; 
 
 
{ SQL Dictionary cache } 
    create view sysdiccache (dic_hashno, dic_chainno, 
            dic_refcount, dic_dirtyflag, dic_heapptr, 
            dic_dbname, dic_servername, dic_ownername, dic_tabname) 
        as 
        select dic_hashno, dic_chainno, 
        dic_refcount, bitval(dic_flags, '0x00800000'), hex(dic_heapptr), 
        dic_dbname, dic_servername, dic_ownername, dic_tabname 
        from sysdic; 
    grant select on sysdiccache to public; 
 
{ SQL Distribution cache } 
    create view sysdistcache (dis_hashno, dis_chainno, 
            dis_id, dis_refcount, dis_dropped, dis_heapptr, 
            dis_dbname, dis_servername, dis_ownername, dis_distname) 
        as 
        select dis_hashno, dis_chainno, 
        dis_id, dis_refcnt, dis_delete, hex(dis_heapptr), 
        dis_dbname, dis_servername, dis_ownername, dis_name 
        from sysdsc; 
    grant select on sysdistcache to public; 
 
{ SQL Procedure cache } 
    create view sysproccache (prc_hashno, prc_chainno, 
            prc_id, prc_refcount, prc_dropped, prc_heapptr, 
            prc_dbname, prc_servername, prc_ownername, prc_procname) 
        as 
        select prc_hashno, prc_chainno, 
        prc_id, prc_refcnt, prc_delete, hex(prc_heapptr), 
        prc_dbname, prc_servername, prc_ownername, prc_name 
        from sysprc; 
    grant select on sysproccache to public; 
 
{ SQL Statements } 
    create view syssqlcurall ( 
    sqc_sessionid, sqc_currdb, sqc_isolationlevel, sqc_lockmode, sqc_sqerrno,  
        sqc_isamerr, sqc_fevers) 
    as 
        select scb_sessionid, odb_dbname, ft.txt, scb_lockmode, 
           scb_sqerrno, scb_iserrno, scb_feversion 
        from syssqscb, outer ( sysopendb, flags_text ft ) 
    where scb_sessionid == odb_sessionid 
      and odb_iscurrent == 'Y' 
      and ft.tabname == 'sysopendb' 
      and ft.flags   == odb_isolation 
      and scb_feversion > '0.00'; 
    grant select on syssqlcurall to public; 
 
{ SQL Current session } 
    create view syssqlcurses ( 
    scs_sessionid, scs_currdb, scs_isolationlevel, scs_lockmode, 
        scs_executions, scs_cumtime, scs_bufreads, scs_pagereads, 
        scs_bufwrites, scs_pagewrites, scs_totsorts, scs_dsksorts, 
        scs_sortspmax, scs_sqerrno, scs_isamerr, scs_fevers,  
        scs_sqlstatement) 
    as 
    select scb_sessionid,  odb_dbname, ft.txt, scb_lockmode, sdb_executions,  
        sdb_cumtime, sdb_bufreads, sdb_pagereads, sdb_bufwrites,  
        sdb_pagewrites, sdb_totsorts, sdb_dsksorts, sdb_sortspmax, 
        scb_sqerrno, scb_iserrno, scb_feversion, cbl_stmt 
    from syssqscb, syssdblock, outer sysconblock, 
    outer ( sysopendb, flags_text ft ) 
        where scb_sessionid == odb_sessionid 
          and scb_sessionid == sdb_sessionid 
          and scb_sessionid == cbl_sessionid 
      and scb_feversion > '0.00' 
          and sdb_sdbno == cbl_sdbno 
          and sdb_iscurrent == 'Y' 
          and odb_iscurrent == 'Y' 
          and cbl_ismainblock == 'Y' 
      and ft.tabname == 'sysopendb' 
      and ft.flags   == odb_isolation 
          ; 
    grant select on syssqlcurses to public; 
 
{ Show sqexplain information } 
    create view syssqexplain (      { Internal Use Only     } 
        sqx_sessionid, sqx_sdbno, sqx_iscurrent, sqx_executions,  
        sqx_cumtime, sqx_bufreads, sqx_pagereads, sqx_bufwrites,  
        sqx_pagewrites, sqx_totsorts, sqx_dsksorts, sqx_sortspmax, 
        sqx_conbno, sqx_ismain, sqx_selflag, sqx_estcost, sqx_estrows, 
        sqx_seqscan, sqx_srtscan, sqx_autoindex, sqx_index, sqx_remsql, 
        sqx_mrgjoin, sqx_dynhashjoin, sqx_keyonly, sqx_tempfile, 
        sqx_tempview, sqx_secthreads, sqx_sqlstatement) 
    as 
    select sdb_sessionid,  sdb_sdbno, sdb_iscurrent, sdb_executions, 
        sdb_cumtime, sdb_bufreads, sdb_pagereads, sdb_bufwrites,  
        sdb_pagewrites, sdb_totsorts, sdb_dsksorts, sdb_sortspmax, 
       cbl_conbno, cbl_ismainblock, ft.txt, cbl_estcost, cbl_estrows, 
        cbl_seqscan, cbl_srtscan, cbl_autoindex, cbl_index, cbl_remsql, 
        cbl_mrgjoin, cbl_dynhashjoin, cbl_keyonly, cbl_tempfile, 
        cbl_tempview, cbl_secthreads, cbl_stmt 
    from syssdblock, outer ( sysconblock, flags_text ft ) 
        where sdb_sessionid == cbl_sessionid 
          and sdb_sdbno     == cbl_sdbno 
      and ft.tabname    == 'sqltype' 
      and ft.flags      == cbl_selflag 
          ; 
    grant select on syssqexplain to public; 
 
{ Extspaces Table } 
    create table sysextspaces           { Internal Use Only } 
        ( 
        id              integer,        { external space id             } 
        name            char(128),      { extspace name                 } 
        owner           char(32),       { extspace owner                } 
        flags           integer,        { extspace flags                } 
        refcnt          integer,        { extspace reference count      } 
        locsize         integer,        { size of location              } 
        locatio         char(256)       { external space location       } 
        ); 
    create unique index sysextspace_ix1 on sysextspaces(name) in table; 
    revoke all on sysextspaces from public; 
    grant select on sysextspaces to public; 
 
{ Archive-related Tables } 
 
{ Volume set information } 
    create table arc_vset 
    ( 
    vset_vid            smallint    primary key, 
    vset_name           char(17)    not null unique, 
    vset_class          char(1)     not null, 
    vset_onsite         char(1)     not null, 
    vset_imported       char(1)     not null, 
    vset_foreign        char(1)     not null, 
    vset_perm_mounted   char(1)     not null, 
    vset_transit        char(1)     not null, 
    vset_accessibility  smallint    not null, 
    vset_owner_node     char(255)   not null, 
    vset_dev_node       char(255)   not null, 
    vset_dev_type       char(128)   not null, 
    vset_dev_driver     char(10)    not null, 
    vset_nb_volumes     smallint    not null, 
    vset_density        char(4), 
    vset_location       char(80), 
    vset_parameters     char(20), 
    vset_protection     char(3), 
    vset_comment        char(80) 
    ); 
    revoke all on arc_vset from public; 
    grant all on arc_vset to root; 
    grant select on arc_vset to public; 
 
{ Volume information } 
    create table arc_volume 
    ( 
    vol_vid             smallint    not null, 
    vol_vno             smallint    not null, 
    vol_max_space       integer     not null, 
    vol_used_space      integer     not null, 
    vol_space_exact     char(1)     not null, 
    vol_full            char(1)     not null, 
    vol_nb_svst         integer     not null, 
    vol_nb_svst_phys    integer     not null, 
    vol_virtual         char(255), 
    vol_parameters      char(20), 
    vol_protection      char(3), 
    vol_rewind_date     datetime    year to day, 
    vol_comment         char(80), 
    vol_label           char(6), 
    vol_remote_virtual  char(255), 
 
    primary key (vol_vid, vol_vno) 
    ); 
    revoke all on arc_volume from public; 
    grant all on arc_volume to root; 
    grant select on arc_volume to public; 
 
{ Volume-set, User relationship information } 
    create table arc_vset_user 
    ( 
    vu_vid              smallint    not null, 
    vu_user_node        char(255)   not null, 
    vu_user_name        char(40)    not null, 
 
    primary key (vu_vid, vu_user_name) 
    ); 
    revoke all on arc_vset_user from public; 
    grant all on arc_vset_user to root; 
    grant select on arc_vset_user to public; 
 
{ Disk usage information } 
    create table arc_diskspace_mgr 
    ( 
    dsm_vid             smallint    not null, 
    dsm_vno             smallint    not null, 
    dsm_pid             integer     not null, 
    dsm_spaces_alloc    integer     not null); 
 
    create index arc_dsk_i1 on arc_diskspace_mgr 
    (dsm_vid, dsm_vno, dsm_pid); 
    revoke all on arc_diskspace_mgr from public; 
    grant all on arc_diskspace_mgr to root; 
    grant select on arc_diskspace_mgr to public; 
 
{ Request information (for archives, restores, backups) } 
    create table arc_request 
    ( 
    req_rid             integer     primary key, 
    req_type            char(2)     not null, 
    req_status          char(2)     not null, 
    req_issue_date      datetime    year to second, 
    req_user_node       char(255)   not null, 
    req_user_name       char(40)    not null, 
    req_user_lang       char(1)     not null, 
    req_qlf_string      char(1200)  not null, 
    req_password        byte in table, 
    req_former_rid      integer, 
    req_former_sid      smallint, 
    req_expiry_date     datetime    year to second, 
    req_execution_date  datetime    year to second, 
    req_dflt_dir_name   char(255) 
    ); 
 
    create index arc_req_i1 on arc_request 
    (req_user_name); 
    revoke all on arc_request from public; 
    grant all on arc_request to root; 
    grant select on arc_request to public; 
 
{ Volume-Request-PID-usage lock & relationship information } 
    create table arc_vol_lock 
    ( 
    vlck_vid            smallint    not null, 
    vlck_vno            smallint    not null, 
    vlck_rid            integer     not null, 
    vlck_pid            integer     not null, 
    vlck_exclusive      char(1)     not null, 
    vlck_operation      char(1)     not null, 
 
    primary key (vlck_vid, vlck_vno, vlck_pid) 
    ); 
    revoke all on arc_vol_lock from public; 
    grant all on arc_vol_lock to root; 
    grant select on arc_vol_lock to public; 
 
{ Pending requests } 
    create table arc_pending_req 
    ( 
    pend_rid            integer     not null, 
    pend_lock_pid       integer     not null, 
    pend_parent_rid     integer, 
    pend_dflt_dir_name  char(255), 
 
    primary key (pend_rid) 
    ); 
    revoke all on arc_pending_req from public; 
    grant all on arc_pending_req to root; 
    grant select on arc_pending_req to public; 
 
{ Volume set-Request relationship information } 
    create table arc_req_vset 
    ( 
    rv_rid              integer     not null, 
    rv_vid              smallint    not null, 
 
    primary key (rv_rid, rv_vid) 
    ); 
    revoke all on arc_req_vset from public; 
    grant all on arc_req_vset to root; 
    grant select on arc_req_vset to public; 
 
{ Save set information } 
    create table arc_save_set 
    ( 
    svst_rid            integer     not null, 
    svst_vid            smallint    not null, 
    svst_complete       char(1)     not null, 
    svst_attached_rid   integer, 
    svst_transit_date   datetime    year to day, 
    svst_nb_volumes     smallint    not null, 
 
    primary key (svst_rid, svst_vid) 
    ); 
    revoke all on arc_save_set from public; 
    grant all on arc_save_set to root; 
    grant select on arc_save_set to public; 
 
{ File information (all file types) } 
    create table arc_file 
    ( 
    file_rid            integer     not null, 
    file_fno            integer     not null, 
    file_type           char(1)     not null, 
    file_name           char(255)   not null, 
    file_dno            integer     not null,    
    file_nb_copies      smallint    not null, 
    file_compressed     char(1)     not null, 
    file_encrypted      char(1)     not null, 
    file_creation_date  datetime    year to day not null, 
    file_modify_date    datetime    year to day, 
    file_expiry_date    datetime    year to day, 
    file_comment        char(80), 
 
    primary key (file_rid, file_fno) 
    ); 
    revoke all on arc_file from public; 
    grant all on arc_file to root; 
    grant select on arc_file to public; 
 
{ File directory information } 
    create table arc_directory 
    ( 
    dir_rid             integer     not null, 
    dir_dno             integer     not null, 
    dir_name            char(255)   not null, 
 
    primary key (dir_rid, dir_dno) 
    ); 
    revoke all on arc_directory from public; 
    grant all on arc_directory to root; 
    grant select on arc_directory to public; 
 
{ DB extract output file information } 
{ Not used by Informix; included for consistency with Computertime } 
    create table arc_db_file 
    ( 
    dbf_rid             integer     not null, 
    dbf_fno             integer     not null, 
    dbf_db_name         char(30)    not null, 
    dbf_user_name       char(30)    not null, 
    dbf_table_name      char(30)    not null, 
    dbf_nb_rows         integer     not null, 
    dbf_retrieved_rows  integer, 
    dbf_sql             char(255), 
 
    primary key (dbf_rid, dbf_fno) 
    ); 
    revoke all on arc_db_file from public; 
    grant all on arc_db_file to root; 
    grant select on arc_db_file to public; 
 
{ Copy information } 
    create table arc_file_copy 
    ( 
    fc_rid              integer     not null, 
    fc_fno              integer     not null, 
    fc_sno              smallint    not null, 
    fc_vid              smallint    not null, 
    fc_vno              smallint    not null, 
    fc_last_sno         char(1)     not null, 
 
    primary key (fc_vid, fc_vno, fc_rid, fc_fno) 
    ); 
 
    create index arc_file_copy_i1 on arc_file_copy 
    (fc_rid, fc_fno); 
    revoke all on arc_file_copy from public; 
    grant all on arc_file_copy to root; 
    grant select on arc_file_copy to public; 
 
{ Dbspace set definitions; used only by Informix } 
    create table arc_dbspace_set 
    ( 
    ds_dsid             serial      primary key, 
    ds_name             char(128)   not null 
    ); 
 
    create unique index arc_dbspace_set_i1 on arc_dbspace_set 
        (ds_name); 
    revoke all on arc_dbspace_set from public; 
    grant all on arc_dbspace_set to root; 
    grant select on arc_dbspace_set to public; 
 
{ Dbspace-dbspace set relationships; used only by Informix } 
    create table arc_dbspace    
    ( 
    dbs_name            char(128)   not null, 
    dbs_dsid            integer     not null references arc_dbspace_set 
    ); 
 
    create index arc_dbspace_i1 on arc_dbspace 
        (dbs_name); 
    revoke all on arc_dbspace from public; 
    grant all on arc_dbspace to root; 
    grant select on arc_dbspace to public; 
 
{ Archive event information; used only by Informix } 
    create table arc_archive_event  
    ( 
    ae_rid              integer     not null references arc_request, 
    ae_dsid             integer     not null, 
    ae_level            smallint    not null, 
    ae_timestamp        integer     not null, 
    ae_prior_rid        integer, 
        ae_logid            integer 
    ); 
    revoke all on arc_archive_event from public; 
    grant all on arc_archive_event to root; 
    grant select on arc_archive_event to public; 
 
    create table arc_version 
       ( 
       av_version           char(128)    not null, 
       av_name              byte in table 
       ); 
    revoke all on arc_version from public; 
    grant all on arc_version to root; 
 
{ Views are used during inserts and modifies for integrity checking } 
 
    create view arc_vset_view  
    as  
    select * from arc_vset 
        where vset_class         in ('S', 'U') 
          and vset_onsite        in ('Y', 'N', 'U') 
          and vset_imported      in ('Y', 'N') 
          and vset_perm_mounted  in ('Y', 'N') 
          and vset_transit       in ('Y', 'N') 
          and vset_nb_volumes    >= 0 
    with check option; 
    revoke all on arc_vset_view from public; 
    grant select on arc_vset_view to root; 
    grant insert on arc_vset_view to root; 
    grant delete on arc_vset_view to root; 
    grant update on arc_vset_view to root; 
 
    create view arc_volume_view 
    as  
    select * from arc_volume 
        where vol_max_space     >= 0 
          and vol_used_space    >= 0 
          and vol_nb_svst       >= 0 
          and vol_nb_svst_phys  >= 0 
          and vol_space_exact   in ('Y', 'N') 
          and vol_full          in ('Y', 'N') 
          and vol_vid           in (select vset_vid from arc_vset)   
    with check option; 
    revoke all on arc_volume_view from public; 
    grant select on arc_volume_view to root; 
    grant insert on arc_volume_view to root; 
    grant delete on arc_volume_view to root; 
    grant update on arc_volume_view to root; 
 
    create view arc_vset_user_view 
    as  
    select * from arc_vset_user 
        where vu_vid in (select vset_vid from arc_vset) 
    with check option; 
    revoke all on arc_vset_user_view from public; 
    grant select on arc_vset_user_view to root; 
    grant insert on arc_vset_user_view to root; 
    grant delete on arc_vset_user_view to root; 
    grant update on arc_vset_user_view to root; 
 
    create view arc_vol_lock_view 
    as  
    select * from arc_vol_lock 
        where vlck_vid in (select vset_vid from arc_vset) 
          and (vlck_vno = 0   
        or vlck_vno in (select vol_vno from arc_volume 
                    where vol_vid = vlck_vid)) 
          and (vlck_rid = 0    
        or vlck_rid in (select req_rid from arc_request)) 
          and vlck_pid > 0 
          and vlck_exclusive in ('Y', 'N') 
          and vlck_operation in ('R', 'W', 'D') 
    with check option; 
    revoke all on arc_vol_lock_view from public; 
    grant select on arc_vol_lock_view to root; 
    grant insert on arc_vol_lock_view to root; 
    grant delete on arc_vol_lock_view to root; 
    grant update on arc_vol_lock_view to root; 
 
    create view arc_request_view 
    as  
    select * from arc_request 
        where req_type       in ('AR', 'BK', 'CO', 'RT', 'RM', 'RB') 
          and req_status     in ('NE', 'EX', 'PA', 'CA', 'FA', 'SU', 'UC') 
          and req_user_lang  in ('E', 'F') 
          and ( (req_expiry_date is not null  
          and (req_type in ('AR', 'BK', 'CO'))) 
        or req_expiry_date is null) 
    with check option; 
    revoke all on arc_request_view from public; 
    grant select on arc_request_view to root; 
    grant insert on arc_request_view to root; 
    grant delete on arc_request_view to root; 
    grant update on arc_request_view to root; 
 
    create view arc_pendreq_view 
    as  
    select * from arc_pending_req 
        where pend_rid in (select req_rid from arc_request 
                   where req_status in ('NE', 'EX', 'PA')) 
          and pend_lock_pid >= 0 
          and (pend_parent_rid is null  
        or pend_parent_rid in (select req_rid from arc_request 
                       where req_status in ('PA', 'EX'))) 
    with check option; 
    revoke all on arc_pendreq_view from public; 
    grant select on arc_pendreq_view to root; 
    grant insert on arc_pendreq_view to root; 
    grant delete on arc_pendreq_view to root; 
    grant update on arc_pendreq_view to root; 
 
    create view arc_req_vset_view 
    as  
    select * from arc_req_vset 
        where rv_rid in (select req_rid from arc_request) 
          and rv_vid in (select vset_vid from arc_vset) 
    with check option; 
    revoke all on arc_req_vset_view from public; 
    grant select on arc_req_vset_view to root; 
    grant insert on arc_req_vset_view to root; 
    grant delete on arc_req_vset_view to root; 
    grant update on arc_req_vset_view to root; 
 
    create view arc_save_set_view 
    as  
    select * from arc_save_set 
        where svst_rid        in (select req_rid from arc_request 
                      where (req_type in ('AR', 'BK'))) 
          and svst_vid        in (select vset_vid from arc_vset) 
          and svst_complete   in ('Y', 'N') 
          and svst_nb_volumes >= 0 
    with check option; 
    revoke all on arc_save_set_view from public; 
    grant select on arc_save_set_view to root; 
    grant insert on arc_save_set_view to root; 
    grant delete on arc_save_set_view to root; 
    grant update on arc_save_set_view to root; 
 
    create view arc_file_view 
    as  
    select * from arc_file 
        where file_type       in ('F', 'D') 
          and file_rid        in (select req_rid from arc_request 
                      where (req_type in ('AR', 'BK'))) 
          and file_compressed in ('Y', 'N') 
          and file_encrypted  in ('Y', 'N') 
              and ((file_dno = 0) or 
              (file_dno        in (select dir_dno from arc_directory 
                      where dir_rid = file_rid))) 
    with check option; 
    revoke all on arc_file_view from public; 
    grant select on arc_file_view to root; 
    grant insert on arc_file_view to root; 
    grant delete on arc_file_view to root; 
    grant update on arc_file_view to root; 
 
    create view arc_directory_view 
    as  
    select * from arc_directory 
        where dir_rid in (select req_rid from arc_request) 
    with check option; 
    revoke all on arc_directory_view from public; 
    grant select on arc_directory_view to root; 
    grant insert on arc_directory_view to root; 
    grant delete on arc_directory_view to root; 
    grant update on arc_directory_view to root; 
 
    create view arc_db_file_view 
    as  
    select * from arc_db_file 
        where dbf_fno = (select file_fno from arc_file 
                 where file_rid = dbf_rid 
                   and file_fno = dbf_fno 
                   and file_type = 'D') 
    with check option; 
    revoke all on arc_db_file_view from public; 
    grant select on arc_db_file_view to root; 
    grant insert on arc_db_file_view to root; 
    grant delete on arc_db_file_view to root; 
    grant update on arc_db_file_view to root; 
 
    create view arc_file_copy_view 
    as  
    select * from arc_file_copy 
        where fc_fno = (select file_fno from arc_file 
                where file_rid = fc_rid 
                  and file_fno = fc_fno) 
          and fc_vno = (select vol_vno from arc_volume 
                where vol_vid = fc_vid 
                  and vol_vno = fc_vno) 
          and fc_last_sno in ('Y', 'N') 
    with check option; 
    revoke all on arc_file_copy_view from public; 
    grant select on arc_file_copy_view to root; 
    grant insert on arc_file_copy_view to root; 
    grant delete on arc_file_copy_view to root; 
    grant update on arc_file_copy_view to root; 
 
    create view arc_ae_view 
    as  
    select * from arc_archive_event 
        where ae_level in (0, 1, 2) 
    with check option; 
    revoke all on arc_ae_view from public; 
    grant select on arc_ae_view to root; 
    grant insert on arc_ae_view to root; 
    grant delete on arc_ae_view to root; 
    grant update on arc_ae_view to root; 
 
{ Physical device table } 
  
    create table arc_phys_dev 
        ( 
        dp_name         char(128)        primary key, 
        dp_path         char(260),       { size matches FNAMELENGTH } 
        dp_driver       char(5), 
        dp_block_sz     integer, 
        dp_max_space    integer 
        ); 
    revoke all on arc_phys_dev from public; 
    grant all on arc_phys_dev to root; 
    grant select on arc_phys_dev to public; 
 
{ arc_replicate : replicate definition table } 
create table arc_replicate ( 
rep_repid integer not null primary key, 
rep_name char(128) not null unique, 
rep_dxs char(255) not null, 
rep_db char(37) not null, 
rep_refresh char(1) not null, 
rep_extract char(1024) not null, 
rep_creation_date datetime year to second not null 
); 
 
{ arc_server : remote servers per replicate } 
create table arc_server ( 
as_server char(128) not null, 
as_db char(128) not null, 
as_repid integer not null references arc_replicate, 
primary key (as_server, as_db, as_repid) 
); 
 
 
 
{ arc_rep_archive : successful replicate extractions } 
create table arc_rep_archive ( 
ra_repid integer not null references arc_replicate, 
ra_rid integer not null references arc_request, 
ra_prior_rid integer not null, 
ra_refresh char (1) not null, 
primary key (ra_repid, ra_rid) 
); 
 
 
{ arc_rep_table : replicate distribution status } 
create table arc_rep_table ( 
rt_table char(128) not null, 
rt_db char(128) not null, 
rt_server char(128) not null, 
rt_last_rid integer not null, 
rt_active char(1) not null, 
rt_repid integer not null 
); 
 
 
{ arc_change_log : change log table mapping } 
{ 
create table arc_change_log ( 
cl_db char(128) not null, 
cl_server char(128) not null, 
cl_table char(128) not null, 
cl_change_log char(128) not null, 
primary key (cl_db, cl_server, cl_table, cl_change_log) 
); 
} 
 
 
{ arc_rep_parent : parent replication distribution } 
create table arc_rep_parent ( 
rp_repid integer not null, 
rp_rid integer not null, 
rp_parent_rid integer not null 
); 
 
 
{ Drop view arc_file_copy_view } 
drop view arc_file_copy_view; 
 
 
{ Modification of arc_file_copy table } 
alter table arc_file_copy 
add fc_device char(120); 
 
 
{ Recreate view arc_file_copy_view } 
create view arc_file_copy_view 
as  
select * from arc_file_copy where fc_fno = (select file_fno from arc_file 
    where file_rid = fc_rid and file_fno = fc_fno) 
          and fc_vno = (select vol_vno from arc_volume 
                where vol_vid = fc_vid 
                  and vol_vno = fc_vno) 
          and fc_last_sno in ('Y', 'N') 
    with check option; 
    revoke all on arc_file_copy_view from public; 
 
 
{ Create stored procedure start_onpload } 
create procedure informix.start_onpload(args char(200)) returning int; 
    define command char(255); -- build command string here 
    define rtnsql  int;       -- place holder for exception sqlcode setting 
    define rtnisam int;       -- isam error code. Should be onpload exit status  
 
   {If $INFORMIXDIR/bin/onpload not found try /usr/informix/bin/onpload} 
   { or NT style} 
    on exception in (-668) set rtnsql, rtnisam 
    if rtnisam = -2 then 
            { If onpload.exe not found by default UNIX style-environment} 
            let command = 'cmd /c %INFORMIXDIR%\bin\onpload ' || args; 
            system (command); 
            return 0; 
         end if 
         if rtnisam = -1 then 
            let command = '/usr/informix/bin/onpload ' || args; 
            system (command); 
            return 0; 
        end if 
        return rtnisam; 
    end exception 
 
    let command = '$INFORMIXDIR/bin/onpload ' || args; 
    system (command); 
    return 0; 
end procedure; 
 
grant execute on informix.start_onpload to public; 
 
{ Create UDR functions for memory resident tables } 
create DBA function informix.ifx_make_res(integer) 
returning integer 
external name '(ifx_res_pnum)' 
language c; 
 
create DBA function informix.ifx_make_unres(integer) 
returning integer 
external name '(ifx_unres_pnum)' 
language c; 
 
create DBA function informix.ifx_make_res(char(256)) 
returning integer 
external name '(ifx_res_name)' 
language c; 
 
create DBA function informix.ifx_make_unres(char(256)) 
returning integer 
external name '(ifx_unres_name)' 
language c; 
 
{ Create stored procedure dbexp used by IECC } 
create procedure informix.dbexp(args char(200)) returning int; 
    define command char(255); -- build command string here 
    define rtnsql  int;       -- place holder for exception sqlcode setting 
    define rtnisam int;       -- isam error code. Should be onpload exit status  
 
    on exception in (-668) set rtnsql, rtnisam 
        if rtnisam = -2 then 
    { If dbexport.exe not found by default NT style-environment } 
            let command = 'cmd /c %INFORMIXDIR%\bin\dbexport ' || args; 
        system (command); 
            return 0; 
        end if 
        return rtnisam; 
    end exception 
 
    let command = '$INFORMIXDIR/bin/dbexport ' || args; 
    system (command); 
    return 0; 
end procedure; 
 
grant execute on informix.dbexp to public; 
 
{ Create stored procedure dbimp used by IECC } 
create procedure informix.dbimp(args char(200)) returning int; 
    define command char(255); -- build command string here 
    define rtnsql  int;       -- place holder for exception sqlcode setting 
    define rtnisam int;       -- isam error code. Should be onpload exit status  
 
    on exception in (-668) set rtnsql, rtnisam 
        if rtnisam = -2 then 
    { If dbimport.exe not found by default UNIX style-environment} 
            let command = 'cmd /c %INFORMIXDIR%\bin\dbimport ' || args; 
        system (command); 
            return 0; 
        end if 
        return rtnisam; 
    end exception 
 
    let command = '$INFORMIXDIR/bin/dbimport ' || args; 
    system (command); 
    return 0; 
end procedure; 
 
grant execute on informix.dbimp to public; 
grant connect to public; 
update statistics; 
close database; 

发表评论