Index !!!!

  • Now Daily at morning 6:00 am the server (Database) does not have any transactions.. i mean its on IDLE state as there are no one to work with it.. and the people comes at 9:00am for work ..

    So before the team vcomes to work with it, My plan is to

    1) First Rebuild/Reorganise Index.. Query - alter index all on tablename rebuild

    2) Execute a Stored procedure

    USE [DBNAME]

    GO

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    ALTER PROC [dbo].[pr_truncateLog]

    AS BEGIN

    DECLARE @DBName sysname,

    @logName sysname

    -- Obtener nombre de base de datos

    SET @DBName = DB_NAME()

    BACKUP LOG @DBName WITH NO_LOG

    -- Obtener lista de archivos LOG

    DECLARE logCursor CURSOR FOR

    SELECT name

    FROM sysfiles

    WHERE groupid = 0

    -- Para cada archivo LOG, ejecutar DBCC SHRINKFILE

    OPEN logCursor

    FETCH NEXT FROM logCursor

    INTO @logName

    WHILE @@FETCH_STATUS = 0 BEGIN

    SELECT @logName = RTRIM(@logName)

    DBCC SHRINKFILE (@logName)

    FETCH NEXT FROM logCursor

    INTO @logName

    END

    CLOSE logCursor

    DEALLOCATE logCursor

    END

    3) Run EXEC sp_updatestats

    4) Server Restart

    Now is this correct or can anyone help me in step by step execution??????

    ************************************
    Every Dog has a Tail !!!!! :-D

  • Ow, ow, ow, ow...

    First you want to rebuild the indexes, then you want to break the log chain (no more point in time recovery), shrink the log file, ensuring that there will be slow downs and log fragmentation from the growths and restart the server ensuring that it'll be slow when the users start using it.

    Well, to be honest I could think of worse things to do, but it might take work. 😉

    For the log, please read through this - Managing Transaction Logs[/url]

    Why not to shrink a DB, see - http://sqlinthewild.co.za/index.php/2007/09/08/shrinking-databases/, much the same goes for the log

    Why restart daily? Some servers I work with haven't been restarted in months and there's seldom a need to restart SQL regularly, doing so means more work for the DB engine to repopulate all its caches.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Gila 🙁

    Can you write the steps here with example or query??? i am not able to understand it ckear as i am new in DB activites;-)

    ************************************
    Every Dog has a Tail !!!!! :-D

  • No I can't, because what you're suggesting is incredibly harmful.

    Read the article and blog post that I referenced. Especially read the article.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Why do u want to perform all the stuff at a shot??? How big your databases?

    Plan accrodingly to the size of the databases.

  • I want to perform this just as a Good Prectise..

    There are 20 Databases almost 10 GB each.. thats it 😉

    ************************************
    Every Dog has a Tail !!!!! :-D

  • Good practise, 2 of the points are BAD practise

    Rebuild/Reorg indexes - Do this yes

    Shrinking the files - Bad idea

    sp_updatestats - This is partily done in the Rebuild/Reorg

    Restarting the server - Bad idea, as Gail already mentions you flush all the cache data out and SQL will perform badly until the cache's have been rebuilt.

  • runal_jagtap (9/25/2012)


    I want to perform this just as a Good Prectise..

    But it's not good practice. Other than the index rebuild and maybe the stats update, the rest of the steps can be downright harmful and should not be done, much less on a regular basis.

    Please, please, please, go and read the article I linked.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • That Means the points mentioned 1, 2 & 3 should be done only???

    ************************************
    Every Dog has a Tail !!!!! :-D

  • No, only points 1 and 3

    Index and statistic maintenance should be done

  • Truncating the log = harmful

    Shrinking the log = harmful

    Restarting SQL = waste of time to harmful.

    You also probably don't want to just rebuild all indexes without consideration, and the sampled updates that sp_updatestats does is sometimes not good enough

    For the last time, please go and read the stuff I linked in my first reply.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Yes Gila, surely i will read that....:-)

    Actually on daily basis many SP get executed so thought of rebuilding the indexes as new records come in it all time...

    this was the processs which was set from first.. am i asked to chabge it or make it right.. so i asked how to move ahead :w00t: still confused how do i move then

    ************************************
    Every Dog has a Tail !!!!! :-D

  • Rebuilding is fine. It's the rest that is the problem. I assume you're not using SQL 2008 (despite posting in the SQL 2008 forums) if that code is already running.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Yes Gila, that code is executed by the developers on 2005... once they use to do it couple of months back..

    thats just a given to me so that to implement that in 2008.. well i am not sure about that code and all..

    But yes according to you, as of now, for the start i will surely only rebuild indexes ;):-)

    ************************************
    Every Dog has a Tail !!!!! :-D

  • Gila please verify below Steps...

    1) Rebuild Indexes.. (Does this is necessary to be done evry day?)

    2) Backup & Truncate log (Is this correct?)

    3) EXEC sp_updatestats (What abt this?) :w00t:

    ************************************
    Every Dog has a Tail !!!!! :-D

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic. Login to reply