SQWareProduction:mssql:bin:sqwmsq RebuildIndexDatabase.ksh

From Wiki_dbSQWare
Jump to: navigation, search

Presentation

Script $gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh :


Rebuild indexes for all databases
version = 2000 -> Dbcc dbreindex (N'[$lvsqw_Owner].[$lvsqw_TableName]',,90)
version >= 2005 -> alter index all on [$lvsqw_Owner].[$lvsqw_TableName] Rebuild with (online = off)



Online help

The online help is available for most scripts with the -h option.
Ex: $gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -h
Content of this assistance :

Sourcing sqwmsq_Global.lib v2024.02 SQWareProduction for MsSql (dbSQWare) ... 

Usage: sqwmsq_RebuildIndexDatabase.ksh [-h] -I <FreeTdsAlias> -D <DatabaseName> [+ options]

DESCRIPTION
   sqwmsq_RebuildIndexDatabase.ksh Rebuild index of database
SUPPORT
   MsSql supported versions: 2000 <= v <= 2022

PARAMETERS
     -I   Instance      : Target instance (freeTds alias).
     -D   databasename  : Target database.
OPTIONS
     -h                 : Display the full usage.
     -s                 : Display samples of usage.
     -IT   listtables   : List of tables to run update statistics on (by default all).
     -ET   listtables   : Tables list to exclude.
     -IL   likeclause   : Like clause to generate tables list (example: 'tbl%').
     -EL   likeclause   : Like clause to exclude tables (example: 'notbl%').
     -WCT  whereclause  : Where clause to generate tables list.
     -FRT       code    : Force return code value on error.
     -AddMail   email   : Email address to add at 'pmexpdba@gmail.com'.
     -RebuildType  type : Type of rebuild, 'all' for table, 'index' for indexes (by default 'index').
     -MinRatioReb ratio : Min avg_fragmentation_in_percent before rebuild (by default 30 %).
     -MinRatioRgz ratio : Min avg_fragmentation_in_percent before reorganize (by default 10 %).
     -SizeMaxIndex Size : Take into account indexes <= $gvsqw_SizeMaxIndexRebuild Mb (by default, 50000 Mb).
     -SizeMinIndex Size : Take into account indexes >= $gvsqw_SizeMinIndexRebuild Mb (by default, 1 Mb).
     -SendReport        : Send execution log report.
     -SortInTempdb      : Rebuild with option sort_in_tempdb=on.
     -Online            : Rebuild with option online=on.
     -Force             : Force Rebuild offline if necessary when -Online.
     -NoMail            : Deactivate sendmail on error pmexpdba@gmail.com (by default, send on error).
     -Locale    locale  : Force Locale for help display (fr,en).
     -Flag     filename : Fichier a chercher.
     -Exec              : Execute commands (by default, display generated commands).

Nuvola apps information.png
Note:
To be sure the aid is accurate, refer directly to the online help script -h option.


Error management

Errors passing arguments

This type of message is generated:

Lack 'FreeTdsAlias' parameter, Usage: sqwmsq_RebuildIndexDatabase.ksh [-h] -I <FreeTdsAlias> -D <DatabaseName> [+ options]
For full help : sqwmsq_RebuildIndexDatabase.ksh -h

If you are connecting through a terminal, no mail will be sent and you will have more this kind of message:

Not sending mail because you are in connected mode !!!
Lack 'FreeTdsAlias' parameter

If you are not connected to a terminal, the error message appears and is sent by mail to the address contained in the variable $gvsqw_GlobalMail (See help customize this variable). The subject line will always start by "$gvsqw_MailMsg_mssql : " (See help customize this variable).

Nuvola apps information.png
Note:
Sending mail can be disabled by the option -NoMail for one execution.


Execution errors

Whether you are or not connected to a terminal, the error message appears and an email containing a summary of treatment errors is sent to the address contained in the variable $gvsqw_Mail_mssql (See help customize this variable). The subject line will always start by "$gvsqw_MailMsg_mssql : " (See help customize this variable).

Nuvola apps information.png
Note:
Sending mail can be disabled by the option -NoMail for one execution.


Usage examples

Sourcing sqwmsq_Global.lib v2024.02 SQWareProduction for MsSql (dbSQWare) ... 

#Standard help for script sqwmsq_RebuildIndexDatabase.ksh:


$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -h
#Display online help for this script

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -Locale en -h
#Display online help for this script with forcing of the 'en' locale (by default locale managed by $gvsqw_Locale)

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -s
#Display usage examples for this script

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName>
#Generate commands but don't execute them !

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -Exec
#Rebuild indexes of target database <DbName>

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -Force -Exec
#Force execution of generated commands

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -Online -Exec
#Reconstruit les indexes sans poser de verrous sur les tables 

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -SortInTempdb -Exec
#Rebuild indexes with use tempdb to store the intermediate sort results
#Reduces index rebuild time, but increases the amount of temporary space disk used

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -RebuildType <type> -Exec
#Exectue Rebuild of type 'all' for tables, 'index' for indexes (by default '$gvsqw_RebuildType')

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -MinRatioReb <ratio> -Exec
#Rebuild indexes when avg_fragmentation_in_percent is 30% (by default $gvsqw_MinRatioRgz %)

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -MinRatioRgz <ratio> -Exec
#Reorganize indexes when avg_fragmentation_in_percent is 10% (by default $gvsqw_MinRatioReb %)

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -SizeMinIndex 100 -SizeMaxIndex 1000 -Exec
#Take into account indexes with size between 100 and 1000 Mb

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -AddMail 'mymail1@mydomaine.com,mymail2@mydomaine.com' -Exec
#Add the mail list to the default address managed by the variable gvsqw_GlobalMail

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -SendReport -Exec
#Send the log by email at the end of the treatment even if there is no error

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -NoMail -Exec
#Disables sending an email on error to $gvsqw_GlobalMail (by default, send on error)

$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -FRT <NumericValue> -Exec
#Force return code to '<NumericValue>' on error (if no error, "exit 0!")
#You can also force return code of this script on all your
#environnement if you set the variable: $gvsqw_ForcedReturnCodeScript_sqwmsq_RebuildIndexDatabase=<NumericValue>
#in configuration file $gvsqw_MsqBin/../etc_cust/sqwmsq_GlobalVar.cfg

#Options to generate table list with filters (you can mix all off them):
$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -IT <listtbl> -Exec
#Generate table list with 'in list':
#=> and name in ('$ListInclude')
$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -ET <listtbl> -Exec
#Generate table list with 'not in list':
#=> and name not in ('$ListExclude')
$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -IL <likeclause> -Exec
#Generate table list with 'like':
#=> and name like '$LikeClause'
$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -EL <likeclause> -Exec
#Generate table list with 'not like':
#=> and name not like '$NotLikeClause'
$gvsqw_MsqBin/sqwmsq_RebuildIndexDatabase.ksh -I $Alias -D <DbName> -W <whereclause> -Exec
#Generate table list with 'where clause':
#=> and '$WhereClause'

Nuvola apps information.png
Note:
To be sure the examples are accurate, refer directly to the online help script -s option.