Saturday, October 20, 2012

Monitor Sybase error log


 Monitor Sybase error log

#!/bin/sh
#set -x
##
## This scripts scans the errorlog for errors and notifies if
## problems are found.
##
##
## Usage: check_errorlog_and_notify <ASE Server Name>
##
##
##
VERSION="check_errorlog_and_notify Version 1.2"
## Input Parameters for script
SRVNAME=`echo $1 | tr '[a-z]' '[A-Z]'`
ENV_DIR="/sybase_sa"
ENVFILE="$ENV_DIR/.$SRVNAME.env"

##
## Check for correct number of parameters
if [ $# -lt 1 ]
then
    echo "Usage: $0 <SQL-Server Name> "
    exit 1
fi

EXECUTE_ENV()
{
 ##
 ## Check for existence of ASE file
 if [ ! -s $ENVFILE ]
 then
    echo "$ENVFILE files does not exist for ASE Server ($SRVNAME) .."
    echo "Script exiting ..."
    exit 1
 fi

 ##
 ## Source environment (ASE) file
 . $ENVFILE
}

SET_VARIABLES()
{
 ##
 ## Defining system variables
 SA_PW=`$GET_PW $SRVNAME`

 SEARCHFILE="$SRV_LOG/errorlog_$SRVNAME"
 NUMBERED_SEARCHFILE="$SYB_TMP/errorlog_$SRVNAME"

 STARTLINE_FILE="$SYB_BIN/STARTLINE_FILE"
 KEYWORD_FILE="$SYB_BIN/KEYWORDS"

 TEMP_MSGFILE="$SYB_TMP/check_msgfile.$SRVNAME"
 TEMP_MSGFILE1="$SYB_TMP/check_msgfile1.$SRVNAME"
 TEMP_MSGFILE2="$SYB_TMP/check_msgfile2.$SRVNAME"
 MSGFILE="$SYB_TMP/check_msgfile3.$SRVNAME"

 rm -f $NUMBERED_SEARCHFILE $TEMP_MSGFILE $TEMP_MSGFILE1 2>/dev/null
 rm -f $TEMP_MSGFILE2 $MSGFILE 2>/dev/null
}

FIND_COUNTER()
{
 ##
 ## start at this line in log file
 ##
 if [ -f "$STARTLINE_FILE" ]
 then
    STARTLINE=`cat $STARTLINE_FILE`
 else
    STARTLINE=0
 fi
}

CONTINUE_SEARCH()
{
 ##
 ## are there any lines past our start point ?
 ## if not, we are done
 ##
 if [ $STARTLINE -ge `cat $SEARCHFILE | wc -l` ]
 then
    exit 0
 fi
}

CREATE_NUMBER_FILE()
{
 ##
 ## start at starting line number
 ## put line numbers on errorlog for message output
 ##
 LINE_COUNTER=`expr $STARTLINE + 1`

 cat $SEARCHFILE | tail +$STARTLINE | while read SEARCHLINE
 do
   if [ $LINE_COUNTER -ge $STARTLINE ]
   then
      echo "$LINE_COUNTER  $SEARCHLINE" >> $NUMBERED_SEARCHFILE
   fi

   LINE_COUNTER=`expr $LINE_COUNTER + 1`
   echo $LINE_COUNTER > $STARTLINE_FILE
 done
}

KEYWORD_SEARCH()
{
 ##
 ## now get down to business....
 ## grep for errors. KEY_ERROR file has what we grep for and what we ignore
 ##
 cat $KEYWORD_FILE | tail +7 | while read LINE
 do
   KEY_ERROR=`echo $LINE | cut -d~ -f1`
   IGNORE=`echo $LINE | cut -d~ -f2`
   ROWS=`echo $LINE | cut -d~ -f3`
   NUM=`echo $LINE | cut -d~ -f4`

   if [ $NUM -ne 0 ]
   then
      grep -i "$KEY_ERROR" $NUMBERED_SEARCHFILE > $TEMP_MSGFILE2
      NEW_NUM=5
      LAST_NUM=`expr $NUM + 4`
      while [ $LAST_NUM -ge $NEW_NUM ]
      do
        NEW_ERROR=`echo $LINE | cut -d~ -f$NEW_NUM`
        grep -v "$NEW_ERROR" $TEMP_MSGFILE2 > $TEMP_MSGFILE1
        cp $TEMP_MSGFILE1 $TEMP_MSGFILE2
        NEW_NUM=`expr $NEW_NUM + 1`
      done

      if [ $ROWS -ne 0 ]
      then
         cat $TEMP_MSGFILE2 | nawk '{print $1}' | while read FILE_ROW
         do
           FILE_ROW=`expr $FILE_ROW - $STARTLINE`
           cat $NUMBERED_SEARCHFILE | tail +$FILE_ROW | head -$ROWS >> $TEMP_MSGFILE
         done
      else
         mv $TEMP_MSGFILE2 $TEMP_MSGFILE
      fi
   else
      if [ $ROWS -eq 0 ]
      then
         grep -i "$KEY_ERROR" $NUMBERED_SEARCHFILE > $TEMP_MSGFILE
      else
         grep -i "$KEY_ERROR" $NUMBERED_SEARCHFILE | nawk '{print $1}' | while read FILE_ROW
         do
           FILE_ROW=`expr $FILE_ROW - $STARTLINE`
           cat $NUMBERED_SEARCHFILE | tail +$FILE_ROW | head -$ROWS >> $TEMP_MSGFILE
         done
      fi
   fi

   if [ -s "$TEMP_MSGFILE" ]
   then
      rm -f $MSGFILE
      UNIX_SRVR=`grep -w $SRVNAME $SERVERS | grep -w sql | nawk '{print $4}' | head -1`

      if [ "$IGNORE" = "MAIL" ]
      then
         echo "Sql($SRVNAME):Unix($UNIX_SRVR)-MAILONLY: " > $MSGFILE
         cat $TEMP_MSGFILE >> $MSGFILE
      else
         echo "Sql($SRVNAME):Unix($UNIX_SRVR):" > $MSGFILE
         cat $TEMP_MSGFILE | while read LINE
         do
           echo $LINE | cut -d" " -f5- >> $MSGFILE
         done
      fi

      if [ -s "$MSGFILE" ]
      then
        MSGTEXT=`cat $MSGFILE | sed s/\'/\ /g`
        echo "################### `date` #################################"
        cat $MSGFILE
      fi

      MSGTEXT1=`echo $MSGTEXT | cut -c1-210`
      MSGTEXT="$MSGTEXT1 *END*"
      echo "***END***" >> $MSGFILE

      MSG_CNT1=`cat $MSGFILE | wc -c`
      MSG_CNT=`echo $MSG_CNT1`
      TEXT_CNT1=`echo $MSGTEXT | wc -c`
      TEXT_CNT=`echo $TEXT_CNT1`

      $SYB_BIN/send_messages $SRVNAME "$MSGFILE" "$MSGTEXT" BOTH ALL
   fi
   rm -f $TEMP_MSGFILE
 done
}

CLEANUP()
{
 ##
 ## Mom taught us to clean up after ourselves...
 ## remove our work files
 ##
 rm -f $MSGFILE $TEMP_MSGFILE $TEMP_MSGFILE1 $TEMP_MSGFILE2 $NUMBERED_SEARCHFILE 2>/dev/null
}

##
## MAIN SECTION
EXECUTE_ENV
SET_VARIABLES
FIND_COUNTER
CONTINUE_SEARCH
CREATE_NUMBER_FILE
KEYWORD_SEARCH
CLEANUP

exit

Sybase Monitor config file


 Monitor config file in Sybase

#!/bin/sh
#set -x
##
## This scripts initiates sp_monitorconfig for parameters that have gone over
##
##
## =================================================================
## Change History
##
## Date         Programmer      Revisions
## -----------------------------------------------------------------
## 03/11/2010   Bhupendra
##
## ==================================================================
##
##
VERSION="monitor_config.sp Version 1.0"
## Input Parameters for script
SRVNAME=`echo $1 | tr '[a-z]' '[A-Z]'`
ENV_DIR="/sybase_sa"
ENVFILE="$ENV_DIR/.$SRVNAME.env"

##
## Check for correct number of parameters
if [ $# -lt 1 ]
then
    echo "Usage: $0 <SQL-Server Name> "
    exit 1
fi

EXECUTE_ENV()
{
 ##
 ## Check for existence of ASE file
 if [ ! -s $ENVFILE ]
 then
    echo "$ENVFILE files does not exist for ASE Server ($SRVNAME) .."
    echo "Script exiting ..."
    exit 1
 fi

 ##
 ## Source environment (ASE) file
 . $ENVFILE
}

SET_VARIABLES()
{
 ##
 ## Defining system variables
 SA_PW=`$GET_PW $SRVNAME`
 DATE=`date +%Y%m%d`
 OUTFILE="$SYB_SRV/monitor_config.$SRVNAME.${DATE}"
 touch ${OUTFILE}
}
MONITOR_CONFIG()
{
$ISQL_CMD -Usa -S${SRVNAME}  -w132<< EOF  >> ${OUTFILE}
${SA_PW}
sp_monitorconfig "all"
go
EOF
}
CLEANUP()
{
find $SYB_SRV -mtime +21 -name "monitor_config.$(SRVNAME}*" -exec /bin/rm -f {} \;
}

##
## MAIN SECTION
EXECUTE_ENV
SET_VARIABLES
MONITOR_CONFIG
CLEANUP
exit

SPACE check of sybase directories


 
SPCAE check of sybase directories :

Note : you may need to change some prams as per your env


#!/bin/sh
##
## space_check
##
##      Usage: space_check server_name dir_name threshold
##             server_name - the name of the ASE server
##             dir_name - name of directory to check. ex. /sybase
##             threshold - a number that indicates the percent above which to
##                          notify you. ex. 75
##      example: space_check p4nmb /sybase_sa 85
##          When the /sybase_sa directory is more than 85% full, notification
##          will be sent.
##
## Version 1.0
##
## =================================================================
## Change History
##
## Date         Programmer      Revisions
## -----------------------------------------------------------------
## 21/1/2012 Bhupendra bagde
##
## ==================================================================
##
## Input Parameters for script
SRVNAME=`echo $1 | tr '[a-z]' '[A-Z]'`
DIR_NAME=$2
THRESHOLD=$3
ENV_DIR=/sybase_sa
ENVFILE="$ENV_DIR/.$SRVNAME.env"

##
## Check for correct number of parameters
if [ $# -lt 3 ]
then
    echo "Usage: $0 <SQL Srvr Name> <dir name> <threshold>"
    exit 1
fi

if [ ! -d $DIR_NAME ]
then
   echo "space_check.csh: ** ERROR ** $DIR_NAME is not a valid directory name"
   exit
fi

EXECUTE_ENV()
{
 ##
 ## Check for existence of ASE file
 if [ ! -s $ENVFILE ]
 then
    echo "$ENVFILE files does not exist for ASE Server ($SRVNAME) .."
    echo "Script exiting ..."
    exit 1
 fi

 ##
 ## Source environment (ASE) file
 . $ENVFILE
}

SET_VARIABLES()
{
 TMP_FILE=$SYB_TMP/TMP_FILE.$$
 LNEW=`date +%Y%m%d"-"%R`
 rm -f $TMP_FILE 2>/dev/null
}

CHECK_DISKSPACE()
{
 ##
 ## extract the directory space used and name.
 ##
 XDATA=`df -k $DIR_NAME | grep "$DIR_NAME" | awk '{line=$0;line=substr(line,index(line,"%")-3,50);print line;}'`
 DIRSIZE=`echo $XDATA | cut -d"%" -f1`
 DIRNAME=`echo $XDATA | cut -d"%" -f2`

 ##
 ## Check to see if current size exceeds threshold.
 ##
 if [ $DIRSIZE -gt $THRESHOLD ]
 then
    SERVER=`/usr/ucb/hostname | awk -F"." '{print $1}' | tr '[a-z]' '[A-Z]'`
    MESSAGE="** WARNING ** On server ($SERVER) directory $DIR_NAME has exceeded threshold of $THRESHOLD% it is at $DIRSIZE%."
    echo "** WARNING ** On server ($SERVER) directory $DIR_NAME has exceeded threshold of $THRESHOLD% it is at $DIRSIZE%." > $TMP_FILE
    $SYB_BIN/send_messages $SRVNAME "$TMP_FILE" "$MESSAGE" BOTH ALL
 fi
}

##
## MAIN SECTION
EXECUTE_ENV
SET_VARIABLES
CHECK_DISKSPACE

rm -f $TMP_FILE 2>/dev/null

exit

Rebuild Indexes on Sybase


Shell Script  to re-build indexes
Note You may need to chnage some params as per your env



#!/bin/ksh
##set -x
#
################################################################################
#
# This script takes sql scripts as input to run clustered index rebuilds on various tables. Note, it # DOES NOT reverse-engineer tables, it's hardcoded for the clustered indexes as they exist 
# today, with the assumption that they  will not change. It also does not necessarily do all
# indexes. It is driven by the sql scripts it takes as input, so they can have as many or as few    # tables/indexes as desired. The ultimate goal was to provide flexibility in scheduling, to          # spread the work over several days and/or weeks as needed.
#
################################################################################
#
#
######################################
## Set the Server and Database Name ##
######################################
ENV_DIR="/sybase_sa"
SERVER=`echo $1 | dd conv=ucase 2>/dev/null`
DATABASE=$2
INFILE=$3
ENVFILE="$ENV_DIR/.$SERVER.env"

##
## Check for correct number of parameters
##
if [ $# -lt 3 ]
then
    echo "Usage: $0 <ASE Server Name> <Database Name> <Input script name>"
    exit 1
fi

##
## Check for existance of ASE file
##
if [ ! -s $ENVFILE ]
then
        echo "$ENVFILE.env does not exist ..."
        echo "Script exiting ..."
        exit 1
fi

##
## Source environment (ASE) file
##
. $ENVFILE


#  SET ENVIRONMENT VARIABLES
#
VERSION="Version 1.0"
#SENDMESSAGE=1 #1=on 0=off
#SQLSWITCH=1 #1=on 0=off
#DELHIST=1 #1=on 0=off

SA_PW=`$GET_PW $SERVER`
LNEW=`date +%m""%d""%y"-"%I":"%M%p`
BINDIR="${SYB_SA}/index/bin"
OUTFILE="${SYB_SA}/index/logs/rebuild_clustered.${SERVER}.${DATABASE}.${INFILE}.out"
LOGFILE="${SYB_SA}/index/logs/rebuild_clustered.${SERVER}.${DATABASE}.${INFILE}.log"
echo " "> ${LOGFILE}

#
## MAIN PROCESSING
#

# run the index rebuild sql input file
$ISQL_CMD -Usa -S$SERVER -w132 -D${DATABASE} -i${BINDIR}/${INFILE} -o${OUTFILE}  -P${SA_PW}

#
## Check for Errors and notify if necessary
#

if [ ! -s ${OUTFILE} ]
then
  echo "${OUTFILE} does not exist" >> $LOGFILE
else
  ERR=`egrep "Error|Msg|FAILED CREATING|CT-LIBRARY" $OUTFILE | wc -l`
fi

echo "Check log file '${OUTFILE}' for more details." >>${LOGFILE}
egrep 'Error|Msg|FAILED CREATING|CT-LIBRARY' ${OUTFILE}  >>${LOGFILE}

if [ $ERR -ge 1  ]
   then
      MSGERR="CRITICAL ISSUE - Index rebuild failed for $SERVER, database $DATABASE , Check email or '${OUTFILE}' for more details"
      $SYB_BIN/send_messages $SERVER "$OUTFILE" "$MSGERR" BOTH ALL
    else
      MSGERR="Successful - Index rebuild for $SERVER, database $DATABASE, Check email or '${OUTFILE}' for more details"
      $SYB_BIN/send_messages $SERVER "$OUTFILE" "$MSGERR" MAIL ALL
fi

#
## Move output file to timestamped output file
#
mv ${OUTFILE} ${OUTFILE}.$LNEW

#remove old logs files that are older than 30 days
#
RUTHERE=`find $SYB_SA/index/logs -mtime +30 -name "${OUTFILE}*" | wc -l`
if [ ${RUTHERE} -ge 1 ]
then
  find $SYB_SA/index/logs -mtime +30 -name "${OUTFILE}*" -exec /bin/rm -fr {} \;
fi
exit

Sybase IQ Table load


LOAD TABLE lineitem
(
l_orderkey BINARY WITH NULL BYTE,l_partkey BINARY WITH NULL BYTE,
l_suppkey BINARY WITH NULL BYTE,l_linenumber BINARY WITH NULL BYTE,
l_quantity BINARY WITH NULL BYTE,l_extendedprice BINARY WITH NULL BYTE,
l_discount BINARY WITH NULL BYTE,l_tax BINARY WITH NULL BYTE,
l_returnflag BINARY WITH NULL BYTE,l_linestatus BINARY WITH NULL BYTE,
l_shipdate BINARY WITH NULL BYTE,l_commitdate BINARY WITH NULL BYTE,
l_receiptdate BINARY WITH NULL BYTE,l_shipinstruct BINARY WITH NULL BYTE,
l_shipmode BINARY WITH NULL BYTE,l_comment BINARY WITH NULL BYTE
)

FROM 'C:\\mydata\\lineitem_binary.inp'

FORMAT BINARY
STRIP OFF
QUOTES OFF
ESCAPES OFF
PREVIEW ON
BYTE ORDER HIGH;

COMMIT

Friday, October 19, 2012

Blocked Process

Dealing with the blocked process

Blocking
When a process acquiring a lock on a object for its transactions to complete and at the same time the other process wants to acquire a lock on the same object
on which the first process is having a lock then the second process needs to wait
until the first one releases its lock. So the second process will be blocked by the first process is called as blocking

*** How to identify the blocked process ?
  • select spid,cmd,status,blocked from master..sysprocess where blocked >0
  • sp_who “spid” → gives information about spid ,uname,cmd,status and kill that process

Identifying SQL text of a process
  • dbcc trace on (3604)
      • trace flags
        • 3604 → Displays output on the screen
        • 3605 → redirect the output to error log file

      • dbcc sqltext(spid) {spid →id which is being blocked }

      Multiple TEMP DBs


      Temp DB Creation
      The multiple tempdb feature provides users the ability to create temporary database which can be used for the creation of temporary objects
      • DBA's can bind any user login's as well as application to the temporary db
      • The concept of multiple tempdb's is introduced from the version 12.5.3 and from version 12.5.1 we can bind the users and application to user created temporary db

      Syntax : create temporary database dbname on devname=size
      Example : create temporary database tempdb on tempdeve= 50m

      1>sp_tempdb “add”, “tempdb”, “default”
      2>go

      • we need to add the tempdatabase to the default group
      • once the database has been created this database will be used as an additional temporary database
      • sp_tempdb 'show'

      Binding application to temporary db

      • create temporary database dbname on devname=size

      • 1>sp_tempdb 'bind','AP','applname','db_name','tempdb'
      • 2>go

      Binding user to the temporary db

      • create temporary database dbname on devname=size

      • 1>sp_tempdb 'bind','LG','sa','DB','tempdb'
      • 2>go

      UN-Binding Users/Application from user created database

      • 1>sp_tempdb 'unbind','AP','applname'
      • 2>go
      Dropping the temporary database

      • 1>drop db dbname
      • 2>go

       

      Maintenance Tasks – DBCC


      DBCC- Database Consistency Checker

      The DBCC is a set of utility command for checking of the logical abd physical consistency of a database.

      • User id's that have been granted the SA_ROLE or the DBO role are automatically granted permissions to use all the dbcc commands.
      • Before a database dump or a routine validation of a database use
              • dbcc checkstorage
              • dbcc checkverify


              Two major functions are :

              • Page linkage
                  • Commands to check the page linkage
                        • dbcc checktable
                        • dbcc checkdb
                        • dbcc checkcatalog

                        • Page Allocation
                            • Commands to check page allocation
                                  • dbcc tablealloc
                                  • dbc indexalloc
                                  • dbcc checkalloc

                                  *** Command that checks consistency of a entire database dbcc checkstorage

                                  DBCC Commands

                                  • dbcc checktable
                                  • dbcc checkdb
                                  • dbcc checkcatalog
                                  • dbcc tablealloc
                                  • dbc indexalloc
                                  • dbcc checkalloc
                                  • dbcc checkstorage
                                  • dbcc checkverify
                                  dbcc checktable
                                  • It Checks page linkage for a given data
                                  • It Checks indexes and data pages are correctly linked
                                  • It Checks indexes are in properly sorted order
                                  • It Checks for the consistency of indexes and data pages

                                  Syntax : dbcc checktable <table name>
                                  Example :

                                  If we want to checks to be done first we need to skip the non-clustered indexes
                                  Syntax : dbcc checktable <table name> skip_ncindex
                                  Example :

                                  To fix the errors and its default
                                  Syntax : dbcc checktable tablename with fix
                                  Example :

                                  This Generates the reports
                                  Syntax : dbcc checktable tablename with nofix
                                  Example :

                                  dbcc checkdb
                                  • If this command is issued internally it checks table
                                  • It checks all tables in a given database
                                  • If no database is specified the check is performed on the current database
                                  • To run this command db should be in “SINGLE USER MODE” I.e set db_option

                                  Syntax : dbcc checkdb <database name> {Default is with fix}
                                  Example : dbcc checkdb titles

                                  dbcc checkcatalog
                                  • Checks for the referential integrity between the system table in the database
                                  • Verifies that the table or view in the sysobjects tables has at-least one row in syscolumns tables
                                  • Verifies that the type in the syscolumns tables has a row in systypes table.
                                  • Checks that the last checkpoint in the syslogs table is valid
                                  • Checks the segments definition in syssegments table
                                  • Verifies that the procedure in the sysobjects table has atleast one row in sysprocedures table
                                  • Also checks sysdevices and sysusages table also I.e whether all the devices are there or not

                                  Syntax : dbcc checkcatalog <database name > {doesnt have options like nofix and skip nc_index}
                                  Example :




                                  dbcc tablealloc
                                  • Checks for datatypes and index pages
                                  • Checks whether the pages are properly allocated in the table and in the index of a particular table
                                  • Checks whether pages that are allocated are properly linked with each other
                                  • It ensures that no allocated page is linked with the page of that particular table
                                  Syntax : dbcc tablealloc(object_name | object_id | partition_id,
                                  [, {full | optimized | fast |null}
                                  [, fix | nofix]])

                                  Example : dbcc tablealloc (titles,optimized)

                                  optimized : Generates reports based on OAM Table
                                  full : Generates the full report
                                  null : By Default takes optimized
                                  fast : fast creates an exemption and like a reference pointer of next apge is there and the particular page doesn't exist
                                  {Combination of 8 pages is 1 extent}

                                  fix : If we give tablealloc for system tables by default it runs with the option and its
                                  default for them
                                  nofix : For user tables default is nofix

                                  ** sp_spaceused <table name> gives how much memory is used ,reserved , size of the index and no. of rows in a table

                                  dbc indexalloc
                                  • Checks for only index pages and remaining checks are same as table alloc
                                  • Options are same as tablealloc

                                  Syntax : dbcc indexalloc(object_name | object_id | partition_id, index_id
                                  [, {full | optimized | fast | null} [, fix | nofix]])

                                  Example :dbcc indexalloc (authors,full)

                                  *** sp_helpindex <object name> → gives the information for that particular table

                                  dbcc checkalloc
                                  When runs on a particular db it internally runs tablealloc on each and every table in that particular database .it database name is not mentioned it checks the present database and database should be in SINGLE USER MODE

                                  Syntax : dbcc checkalloc [(database_name [, fix | nofix] )]
                                  Example : dbcc checkalloc pubs2,fix



                                  For better performance
                                  • use dbcc checkalloc to locate error (but do not fix them)
                                  • use dbcc tablealloc as needed to fix errors
                                  • Default dbcc checkalloc is no fix ,to use it with fix option,the database must be in SINGEL USER MODE

                                  Dropping a Damaged Database
                                  • If a database has large enough number of inconsistencies the server may consider the database to be corrupt and mark it suspect
                                  • In this situation the database cannot be dropped with the drop database command
                                  • The database can be dropped only with dbcc dbrepair

                                  Syntax : dbcc dbrepair(database_name, dropdb)
                                  Example : dbcc dbrepair(database_name, dropdb)


                                  dbcc checkstorage
                                  • In order to run dbcc checkstorage we need to install dbcc database
                                  • It is special dbcc command that combines the functionality of tall the commands like
                                        • dbcc checktable
                                        • dbcc checkdb
                                        • dbcc checkalloc
                                        • dbcc indexalloc
                                        • dbcc tablealloc

                                        Syntax : dbcc checkstorage [(dbname)]
                                        Example : dbcc checkstorage pubs2

                                        • In checktable it only checks for datapages
                                        • checkdb → checks for dataapge
                                        • dbcc checkstorage just generates a report and doesn't fix the error
                                        • when dbcc checkstorage command is run on a db it puts that db in dbccdb and performs all other dbcc commands
                                        • The faults that encountered in dbcc checkstorage will be stored in dbcc_faults
                                        • whenever dbcc commands are run on user database first dbcc needs to installed and this database can be on production server/development

                                        Advantages
                                        • Doesn't lock tables or pages for extended period of time
                                        • Executes in parallel using multiple worker process
                                        • Logs integrity faults in a database instead of standard output
                                        • Scales nearly linearly as resources are added
                                        • dbcc checkstorage checks the entire database including unused pages
                                        • Stores checkstorage activity and results in dbccdb database
                                        • Check storage only detects the faults it will not repair we need to run appropriate dbcc command to repair the faults
                                        • workspace is special type of table pre-allocated for dbcc checkstorage
                                        • A scan work space which contains a row for each page of target database
                                        • A text namespace contains a row for each table in target database that contain a text or image column

                                        dbcc checkverify

                                        • dbcc checkverify reads faults recorded by check storage
                                        • Sybase recommends that to run a check verify as soon as possible after running check storage
                                        • dbcc checkverify locks against concurrent updates to reclassify soft faults corrupted
                                        • dbcc checkverify reads information in dba_operation and dba_operation_results
                                        • code 100011 → it is a HARD FAULT & TEXT POINTER FAULT can be resolved without recovering database or dropping the table
                                        • code 100016 → page allocated but not linked (depends upon page allocation or database allocation then we need to run a tablealloc or checkalloc)
                                        • code 100035 → Space bits mismatch (To fix this run dbcc checktable)

                                        Syntax : dbcc checkverify <dbname>
                                        or
                                        sp_dbcc_runcheck

                                        Example :


                                        The faults that are encountered in dbcc checkstorage are stored in dbcc_faults
                                        Two Types of Faults:
                                        • Soft Fault
                                        • Hard Fault

                                        Soft Fault :
                                        These are not persistent and can be rectified by running dbcc commands.

                                        • code 100020 → Check aborted
                                        • code 100025 → Row count Fault
                                        • code 100028 → Page allocation of current segment


                                        Soft faults are those faults whenever there is page linkage error for

                                        Example : If a page is pointing to the next page and that page doesn't exist such faults are
                                        called soft faults

                                        During the time of data modification are happening on the pages and at the same timethe dbcc checkstorage is done it reports for soft faults

                                        These soft faults may not be 100% faults reported .In order to verify whether these are the actual faults we need to run dbcc checkverify which verifies the soft faults reported by previous dbcc checkstorage and gives the actual report

                                        Hard Fault:
                                        These are persistent errors and by restarting also they will not get resolved
                                        • Only one way to resolve is recover the database from backup
                                        • Even after re-running the command to resolve soft faults and if they do not get resolved they are said to be hard faults
                                        • When ever dbcc checkstorage is run in SINGLE USER MODE. We can encounter less no of soft faults which leads to outage i.e. the downtime.


                                        Classifies the fault. Valid values are:

                                        0 – Soft fault, possibly transient

                                        1– Hard fault

                                        2 – Soft fault that proved to be transient

                                        3 – Soft fault upgraded to a hard fault

                                        5 – Repaired hard fault

                                        7 – Repaired upgraded hard fault

                                        9 – Hard fault not repairable

                                        11 – Soft fault upgraded to a hard fault and not repairable

                                        16 – Soft fault, object dropped (inaccessible)

                                        17 – Hard fault, object dropped (inaccessible)

                                        18 – Transient soft fault, object dropped (inaccessible)

                                        19 – Soft fault upgraded to a hard fault and object dropped (inaccessible)

                                        dbcc reports

                                        dbcc checktype generated four types of reports and are stored in dbccdb database

                                        1. sp_dbcc_summaryreport It gives the summary of the HARD Fault and SOFT Fault that are reported
                                        Example : sp_dbcc_summary_report [dbname,(,date)(,opname)]

                                        1. sp_dbcc_faultreport It displays detailed information for each fault report
                                        sp_dbcc_faultreport 'short'
                                        sp_dbcc_faultreport 'long' {sp_dbcc_summaryreport / sp_dbcc_configreport / sp_dbcc_statisticsreport}

                                        1. sp_dbcc_fullreport Displays configuration statistics and fault data for a given database or object

                                        1. sp_dbcc_differentialreport Displays comperative results of the dbcc_checkstorage operations that are completed for a specified dates

                                        Maintaining dbccdb
                                        sp_dbcc_deletedb It deltes all the information on the specified database from dbccdb

                                        sp_dbcc_deletehistory It deletes the results of dbcc checkstorage operations from dbccdb

                                        *** Difference between checkstorage and checkdb ?
                                        1. dbccdb must be installed to run checkstorage the results will be stored in the database.
                                        2. If we use checkdb it will lock the database while running checkdb
                                        3. If we use checkstorage we should install the dbccdb because it will copy the source database to dbcc

                                        *** How dbcc checkstorage works ?
                                        1. Initialization Verifies the configuration of the target database and availability of required resources
                                        2. Database Scan Reads the entire database as quickly as possibly ,performs some checks and writes a brief summary of every page to the workspace in dbccdb
                                        3. Remaining checks are performed entirely in dbccdb

                                        *** How do you know the size of dbccdb ?
                                        sp_plan_dbccdb<dbanme>
                                        If dbaname is not specified sp_plan_dbccdb makes recommendations for all databases in master sysdatabases
                                        dbcc errors To make scanning dbcc output easier use operating system scripts to scan the output to look for specific strings

                                        String to look for:

                                        Msg → All Error Msg start with Msg

                                        Error → This word is often found in error messages

                                        Severity → Error that have a severity greater than 16 are serious

                                        Error Messages between 2500 & 2599 with a severity level of 16 can be a corrupt object


                                        1- 16 → LOW
                                        16-20 → To be Done
                                        21- Last → Taken to Technical Support /Senior administrator