Showing posts with label indexes. Show all posts
Showing posts with label indexes. Show all posts

Monday, March 26, 2012

Rebuilding the system merge repl indexes

Hi,

We have a client that has a large (5Gb) database replicated to 13 subscribers, the publisher is Sql 2005, the subscribers are Sql Express. The publication has as few filtered articles too. I have found that after several months of continuous running Replication Monitor is taking a long time to report history on each subscriber.

Do people tend to rebuild the indexes on the system merge replication tables on production servers, or should the standard replication jobs take care of this?

Thanks for your help

Graham

1. What is the retention period?

2. Was the cleanup job run?

|||

The retention period is 14 days for all subscribers.

The Agent history clean uo: Distributor job (publisher and distributor are on the same box), was last run yesterday successfully.

The Distribution Clean up: Distributor job has never been run and it not enabled.

The Replication monitoring refresher for Distributor job has never been run and is not enabled.

|||

1. Did the replication Monitor running all the time (on the subscriber)?

2. If you stop and re-start to launch it, does it still take a long time to refresh "sync status"?

3. if the repl monitor still takes a long time to refresh the sync status, can you turn on the profiler to see which RPC call takes unexpected long execution time? (I suspect the SQL Agent job history continuous to grow)

This posting is provided "AS IS" with no warranties, and confers no rights

|||

Replication does not do any index rebuilding or any defragmentation. It may be a good idea to create a job that does this for you during off-peak hours.

You may also want to monitor what's going on in the background while you're refreshing, replmonitor does make use of temp tables as well and it may have some contention with existing replication metadata tables that we're trying to improve for the next release of Katmai.

|||

Things took at turn for the worse yesterday. I had to reinitialize one of the subscribers because for some reason the publisher had decided to delete its merge meta data (the thing that normally happens when the subscriber does not sync for more than the retention period) dispite it sync'ing the day before. When I did the reinit, it then told me the snapshot was obsolete and I had to re-generate it. When I re-generated the snapshot it failed with a timeout after being stuck at 48% for 30minutes. Then all my other subscribers failed because of the same reason - the snapshot was obsolete.

In the end I tore down replication and re-created the publication and added all the subscribers again (this took all day too).

Now replication monitor is a lot more responsive.

Thanks for everyones help.

Friday, March 23, 2012

Rebuilding Indexes While logshipping

We implemented logshipping on one of our database and the log is shipped via
wan to different destination.it works great but on weekends we do rebuild
indexes for that databases which generates huge log and it takes forever to
copy that log at least two days.is there a work around for it.
Thanks,
We had the same problem, so we stopped rebuilding index's until a solution
is found. It was more important to have disaster recovery than index's that
are not defragged.
Sorry cant help more.
regards
steve
"chinn" <chinn@.discussions.microsoft.com> wrote in message
news:DAF0B62E-AC27-4766-8366-371101325AD4@.microsoft.com...
> We implemented logshipping on one of our database and the log is shipped
> via
> wan to different destination.it works great but on weekends we do rebuild
> indexes for that databases which generates huge log and it takes forever
> to
> copy that log at least two days.is there a work around for it.
> Thanks,
|||place the DB in bulk logged mode during index maintenance. this will reduce
logging for index changs.
Greg Jackson
PDX, Oregon
|||Actually that does not help with log shipping. While it will reduce the
amount of data sent to the transaction log the backup itself will include
ALL the changes and will be just as large.
Andrew J. Kelly SQL MVP
"pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
news:%233o4dsUQGHA.5924@.TK2MSFTNGP09.phx.gbl...
> place the DB in bulk logged mode during index maintenance. this will
> reduce logging for index changs.
>
> Greg Jackson
> PDX, Oregon
>
|||I agree with Andrew because i tested it and it didn't make a difference.
"Andrew J. Kelly" wrote:

> Actually that does not help with log shipping. While it will reduce the
> amount of data sent to the transaction log the backup itself will include
> ALL the changes and will be just as large.
> --
> Andrew J. Kelly SQL MVP
>
> "pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
> news:%233o4dsUQGHA.5924@.TK2MSFTNGP09.phx.gbl...
>
>
|||One thing you should look at is only rebuild indexes that actually need it.
This KB should be helpful and there is a sample script in BooksOnLine under
DBCC SHOWCONTIG that will only reindex the indexes that are fragmented
beyond a certain point. This should cut down the amount that is being
logged dramatically.
http://www.microsoft.com/technet/pro.../ss2kidbp.mspx
Andrew J. Kelly SQL MVP
"chinn" <chinn@.discussions.microsoft.com> wrote in message
news:FF010CDA-3598-4607-8DE2-0BECECE5593D@.microsoft.com...[vbcol=seagreen]
>I agree with Andrew because i tested it and it didn't make a difference.
> "Andrew J. Kelly" wrote:
|||hmm...that's too bad.
How about:
1. disable Log Shipping
2. Perform Index Maintenance
3. ReSeed your Standby DB
4. Start logshipping back up
This is a pain, but MUCH better than NOT doing index maintenance...
GAJ

Rebuilding Indexes While logshipping

We implemented logshipping on one of our database and the log is shipped via
wan to different destination.it works great but on weekends we do rebuild
indexes for that databases which generates huge log and it takes forever to
copy that log at least two days.is there a work around for it.
Thanks,We had the same problem, so we stopped rebuilding index's until a solution
is found. It was more important to have disaster recovery than index's that
are not defragged.
Sorry cant help more.
regards
steve
"chinn" <chinn@.discussions.microsoft.com> wrote in message
news:DAF0B62E-AC27-4766-8366-371101325AD4@.microsoft.com...
> We implemented logshipping on one of our database and the log is shipped
> via
> wan to different destination.it works great but on weekends we do rebuild
> indexes for that databases which generates huge log and it takes forever
> to
> copy that log at least two days.is there a work around for it.
> Thanks,|||place the DB in bulk logged mode during index maintenance. this will reduce
logging for index changs.
Greg Jackson
PDX, Oregon|||Actually that does not help with log shipping. While it will reduce the
amount of data sent to the transaction log the backup itself will include
ALL the changes and will be just as large.
Andrew J. Kelly SQL MVP
"pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
news:%233o4dsUQGHA.5924@.TK2MSFTNGP09.phx.gbl...
> place the DB in bulk logged mode during index maintenance. this will
> reduce logging for index changs.
>
> Greg Jackson
> PDX, Oregon
>|||I agree with Andrew because i tested it and it didn't make a difference.
"Andrew J. Kelly" wrote:

> Actually that does not help with log shipping. While it will reduce the
> amount of data sent to the transaction log the backup itself will include
> ALL the changes and will be just as large.
> --
> Andrew J. Kelly SQL MVP
>
> "pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
> news:%233o4dsUQGHA.5924@.TK2MSFTNGP09.phx.gbl...
>
>|||One thing you should look at is only rebuild indexes that actually need it.
This KB should be helpful and there is a sample script in BooksOnLine under
DBCC SHOWCONTIG that will only reindex the indexes that are fragmented
beyond a certain point. This should cut down the amount that is being
logged dramatically.
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
Andrew J. Kelly SQL MVP
"chinn" <chinn@.discussions.microsoft.com> wrote in message
news:FF010CDA-3598-4607-8DE2-0BECECE5593D@.microsoft.com...[vbcol=seagreen]
>I agree with Andrew because i tested it and it didn't make a difference.
> "Andrew J. Kelly" wrote:
>|||hmm...that's too bad.
How about:
1. disable Log Shipping
2. Perform Index Maintenance
3. ReSeed your Standby DB
4. Start logshipping back up
This is a pain, but MUCH better than NOT doing index maintenance...
GAJsql

Rebuilding Indexes While logshipping

We implemented logshipping on one of our database and the log is shipped via
wan to different destination.it works great but on weekends we do rebuild
indexes for that databases which generates huge log and it takes forever to
copy that log at least two days.is there a work around for it.
Thanks,We had the same problem, so we stopped rebuilding index's until a solution
is found. It was more important to have disaster recovery than index's that
are not defragged.
Sorry cant help more.
regards
steve
"chinn" <chinn@.discussions.microsoft.com> wrote in message
news:DAF0B62E-AC27-4766-8366-371101325AD4@.microsoft.com...
> We implemented logshipping on one of our database and the log is shipped
> via
> wan to different destination.it works great but on weekends we do rebuild
> indexes for that databases which generates huge log and it takes forever
> to
> copy that log at least two days.is there a work around for it.
> Thanks,|||place the DB in bulk logged mode during index maintenance. this will reduce
logging for index changs.
Greg Jackson
PDX, Oregon|||Actually that does not help with log shipping. While it will reduce the
amount of data sent to the transaction log the backup itself will include
ALL the changes and will be just as large.
--
Andrew J. Kelly SQL MVP
"pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
news:%233o4dsUQGHA.5924@.TK2MSFTNGP09.phx.gbl...
> place the DB in bulk logged mode during index maintenance. this will
> reduce logging for index changs.
>
> Greg Jackson
> PDX, Oregon
>|||I agree with Andrew because i tested it and it didn't make a difference.
"Andrew J. Kelly" wrote:
> Actually that does not help with log shipping. While it will reduce the
> amount of data sent to the transaction log the backup itself will include
> ALL the changes and will be just as large.
> --
> Andrew J. Kelly SQL MVP
>
> "pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
> news:%233o4dsUQGHA.5924@.TK2MSFTNGP09.phx.gbl...
> > place the DB in bulk logged mode during index maintenance. this will
> > reduce logging for index changs.
> >
> >
> >
> > Greg Jackson
> > PDX, Oregon
> >
>
>|||One thing you should look at is only rebuild indexes that actually need it.
This KB should be helpful and there is a sample script in BooksOnLine under
DBCC SHOWCONTIG that will only reindex the indexes that are fragmented
beyond a certain point. This should cut down the amount that is being
logged dramatically.
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
Andrew J. Kelly SQL MVP
"chinn" <chinn@.discussions.microsoft.com> wrote in message
news:FF010CDA-3598-4607-8DE2-0BECECE5593D@.microsoft.com...
>I agree with Andrew because i tested it and it didn't make a difference.
> "Andrew J. Kelly" wrote:
>> Actually that does not help with log shipping. While it will reduce the
>> amount of data sent to the transaction log the backup itself will include
>> ALL the changes and will be just as large.
>> --
>> Andrew J. Kelly SQL MVP
>>
>> "pdxJaxon" <GregoryAJackson@.Hotmail.com> wrote in message
>> news:%233o4dsUQGHA.5924@.TK2MSFTNGP09.phx.gbl...
>> > place the DB in bulk logged mode during index maintenance. this will
>> > reduce logging for index changs.
>> >
>> >
>> >
>> > Greg Jackson
>> > PDX, Oregon
>> >
>>|||hmm...that's too bad.
How about:
1. disable Log Shipping
2. Perform Index Maintenance
3. ReSeed your Standby DB
4. Start logshipping back up
This is a pain, but MUCH better than NOT doing index maintenance...
GAJ

Rebuilding indexes nightly bad?

Hey all,
My company currently rebuilds the database indexes nightly.
We haven't really done an analysis on what fill factors might be good
for our indexes, and use a stock value of 95 when rebuilding.
Our application does majority of reads when using the database,
although there are also inserta and updates done here and there.
>From my understanding, an incorrect fill factor can contribute to page
splits, which is an I/O hit.
When the index is rebuilt, it adjusts the fill factor back to 95. So
thus, if it is not the best value, more page splits are likely and thus
I/O goes up. So over a period, say a week, would the amount of page
splitting decrease as the index creates new pages?
Would it be better to rebuild indexes say on a week? If not, is there a
way to determine when the ideal time frame to rebuild indexes is?
One last question - I assume a page split only occurs when inserting
into an index?
Thanks!Try this - the morning after you rebuild your indexes, cancel your
transaction log backups for a few hours and then run the following query
which will scan through your transaction logs and report on page splits -
select [Object Name], [Index Name], count([Current LSN])
from ::fn_dblog(null, null)
where Operation = N'LOP_DELETE_SPLIT'
group by [Object Name], [Index Name]
You can also run the following dbcc on Friday evenings (before the rebuild
indexes) to see how fragmented your tables and indexes are -
dbcc showcontig(tablename) with all_indexes
Be careful about running the dbcc as it may lock up user processes on the
server.
You shouldn't be rebuilding more than once a week - if you see excessive
fragmentation on Friday evening, change the fill factor with ALTER INDEX
Good luck!
"davconts@.gmail.com" wrote:
> Hey all,
> My company currently rebuilds the database indexes nightly.
> We haven't really done an analysis on what fill factors might be good
> for our indexes, and use a stock value of 95 when rebuilding.
> Our application does majority of reads when using the database,
> although there are also inserta and updates done here and there.
> >From my understanding, an incorrect fill factor can contribute to page
> splits, which is an I/O hit.
> When the index is rebuilt, it adjusts the fill factor back to 95. So
> thus, if it is not the best value, more page splits are likely and thus
> I/O goes up. So over a period, say a week, would the amount of page
> splitting decrease as the index creates new pages?
> Would it be better to rebuild indexes say on a week? If not, is there a
> way to determine when the ideal time frame to rebuild indexes is?
> One last question - I assume a page split only occurs when inserting
> into an index?
> Thanks!
>|||davconts@.gmail.com wrote:
> Hey all,
> My company currently rebuilds the database indexes nightly.
> We haven't really done an analysis on what fill factors might be good
> for our indexes, and use a stock value of 95 when rebuilding.
> Our application does majority of reads when using the database,
> although there are also inserta and updates done here and there.
>>From my understanding, an incorrect fill factor can contribute to page
> splits, which is an I/O hit.
> When the index is rebuilt, it adjusts the fill factor back to 95. So
> thus, if it is not the best value, more page splits are likely and thus
> I/O goes up. So over a period, say a week, would the amount of page
> splitting decrease as the index creates new pages?
> Would it be better to rebuild indexes say on a week? If not, is there a
> way to determine when the ideal time frame to rebuild indexes is?
> One last question - I assume a page split only occurs when inserting
> into an index?
> Thanks!
>
Consider rebuilding only those indexes that have become badly
fragmented. See
http://realsqlguy.com/twiki/bin/view/RealSQLGuy/DefragIndexesAsNeeded
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||Thanks Himanshu - I tried running that query but get:
Msg 207, Level 16, State 1, Line 4
Invalid column name 'Object Name'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'Index Name'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Object Name'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Index Name'.
Do I need to supply and particular details like the name of the
database/log?
I'm not that advanced with this type of SQL so sorry if this is a bit
of a stupid question :)
BTW I am using SQL 2005.
David
Himanshu wrote:
> Try this - the morning after you rebuild your indexes, cancel your
> transaction log backups for a few hours and then run the following query
> which will scan through your transaction logs and report on page splits -
> select [Object Name], [Index Name], count([Current LSN])
> from ::fn_dblog(null, null)
> where Operation = N'LOP_DELETE_SPLIT'
> group by [Object Name], [Index Name]
> You can also run the following dbcc on Friday evenings (before the rebuild
> indexes) to see how fragmented your tables and indexes are -
> dbcc showcontig(tablename) with all_indexes
> Be careful about running the dbcc as it may lock up user processes on the
> server.
> You shouldn't be rebuilding more than once a week - if you see excessive
> fragmentation on Friday evening, change the fill factor with ALTER INDEX
> Good luck!
>
>
> "davconts@.gmail.com" wrote:
> > Hey all,
> >
> > My company currently rebuilds the database indexes nightly.
> >
> > We haven't really done an analysis on what fill factors might be good
> > for our indexes, and use a stock value of 95 when rebuilding.
> >
> > Our application does majority of reads when using the database,
> > although there are also inserta and updates done here and there.
> >
> > >From my understanding, an incorrect fill factor can contribute to page
> > splits, which is an I/O hit.
> >
> > When the index is rebuilt, it adjusts the fill factor back to 95. So
> > thus, if it is not the best value, more page splits are likely and thus
> > I/O goes up. So over a period, say a week, would the amount of page
> > splitting decrease as the index creates new pages?
> >
> > Would it be better to rebuild indexes say on a week? If not, is there a
> > way to determine when the ideal time frame to rebuild indexes is?
> >
> > One last question - I assume a page split only occurs when inserting
> > into an index?
> >
> > Thanks!
> >
> >|||Hi Tracy,
Thanks, I have tried your stored procedure.
Tried it in report mode, using a MaxFragmentationPercent parameter of
30 - it came back with about 50 indexes that had % frag of around 70 -
80%.
I then tried defragging/rebuilding options, but they still seem to have
the same frag %.
Seems like the defrag/rebuilding isn't really helping here...is there a
reason for this? (noob question, still learning here)
Also, do you have a suggested MaxFragmentationPercent from your
experience?
Thanks
David
Tracy McKibben wrote:
> davconts@.gmail.com wrote:
> > Hey all,
> >
> > My company currently rebuilds the database indexes nightly.
> >
> > We haven't really done an analysis on what fill factors might be good
> > for our indexes, and use a stock value of 95 when rebuilding.
> >
> > Our application does majority of reads when using the database,
> > although there are also inserta and updates done here and there.
> >
> >>From my understanding, an incorrect fill factor can contribute to page
> > splits, which is an I/O hit.
> >
> > When the index is rebuilt, it adjusts the fill factor back to 95. So
> > thus, if it is not the best value, more page splits are likely and thus
> > I/O goes up. So over a period, say a week, would the amount of page
> > splitting decrease as the index creates new pages?
> >
> > Would it be better to rebuild indexes say on a week? If not, is there a
> > way to determine when the ideal time frame to rebuild indexes is?
> >
> > One last question - I assume a page split only occurs when inserting
> > into an index?
> >
> > Thanks!
> >
> Consider rebuilding only those indexes that have become badly
> fragmented. See
> http://realsqlguy.com/twiki/bin/view/RealSQLGuy/DefragIndexesAsNeeded
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com|||>My company currently rebuilds the database indexes nightly.
>although there are also inserta and updates done here and there.
The reason to rebuild indexes is that there has been significant
update activity. What you describe sounds like rather light update
activity. On that basis alone, daily rebuilding of indexes sounds
like absurd overkill.
If you are going beyond default fill factors, it only makes sense to
do it at the table and individual index level. In particular, the
clustered index on a table that is heavily updated needs careful
analysis. Cluster an invoice table on invoice_date and most inserts
will be at the end - new pages, but not page splits. Cluster a Orders
table on CusterID and inserts will tend to cluster on the most active
customers; free space and regular index rebuilds would be important.
Roy Harvey
Beacon Falls, CT|||David
Yes, that code will not work for SQL 2005. Metadata has been completely
reorganized.
Try this:
select AllocUnitName, count([Current LSN])
from ::fn_dblog(null, null)
where Operation = N'LOP_DELETE_SPLIT'
group by AllocUnitName
You need to be using the database that you are interested in.
--
HTH
Kalen Delaney, SQL Server MVP
<davconts@.gmail.com> wrote in message
news:1152756009.634285.195120@.35g2000cwc.googlegroups.com...
> Thanks Himanshu - I tried running that query but get:
> Msg 207, Level 16, State 1, Line 4
> Invalid column name 'Object Name'.
> Msg 207, Level 16, State 1, Line 4
> Invalid column name 'Index Name'.
> Msg 207, Level 16, State 1, Line 1
> Invalid column name 'Object Name'.
> Msg 207, Level 16, State 1, Line 1
> Invalid column name 'Index Name'.
> Do I need to supply and particular details like the name of the
> database/log?
> I'm not that advanced with this type of SQL so sorry if this is a bit
> of a stupid question :)
> BTW I am using SQL 2005.
> David
> Himanshu wrote:
>> Try this - the morning after you rebuild your indexes, cancel your
>> transaction log backups for a few hours and then run the following query
>> which will scan through your transaction logs and report on page splits -
>> select [Object Name], [Index Name], count([Current LSN])
>> from ::fn_dblog(null, null)
>> where Operation = N'LOP_DELETE_SPLIT'
>> group by [Object Name], [Index Name]
>> You can also run the following dbcc on Friday evenings (before the
>> rebuild
>> indexes) to see how fragmented your tables and indexes are -
>> dbcc showcontig(tablename) with all_indexes
>> Be careful about running the dbcc as it may lock up user processes on the
>> server.
>> You shouldn't be rebuilding more than once a week - if you see excessive
>> fragmentation on Friday evening, change the fill factor with ALTER INDEX
>> Good luck!
>>
>>
>> "davconts@.gmail.com" wrote:
>> > Hey all,
>> >
>> > My company currently rebuilds the database indexes nightly.
>> >
>> > We haven't really done an analysis on what fill factors might be good
>> > for our indexes, and use a stock value of 95 when rebuilding.
>> >
>> > Our application does majority of reads when using the database,
>> > although there are also inserta and updates done here and there.
>> >
>> > >From my understanding, an incorrect fill factor can contribute to page
>> > splits, which is an I/O hit.
>> >
>> > When the index is rebuilt, it adjusts the fill factor back to 95. So
>> > thus, if it is not the best value, more page splits are likely and thus
>> > I/O goes up. So over a period, say a week, would the amount of page
>> > splitting decrease as the index creates new pages?
>> >
>> > Would it be better to rebuild indexes say on a week? If not, is there a
>> > way to determine when the ideal time frame to rebuild indexes is?
>> >
>> > One last question - I assume a page split only occurs when inserting
>> > into an index?
>> >
>> > Thanks!
>> >
>> >
>|||This is Microsoft definitive whitepaper on the subject:
Microsoft SQL Server 2000 Index Defragmentation Best Practices
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
You need to make sure an index needs rebuilding before you rebuild it.
First, it has to be fragmented, and second, you have to verify that the
fragmentation is actually a problem. There are many cases where your
performance will not suffer just because indexes are fragmented. It's all in
the Whitepaper.
--
HTH
Kalen Delaney, SQL Server MVP
"Tracy McKibben" <tracy@.realsqlguy.com> wrote in message
news:uQ5p$phpGHA.4188@.TK2MSFTNGP04.phx.gbl...
> davconts@.gmail.com wrote:
>> Hey all,
>> My company currently rebuilds the database indexes nightly.
>> We haven't really done an analysis on what fill factors might be good
>> for our indexes, and use a stock value of 95 when rebuilding.
>> Our application does majority of reads when using the database,
>> although there are also inserta and updates done here and there.
>>From my understanding, an incorrect fill factor can contribute to page
>> splits, which is an I/O hit.
>> When the index is rebuilt, it adjusts the fill factor back to 95. So
>> thus, if it is not the best value, more page splits are likely and thus
>> I/O goes up. So over a period, say a week, would the amount of page
>> splitting decrease as the index creates new pages?
>> Would it be better to rebuild indexes say on a week? If not, is there a
>> way to determine when the ideal time frame to rebuild indexes is?
>> One last question - I assume a page split only occurs when inserting
>> into an index?
>> Thanks!
> Consider rebuilding only those indexes that have become badly fragmented.
> See http://realsqlguy.com/twiki/bin/view/RealSQLGuy/DefragIndexesAsNeeded
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com|||Great that worked... so I assume that the count returned is the number
of page splits?
(and this should be as close to 0 as possible?)
Would a high number indicate that the fill factor might need to be
adjusted?
Thanks!
Kalen Delaney wrote:
> David
> Yes, that code will not work for SQL 2005. Metadata has been completely
> reorganized.
> Try this:
> select AllocUnitName, count([Current LSN])
> from ::fn_dblog(null, null)
> where Operation = N'LOP_DELETE_SPLIT'
> group by AllocUnitName
> You need to be using the database that you are interested in.
> --
> HTH
> Kalen Delaney, SQL Server MVP
>
> <davconts@.gmail.com> wrote in message
> news:1152756009.634285.195120@.35g2000cwc.googlegroups.com...
> > Thanks Himanshu - I tried running that query but get:
> >
> > Msg 207, Level 16, State 1, Line 4
> > Invalid column name 'Object Name'.
> > Msg 207, Level 16, State 1, Line 4
> > Invalid column name 'Index Name'.
> > Msg 207, Level 16, State 1, Line 1
> > Invalid column name 'Object Name'.
> > Msg 207, Level 16, State 1, Line 1
> > Invalid column name 'Index Name'.
> >
> > Do I need to supply and particular details like the name of the
> > database/log?
> > I'm not that advanced with this type of SQL so sorry if this is a bit
> > of a stupid question :)
> >
> > BTW I am using SQL 2005.
> >
> > David
> >
> > Himanshu wrote:
> >> Try this - the morning after you rebuild your indexes, cancel your
> >> transaction log backups for a few hours and then run the following query
> >> which will scan through your transaction logs and report on page splits -
> >>
> >> select [Object Name], [Index Name], count([Current LSN])
> >> from ::fn_dblog(null, null)
> >> where Operation = N'LOP_DELETE_SPLIT'
> >> group by [Object Name], [Index Name]
> >>
> >> You can also run the following dbcc on Friday evenings (before the
> >> rebuild
> >> indexes) to see how fragmented your tables and indexes are -
> >>
> >> dbcc showcontig(tablename) with all_indexes
> >>
> >> Be careful about running the dbcc as it may lock up user processes on the
> >> server.
> >>
> >> You shouldn't be rebuilding more than once a week - if you see excessive
> >> fragmentation on Friday evening, change the fill factor with ALTER INDEX
> >>
> >> Good luck!
> >>
> >>
> >>
> >>
> >> "davconts@.gmail.com" wrote:
> >>
> >> > Hey all,
> >> >
> >> > My company currently rebuilds the database indexes nightly.
> >> >
> >> > We haven't really done an analysis on what fill factors might be good
> >> > for our indexes, and use a stock value of 95 when rebuilding.
> >> >
> >> > Our application does majority of reads when using the database,
> >> > although there are also inserta and updates done here and there.
> >> >
> >> > >From my understanding, an incorrect fill factor can contribute to page
> >> > splits, which is an I/O hit.
> >> >
> >> > When the index is rebuilt, it adjusts the fill factor back to 95. So
> >> > thus, if it is not the best value, more page splits are likely and thus
> >> > I/O goes up. So over a period, say a week, would the amount of page
> >> > splitting decrease as the index creates new pages?
> >> >
> >> > Would it be better to rebuild indexes say on a week? If not, is there a
> >> > way to determine when the ideal time frame to rebuild indexes is?
> >> >
> >> > One last question - I assume a page split only occurs when inserting
> >> > into an index?
> >> >
> >> > Thanks!
> >> >
> >> >
> >|||davconts@.gmail.com wrote:
> Hi Tracy,
> Thanks, I have tried your stored procedure.
> Tried it in report mode, using a MaxFragmentationPercent parameter of
> 30 - it came back with about 50 indexes that had % frag of around 70 -
> 80%.
> I then tried defragging/rebuilding options, but they still seem to have
> the same frag %.
> Seems like the defrag/rebuilding isn't really helping here...is there a
> reason for this? (noob question, still learning here)
They might be small indexes, in which case fragmentation really isn't
preventable, nor is it a problem. The rule of thumb is that any index
smaller than 1000 pages really doesn't suffer due to fragmentation. I
should make my routine smart enough to exclude those, but it's really a
non-issue either way.
> Also, do you have a suggested MaxFragmentationPercent from your
> experience?
I typically look for anything 30% or more.
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||I missed the start of this thread where I'm guessing the script got posted.
Is it looking at Extent Scan Fragmentation or is it based off my Example E
in DBCC SHOWCONTIG BOL? Usually when someone says that the frag% stayed the
same after a defrag/rebuild its because they're looking at Extent Scan
Fragmentation and they have multiple files - Extent Scan Fragmentation is
documented as not applicable when multiple files are invovled - I didn't
upgrade the algorithm when I rewrote DBCC SHOWCONTIG for SQL 2000.
Fragmentation % is a poor way to pick indexes to defrag, if that's all you
look at. Fragmentation is only going to affect range scan performance so you
need to identify those indexes that are used in queries that have range
scans. You should also correlate decreasing perf with increasing Logical
Scan Fragmentation before rebuilding indexes every night.
Have a look at the whitepaper below for more info:
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
And you probably want to start following my index fragmentation series on
the blog below.
Thanks
--
Paul Randal
Lead Program Manager, Microsoft SQL Server Storage Engine
http://blogs.msdn.com/sqlserverstorageengine/default.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tracy McKibben" <tracy@.realsqlguy.com> wrote in message
news:%23UeioknpGHA.3600@.TK2MSFTNGP04.phx.gbl...
> davconts@.gmail.com wrote:
>> Hi Tracy,
>> Thanks, I have tried your stored procedure.
>> Tried it in report mode, using a MaxFragmentationPercent parameter of
>> 30 - it came back with about 50 indexes that had % frag of around 70 -
>> 80%.
>> I then tried defragging/rebuilding options, but they still seem to have
>> the same frag %.
>> Seems like the defrag/rebuilding isn't really helping here...is there a
>> reason for this? (noob question, still learning here)
> They might be small indexes, in which case fragmentation really isn't
> preventable, nor is it a problem. The rule of thumb is that any index
> smaller than 1000 pages really doesn't suffer due to fragmentation. I
> should make my routine smart enough to exclude those, but it's really a
> non-issue either way.
>> Also, do you have a suggested MaxFragmentationPercent from your
>> experience?
> I typically look for anything 30% or more.
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com|||Paul S Randal [MS] wrote:
> I missed the start of this thread where I'm guessing the script got posted.
> Is it looking at Extent Scan Fragmentation or is it based off my Example E
> in DBCC SHOWCONTIG BOL? Usually when someone says that the frag% stayed the
> same after a defrag/rebuild its because they're looking at Extent Scan
> Fragmentation and they have multiple files - Extent Scan Fragmentation is
> documented as not applicable when multiple files are invovled - I didn't
> upgrade the algorithm when I rewrote DBCC SHOWCONTIG for SQL 2000.
> Fragmentation % is a poor way to pick indexes to defrag, if that's all you
> look at. Fragmentation is only going to affect range scan performance so you
> need to identify those indexes that are used in queries that have range
> scans. You should also correlate decreasing perf with increasing Logical
> Scan Fragmentation before rebuilding indexes every night.
> Have a look at the whitepaper below for more info:
> http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
> And you probably want to start following my index fragmentation series on
> the blog below.
> Thanks
>
Script is visible at
http://realsqlguy.com/twiki/bin/view/RealSQLGuy/DefragIndexesAsNeeded.
I'm looking at logical scan fragmentation. I'll read that whitepaper
and watch the blog, always room for improvement!
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||Cool - its based off my example (or is eerily close to it).
--
Paul Randal
Lead Program Manager, Microsoft SQL Server Storage Engine
http://blogs.msdn.com/sqlserverstorageengine/default.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tracy McKibben" <tracy@.realsqlguy.com> wrote in message
news:O0jdO8FqGHA.4996@.TK2MSFTNGP05.phx.gbl...
> Paul S Randal [MS] wrote:
>> I missed the start of this thread where I'm guessing the script got
>> posted. Is it looking at Extent Scan Fragmentation or is it based off my
>> Example E in DBCC SHOWCONTIG BOL? Usually when someone says that the
>> frag% stayed the same after a defrag/rebuild its because they're looking
>> at Extent Scan Fragmentation and they have multiple files - Extent Scan
>> Fragmentation is documented as not applicable when multiple files are
>> invovled - I didn't upgrade the algorithm when I rewrote DBCC SHOWCONTIG
>> for SQL 2000.
>> Fragmentation % is a poor way to pick indexes to defrag, if that's all
>> you look at. Fragmentation is only going to affect range scan performance
>> so you need to identify those indexes that are used in queries that have
>> range scans. You should also correlate decreasing perf with increasing
>> Logical Scan Fragmentation before rebuilding indexes every night.
>> Have a look at the whitepaper below for more info:
>> http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
>> And you probably want to start following my index fragmentation series on
>> the blog below.
>> Thanks
> Script is visible at
> http://realsqlguy.com/twiki/bin/view/RealSQLGuy/DefragIndexesAsNeeded. I'm
> looking at logical scan fragmentation. I'll read that whitepaper and
> watch the blog, always room for improvement!
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com|||Paul S Randal [MS] wrote:
> Cool - its based off my example (or is eerily close to it).
>
It might share some code here and there... :-)
Tracy McKibben
MCDBA
http://www.realsqlguy.com

Rebuilding indexes nightly bad?

Hey all,
My company currently rebuilds the database indexes nightly.
We haven't really done an analysis on what fill factors might be good
for our indexes, and use a stock value of 95 when rebuilding.
Our application does majority of reads when using the database,
although there are also inserta and updates done here and there.

>From my understanding, an incorrect fill factor can contribute to page
splits, which is an I/O hit.
When the index is rebuilt, it adjusts the fill factor back to 95. So
thus, if it is not the best value, more page splits are likely and thus
I/O goes up. So over a period, say a week, would the amount of page
splitting decrease as the index creates new pages?
Would it be better to rebuild indexes say on a week? If not, is there a
way to determine when the ideal time frame to rebuild indexes is?
One last question - I assume a page split only occurs when inserting
into an index?
Thanks!Try this - the morning after you rebuild your indexes, cancel your
transaction log backups for a few hours and then run the following query
which will scan through your transaction logs and report on page splits -
select [Object Name], [Index Name], count([Current LSN])
from ::fn_dblog(null, null)
where Operation = N'LOP_DELETE_SPLIT'
group by [Object Name], [Index Name]
You can also run the following dbcc on Friday evenings (before the rebuild
indexes) to see how fragmented your tables and indexes are -
dbcc showcontig(tablename) with all_indexes
Be careful about running the dbcc as it may lock up user processes on the
server.
You shouldn't be rebuilding more than once a week - if you see excessive
fragmentation on Friday evening, change the fill factor with ALTER INDEX
Good luck!
"davconts@.gmail.com" wrote:

> Hey all,
> My company currently rebuilds the database indexes nightly.
> We haven't really done an analysis on what fill factors might be good
> for our indexes, and use a stock value of 95 when rebuilding.
> Our application does majority of reads when using the database,
> although there are also inserta and updates done here and there.
>
> splits, which is an I/O hit.
> When the index is rebuilt, it adjusts the fill factor back to 95. So
> thus, if it is not the best value, more page splits are likely and thus
> I/O goes up. So over a period, say a week, would the amount of page
> splitting decrease as the index creates new pages?
> Would it be better to rebuild indexes say on a week? If not, is there a
> way to determine when the ideal time frame to rebuild indexes is?
> One last question - I assume a page split only occurs when inserting
> into an index?
> Thanks!
>|||davconts@.gmail.com wrote:
> Hey all,
> My company currently rebuilds the database indexes nightly.
> We haven't really done an analysis on what fill factors might be good
> for our indexes, and use a stock value of 95 when rebuilding.
> Our application does majority of reads when using the database,
> although there are also inserta and updates done here and there.
>
> splits, which is an I/O hit.
> When the index is rebuilt, it adjusts the fill factor back to 95. So
> thus, if it is not the best value, more page splits are likely and thus
> I/O goes up. So over a period, say a week, would the amount of page
> splitting decrease as the index creates new pages?
> Would it be better to rebuild indexes say on a week? If not, is there a
> way to determine when the ideal time frame to rebuild indexes is?
> One last question - I assume a page split only occurs when inserting
> into an index?
> Thanks!
>
Consider rebuilding only those indexes that have become badly
fragmented. See
http://realsqlguy.com/twiki/bin/vie...IndexesAsNeeded
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||Thanks Himanshu - I tried running that query but get:
Msg 207, Level 16, State 1, Line 4
Invalid column name 'Object Name'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'Index Name'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Object Name'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Index Name'.
Do I need to supply and particular details like the name of the
database/log?
I'm not that advanced with this type of SQL so sorry if this is a bit
of a stupid question
BTW I am using SQL 2005.
David
Himanshu wrote:[vbcol=seagreen]
> Try this - the morning after you rebuild your indexes, cancel your
> transaction log backups for a few hours and then run the following query
> which will scan through your transaction logs and report on page splits -
> select [Object Name], [Index Name], count([Current LSN])
> from ::fn_dblog(null, null)
> where Operation = N'LOP_DELETE_SPLIT'
> group by [Object Name], [Index Name]
> You can also run the following dbcc on Friday evenings (before the rebuild
> indexes) to see how fragmented your tables and indexes are -
> dbcc showcontig(tablename) with all_indexes
> Be careful about running the dbcc as it may lock up user processes on the
> server.
> You shouldn't be rebuilding more than once a week - if you see excessive
> fragmentation on Friday evening, change the fill factor with ALTER INDEX
> Good luck!
>
>
> "davconts@.gmail.com" wrote:
>|||>My company currently rebuilds the database indexes nightly.

>although there are also inserta and updates done here and there.
The reason to rebuild indexes is that there has been significant
update activity. What you describe sounds like rather light update
activity. On that basis alone, daily rebuilding of indexes sounds
like absurd overkill.
If you are going beyond default fill factors, it only makes sense to
do it at the table and individual index level. In particular, the
clustered index on a table that is heavily updated needs careful
analysis. Cluster an invoice table on invoice_date and most inserts
will be at the end - new pages, but not page splits. Cluster a Orders
table on CusterID and inserts will tend to cluster on the most active
customers; free space and regular index rebuilds would be important.
Roy Harvey
Beacon Falls, CT|||Hi Tracy,
Thanks, I have tried your stored procedure.
Tried it in report mode, using a MaxFragmentationPercent parameter of
30 - it came back with about 50 indexes that had % frag of around 70 -
80%.
I then tried defragging/rebuilding options, but they still seem to have
the same frag %.
Seems like the defrag/rebuilding isn't really helping here...is there a
reason for this? (noob question, still learning here)
Also, do you have a suggested MaxFragmentationPercent from your
experience?
Thanks
David
Tracy McKibben wrote:
> davconts@.gmail.com wrote:
> Consider rebuilding only those indexes that have become badly
> fragmented. See
> http://realsqlguy.com/twiki/bin/vie...IndexesAsNeeded
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com|||David
Yes, that code will not work for SQL 2005. Metadata has been completely
reorganized.
Try this:
select AllocUnitName, count([Current LSN])
from ::fn_dblog(null, null)
where Operation = N'LOP_DELETE_SPLIT'
group by AllocUnitName
You need to be using the database that you are interested in.
--
HTH
Kalen Delaney, SQL Server MVP
<davconts@.gmail.com> wrote in message
news:1152756009.634285.195120@.35g2000cwc.googlegroups.com...
> Thanks Himanshu - I tried running that query but get:
> Msg 207, Level 16, State 1, Line 4
> Invalid column name 'Object Name'.
> Msg 207, Level 16, State 1, Line 4
> Invalid column name 'Index Name'.
> Msg 207, Level 16, State 1, Line 1
> Invalid column name 'Object Name'.
> Msg 207, Level 16, State 1, Line 1
> Invalid column name 'Index Name'.
> Do I need to supply and particular details like the name of the
> database/log?
> I'm not that advanced with this type of SQL so sorry if this is a bit
> of a stupid question
> BTW I am using SQL 2005.
> David
> Himanshu wrote:
>|||This is Microsoft definitive whitepaper on the subject:
Microsoft SQL Server 2000 Index Defragmentation Best Practices
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
You need to make sure an index needs rebuilding before you rebuild it.
First, it has to be fragmented, and second, you have to verify that the
fragmentation is actually a problem. There are many cases where your
performance will not suffer just because indexes are fragmented. It's all in
the Whitepaper.
HTH
Kalen Delaney, SQL Server MVP
"Tracy McKibben" <tracy@.realsqlguy.com> wrote in message
news:uQ5p$phpGHA.4188@.TK2MSFTNGP04.phx.gbl...
> davconts@.gmail.com wrote:
> Consider rebuilding only those indexes that have become badly fragmented.
> See http://realsqlguy.com/twiki/bin/vie...IndexesAsNeeded
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com|||Great that worked... so I assume that the count returned is the number
of page splits?
(and this should be as close to 0 as possible?)
Would a high number indicate that the fill factor might need to be
adjusted?
Thanks!
Kalen Delaney wrote:[vbcol=seagreen]
> David
> Yes, that code will not work for SQL 2005. Metadata has been completely
> reorganized.
> Try this:
> select AllocUnitName, count([Current LSN])
> from ::fn_dblog(null, null)
> where Operation = N'LOP_DELETE_SPLIT'
> group by AllocUnitName
> You need to be using the database that you are interested in.
> --
> HTH
> Kalen Delaney, SQL Server MVP
>
> <davconts@.gmail.com> wrote in message
> news:1152756009.634285.195120@.35g2000cwc.googlegroups.com...|||davconts@.gmail.com wrote:
> Hi Tracy,
> Thanks, I have tried your stored procedure.
> Tried it in report mode, using a MaxFragmentationPercent parameter of
> 30 - it came back with about 50 indexes that had % frag of around 70 -
> 80%.
> I then tried defragging/rebuilding options, but they still seem to have
> the same frag %.
> Seems like the defrag/rebuilding isn't really helping here...is there a
> reason for this? (noob question, still learning here)
They might be small indexes, in which case fragmentation really isn't
preventable, nor is it a problem. The rule of thumb is that any index
smaller than 1000 pages really doesn't suffer due to fragmentation. I
should make my routine smart enough to exclude those, but it's really a
non-issue either way.

> Also, do you have a suggested MaxFragmentationPercent from your
> experience?
I typically look for anything 30% or more.
Tracy McKibben
MCDBA
http://www.realsqlguy.com

Rebuilding indexes in SQL 2000

All
Is there any way to estimate how long it would take to drop and rebuild the
indexes on a database. I have a farily tight maintenance window on a payroll
database and need to be sure that any work would be completed in time. I
assume the database size and amount of tables has a major bearing but not
sure where I would go from that info.
Thanks
Si
Simon
You can determine what tables are heavely defragmented and run rebuilt
index only on them
"Simon" <Simon@.discussions.microsoft.com> wrote in message
news:5D6C2F49-E817-4E24-893A-B108549F5331@.microsoft.com...
> All
> Is there any way to estimate how long it would take to drop and rebuild
> the
> indexes on a database. I have a farily tight maintenance window on a
> payroll
> database and need to be sure that any work would be completed in time. I
> assume the database size and amount of tables has a major bearing but not
> sure where I would go from that info.
> Thanks
> Si
|||On Feb 27, 9:37 am, Simon <S...@.discussions.microsoft.com> wrote:
> All
> Is there any way to estimate how long it would take to drop and rebuild the
> indexes on a database. I have a farily tight maintenance window on a payroll
> database and need to be sure that any work would be completed in time. I
> assume the database size and amount of tables has a major bearing but not
> sure where I would go from that info.
> Thanks
> Si
Rather than rebuild ALL of the indexes, consider rebuilding only those
that are badly fragmented. Rebuilding all of them is usually
unnecessary. Here's a script that might help you:
http://realsqlguy.blogspot.com/2007/02/smart-index-defragmentation.html
|||Simon,
there are too many variables in your case for an estimation from someone
external to work.
You could generate your own decent estimate if you restore a recent backup
onto a test server of similar specs and run the rebuild there.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
|||The problem I have is the database has around 600 tables, of which 350 need
rebuilding. There is also a high level of fragmentation so I thought that
Reindexing would be quicker.
"Tracy McKibben" wrote:

> On Feb 27, 9:37 am, Simon <S...@.discussions.microsoft.com> wrote:
> Rather than rebuild ALL of the indexes, consider rebuilding only those
> that are badly fragmented. Rebuilding all of them is usually
> unnecessary. Here's a script that might help you:
> http://realsqlguy.blogspot.com/2007/02/smart-index-defragmentation.html
>

Rebuilding indexes in SQL 2000

All
Is there any way to estimate how long it would take to drop and rebuild the
indexes on a database. I have a farily tight maintenance window on a payroll
database and need to be sure that any work would be completed in time. I
assume the database size and amount of tables has a major bearing but not
sure where I would go from that info.
Thanks
SiSimon
You can determine what tables are heavely defragmented and run rebuilt
index only on them
"Simon" <Simon@.discussions.microsoft.com> wrote in message
news:5D6C2F49-E817-4E24-893A-B108549F5331@.microsoft.com...
> All
> Is there any way to estimate how long it would take to drop and rebuild
> the
> indexes on a database. I have a farily tight maintenance window on a
> payroll
> database and need to be sure that any work would be completed in time. I
> assume the database size and amount of tables has a major bearing but not
> sure where I would go from that info.
> Thanks
> Si|||On Feb 27, 9:37 am, Simon <S...@.discussions.microsoft.com> wrote:
> All
> Is there any way to estimate how long it would take to drop and rebuild th
e
> indexes on a database. I have a farily tight maintenance window on a payro
ll
> database and need to be sure that any work would be completed in time. I
> assume the database size and amount of tables has a major bearing but not
> sure where I would go from that info.
> Thanks
> Si
Rather than rebuild ALL of the indexes, consider rebuilding only those
that are badly fragmented. Rebuilding all of them is usually
unnecessary. Here's a script that might help you:
http://realsqlguy.blogspot.com/2007...gmentation.html|||Simon,
there are too many variables in your case for an estimation from someone
external to work.
You could generate your own decent estimate if you restore a recent backup
onto a test server of similar specs and run the rebuild there.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com|||The problem I have is the database has around 600 tables, of which 350 need
rebuilding. There is also a high level of fragmentation so I thought that
Reindexing would be quicker.
"Tracy McKibben" wrote:

> On Feb 27, 9:37 am, Simon <S...@.discussions.microsoft.com> wrote:
> Rather than rebuild ALL of the indexes, consider rebuilding only those
> that are badly fragmented. Rebuilding all of them is usually
> unnecessary. Here's a script that might help you:
> http://realsqlguy.blogspot.com/2007...gmentation.html
>sql

Rebuilding indexes in SQL 2000

All
Is there any way to estimate how long it would take to drop and rebuild the
indexes on a database. I have a farily tight maintenance window on a payroll
database and need to be sure that any work would be completed in time. I
assume the database size and amount of tables has a major bearing but not
sure where I would go from that info.
Thanks
SiSimon
You can determine what tables are heavely defragmented and run rebuilt
index only on them
"Simon" <Simon@.discussions.microsoft.com> wrote in message
news:5D6C2F49-E817-4E24-893A-B108549F5331@.microsoft.com...
> All
> Is there any way to estimate how long it would take to drop and rebuild
> the
> indexes on a database. I have a farily tight maintenance window on a
> payroll
> database and need to be sure that any work would be completed in time. I
> assume the database size and amount of tables has a major bearing but not
> sure where I would go from that info.
> Thanks
> Si|||On Feb 27, 9:37 am, Simon <S...@.discussions.microsoft.com> wrote:
> All
> Is there any way to estimate how long it would take to drop and rebuild the
> indexes on a database. I have a farily tight maintenance window on a payroll
> database and need to be sure that any work would be completed in time. I
> assume the database size and amount of tables has a major bearing but not
> sure where I would go from that info.
> Thanks
> Si
Rather than rebuild ALL of the indexes, consider rebuilding only those
that are badly fragmented. Rebuilding all of them is usually
unnecessary. Here's a script that might help you:
http://realsqlguy.blogspot.com/2007/02/smart-index-defragmentation.html|||Simon,
there are too many variables in your case for an estimation from someone
external to work.
You could generate your own decent estimate if you restore a recent backup
onto a test server of similar specs and run the rebuild there.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com|||The problem I have is the database has around 600 tables, of which 350 need
rebuilding. There is also a high level of fragmentation so I thought that
Reindexing would be quicker.
"Tracy McKibben" wrote:
> On Feb 27, 9:37 am, Simon <S...@.discussions.microsoft.com> wrote:
> > All
> >
> > Is there any way to estimate how long it would take to drop and rebuild the
> > indexes on a database. I have a farily tight maintenance window on a payroll
> > database and need to be sure that any work would be completed in time. I
> > assume the database size and amount of tables has a major bearing but not
> > sure where I would go from that info.
> >
> > Thanks
> >
> > Si
> Rather than rebuild ALL of the indexes, consider rebuilding only those
> that are badly fragmented. Rebuilding all of them is usually
> unnecessary. Here's a script that might help you:
> http://realsqlguy.blogspot.com/2007/02/smart-index-defragmentation.html
>

Rebuilding Indexes and Updating Statistics

I believe that when you use DBCCReindex the statistics are updated for each
table, but can anyone tell me if it does a fullscan update or a partial scan
update when using DBCCReindex?
The entire index is rebuild, so all values are touched and collected. A
partial scan would not make sense.
Gert-Jan
Rick wrote:
> I believe that when you use DBCCReindex the statistics are updated for each
> table, but can anyone tell me if it does a fullscan update or a partial scan
> update when using DBCCReindex?
|||Gert-Jan,
I have been there, done that and I disagree with you.
Rick,
If you want to get your performance back after rebuilding indexes you MUST
run update stats with a FULL SCAN because when you rebuild indexes or run
update stats statements the selectivity level by default is 10% that mean the
server scans only 10% and does not touch 90%.
DO that full scan, have your performance BACK, save some money for your
company and pray for me.
v/r
ktf
"Gert-Jan Strik" wrote:

> The entire index is rebuild, so all values are touched and collected. A
> partial scan would not make sense.
> Gert-Jan
>
> Rick wrote:
>

Rebuilding Indexes and Updating Statistics

I believe that when you use DBCCReindex the statistics are updated for each
table, but can anyone tell me if it does a fullscan update or a partial scan
update when using DBCCReindex?The entire index is rebuild, so all values are touched and collected. A
partial scan would not make sense.
Gert-Jan
Rick wrote:
> I believe that when you use DBCCReindex the statistics are updated for each
> table, but can anyone tell me if it does a fullscan update or a partial scan
> update when using DBCCReindex?|||Gert-Jan,
I have been there, done that and I disagree with you.
Rick,
If you want to get your performance back after rebuilding indexes you MUST
run update stats with a FULL SCAN because when you rebuild indexes or run
update stats statements the selectivity level by default is 10% that mean the
server scans only 10% and does not touch 90%.
DO that full scan, have your performance BACK, save some money for your
company and pray for me.
v/r
ktf
"Gert-Jan Strik" wrote:
> The entire index is rebuild, so all values are touched and collected. A
> partial scan would not make sense.
> Gert-Jan
>
> Rick wrote:
> >
> > I believe that when you use DBCCReindex the statistics are updated for each
> > table, but can anyone tell me if it does a fullscan update or a partial scan
> > update when using DBCCReindex?
>|||ktf,
I have to disagree.
I could not believe your statement, so I tested it, as below.
-- drop table Test
create table Test(id int not null,id2 int not null)
create index CLIX_Test on Test(id)
create nonclustered index NCIX_Test on Test(id2)
insert into Test
select id,(id/2)+((id%2)*1000000000)
from sysobjects
insert into Test values (3,3)
declare @.i int
set @.i=250
while @.i>0
begin
insert into Test
select id+@.i,((id+@.i)/2)+(((id+@.i)%2)*1000000000)
from sysobjects
set @.i=@.i-1
end
go
dbcc show_statistics ("Test",CLIX_Test)
-- nothing
update statistics Test (CLIX_Test) with sample 10 percent
dbcc show_statistics ("Test",CLIX_Test)
-- low number in the "Rows Sampled" column
dbcc dbreindex("Test",CLIX_Test)
dbcc show_statistics ("Test",CLIX_Test)
-- high number in the "Rows Sampled" column
update statistics Test (CLIX_Test) with fullscan
dbcc show_statistics ("Test",CLIX_Test)
-- same number in the "Rows Sampled" column
Now the only thing I could not really explain is some (minor?)
inconsistency in the results after reindexing and after updating the
statistics with fullscan. The Rows Sampled would always be the same, but
sometimes the number of steps in the histogram would differ, causing
different results. I have only seen these differences a few times.
All of the times, both the Rows Sampled and the actual statistics
distribution would be different between the 10% sample and the
reindex/fullscan. There is no doubt about it that reindexing will not
(as a rule) sample just 10 percent of all rows, it is definitely
scanning all rows. I still have no reason to assume that a reindex would
not sample all rows for statistics purposes.
Gert-Jan
ktf wrote:
> Gert-Jan,
> I have been there, done that and I disagree with you.
> Rick,
> If you want to get your performance back after rebuilding indexes you MUST
> run update stats with a FULL SCAN because when you rebuild indexes or run
> update stats statements the selectivity level by default is 10% that mean the
> server scans only 10% and does not touch 90%.
> DO that full scan, have your performance BACK, save some money for your
> company and pray for me.
> v/r
> ktf
> "Gert-Jan Strik" wrote:
> > The entire index is rebuild, so all values are touched and collected. A
> > partial scan would not make sense.
> >
> > Gert-Jan
> >
> >
> > Rick wrote:
> > >
> > > I believe that when you use DBCCReindex the statistics are updated for each
> > > table, but can anyone tell me if it does a fullscan update or a partial scan
> > > update when using DBCCReindex?
> >

Rebuilding Indexes and Updating Statistics

I believe that when you use DBCCReindex the statistics are updated for each
table, but can anyone tell me if it does a fullscan update or a partial scan
update when using DBCCReindex?The entire index is rebuild, so all values are touched and collected. A
partial scan would not make sense.
Gert-Jan
Rick wrote:
> I believe that when you use DBCCReindex the statistics are updated for eac
h
> table, but can anyone tell me if it does a fullscan update or a partial sc
an
> update when using DBCCReindex?|||Gert-Jan,
I have been there, done that and I disagree with you.
Rick,
If you want to get your performance back after rebuilding indexes you MUST
run update stats with a FULL SCAN because when you rebuild indexes or run
update stats statements the selectivity level by default is 10% that mean th
e
server scans only 10% and does not touch 90%.
DO that full scan, have your performance BACK, save some money for your
company and pray for me.
v/r
ktf
"Gert-Jan Strik" wrote:

> The entire index is rebuild, so all values are touched and collected. A
> partial scan would not make sense.
> Gert-Jan
>
> Rick wrote:
>

Rebuilding Indexes and Shrinking Databases

Is there a best practice for the time of day to rebuild indexes and shrink
databases? i.e. not in the middle of the day
What performance hit would it have performing them actions on a 20Gb
Database have on disk I/O, Processor, etc.?
Thanks
Tim
Yes it is a good practice to rebuild indexes but when it depends on your
data load. We do it a twice a week.
Don't shrink database because it causes a fragmentation to be created of
the data pages. How do you increase a size of the database?
"Tim Earnshaw" <TimEarnshaw@.discussions.microsoft.com> wrote in message
news:1EBF5F1D-C20C-4969-A5AF-2A52E784A0F5@.microsoft.com...
> Is there a best practice for the time of day to rebuild indexes and shrink
> databases? i.e. not in the middle of the day
> What performance hit would it have performing them actions on a 20Gb
> Database have on disk I/O, Processor, etc.?
> Thanks
|||Tim,
Depends on what maintenance windows you have - do it then. I usually
rebuild indexes weekly and never, ever, ever shrink databases unless
there's an emergency (run out of disk space).
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html
Tim Earnshaw wrote:
> Is there a best practice for the time of day to rebuild indexes and shrink
> databases? i.e. not in the middle of the day
> What performance hit would it have performing them actions on a 20Gb
> Database have on disk I/O, Processor, etc.?
> Thanks
|||Thanks for the replies
The reason I ask is someone where I work was shrinking and rebuilding
indexes at 2pm and they said that its industry / microsoft standard to
rebuild indexes whenever needed. I didn't believe them and thought that I
would ask on here.
"Mark Allison" wrote:

> Tim,
> Depends on what maintenance windows you have - do it then. I usually
> rebuild indexes weekly and never, ever, ever shrink databases unless
> there's an emergency (run out of disk space).
> --
> Mark Allison, SQL Server MVP
> http://www.markallison.co.uk
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602m.html
>
> Tim Earnshaw wrote:
>
|||Hello Tim,
It is wrong to rebuild Indexes just because there is a command "DBCC Rebuild
... " - Atleast not everyday !!.
We used to load the contracts data into the Reinsurance Accounting DB on a
daily basis. Before the load, we used
to drop the Indexes and recreate them after loading the data. This process
used to take care of Rebuilding the Indexes
However, for the transaction accounting tables (contract tables in the
Reinsurance Accounting becomes Read Only ),
I used to manually drop them recreate them on a weekly basis. Manually
because the "Rebuild Index" process fills
the transaction log pretty fast if the table is huge. The application/DB was
a 24/7 application and one hour (6:30 PM EST)
was allocated for all sort of maintenance.
Hope this helps.
Gopi
"Tim Earnshaw" <TimEarnshaw@.discussions.microsoft.com> wrote in message
news:F97F5310-D81B-4995-A7B6-C7DEA329DBFD@.microsoft.com...[vbcol=seagreen]
> Thanks for the replies
> The reason I ask is someone where I work was shrinking and rebuilding
> indexes at 2pm and they said that its industry / microsoft standard to
> rebuild indexes whenever needed. I didn't believe them and thought that I
> would ask on here.
>
> "Mark Allison" wrote:
|||You may also want to check the following article:
Microsoft SQL Server 2000 Index Defragmentation Best
Practices
http://www.microsoft.com/technet/pro.../ss2kidbp.mspx
-Sue
On Tue, 5 Jul 2005 01:45:02 -0700, Tim Earnshaw
<TimEarnshaw@.discussions.microsoft.com> wrote:
[vbcol=seagreen]
>Thanks for the replies
>The reason I ask is someone where I work was shrinking and rebuilding
>indexes at 2pm and they said that its industry / microsoft standard to
>rebuild indexes whenever needed. I didn't believe them and thought that I
>would ask on here.
>
>"Mark Allison" wrote:
|||Tim,
You might also want to check out the sample script under DBCC SHOWCONTIG in
BOL. It allows you to only reindex ones that really need it.
Andrew J. Kelly SQL MVP
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:s7tkc1t81de95nhc20tbl3ftdf8vam2ei2@.4ax.com...
> You may also want to check the following article:
> Microsoft SQL Server 2000 Index Defragmentation Best
> Practices
> http://www.microsoft.com/technet/pro.../ss2kidbp.mspx
> -Sue
> On Tue, 5 Jul 2005 01:45:02 -0700, Tim Earnshaw
> <TimEarnshaw@.discussions.microsoft.com> wrote:
>
|||Although even that example I provided doesn't take into account whether the
index is actually used for range scans and so will benefit from being
rebuilt/defragged.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:OAMduScgFHA.516@.TK2MSFTNGP09.phx.gbl...
> Tim,
> You might also want to check out the sample script under DBCC SHOWCONTIG
> in BOL. It allows you to only reindex ones that really need it.
>
> --
> Andrew J. Kelly SQL MVP
>
> "Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
> news:s7tkc1t81de95nhc20tbl3ftdf8vam2ei2@.4ax.com...
>
sql

Rebuilding Indexes and Shrinking Databases

Is there a best practice for the time of day to rebuild indexes and shrink
databases? i.e. not in the middle of the day
What performance hit would it have performing them actions on a 20Gb
Database have on disk I/O, Processor, etc.?
ThanksTim
Yes it is a good practice to rebuild indexes but when it depends on your
data load. We do it a twice a week.
Don't shrink database because it causes a fragmentation to be created of
the data pages. How do you increase a size of the database?
"Tim Earnshaw" <TimEarnshaw@.discussions.microsoft.com> wrote in message
news:1EBF5F1D-C20C-4969-A5AF-2A52E784A0F5@.microsoft.com...
> Is there a best practice for the time of day to rebuild indexes and shrink
> databases? i.e. not in the middle of the day
> What performance hit would it have performing them actions on a 20Gb
> Database have on disk I/O, Processor, etc.?
> Thanks|||Tim,
Depends on what maintenance windows you have - do it then. I usually
rebuild indexes weekly and never, ever, ever shrink databases unless
there's an emergency (run out of disk space).
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html
Tim Earnshaw wrote:
> Is there a best practice for the time of day to rebuild indexes and shrink
> databases? i.e. not in the middle of the day
> What performance hit would it have performing them actions on a 20Gb
> Database have on disk I/O, Processor, etc.?
> Thanks|||Thanks for the replies
The reason I ask is someone where I work was shrinking and rebuilding
indexes at 2pm and they said that its industry / microsoft standard to
rebuild indexes whenever needed. I didn't believe them and thought that I
would ask on here.
"Mark Allison" wrote:

> Tim,
> Depends on what maintenance windows you have - do it then. I usually
> rebuild indexes weekly and never, ever, ever shrink databases unless
> there's an emergency (run out of disk space).
> --
> Mark Allison, SQL Server MVP
> http://www.markallison.co.uk
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602m.html
>
> Tim Earnshaw wrote:
>|||Hello Tim,
It is wrong to rebuild Indexes just because there is a command "DBCC Rebuild
... " - Atleast not everyday !!.
We used to load the contracts data into the Reinsurance Accounting DB on a
daily basis. Before the load, we used
to drop the Indexes and recreate them after loading the data. This process
used to take care of Rebuilding the Indexes
However, for the transaction accounting tables (contract tables in the
Reinsurance Accounting becomes Read Only ),
I used to manually drop them recreate them on a weekly basis. Manually
because the "Rebuild Index" process fills
the transaction log pretty fast if the table is huge. The application/DB was
a 24/7 application and one hour (6:30 PM EST)
was allocated for all sort of maintenance.
Hope this helps.
Gopi
"Tim Earnshaw" <TimEarnshaw@.discussions.microsoft.com> wrote in message
news:F97F5310-D81B-4995-A7B6-C7DEA329DBFD@.microsoft.com...[vbcol=seagreen]
> Thanks for the replies
> The reason I ask is someone where I work was shrinking and rebuilding
> indexes at 2pm and they said that its industry / microsoft standard to
> rebuild indexes whenever needed. I didn't believe them and thought that I
> would ask on here.
>
> "Mark Allison" wrote:
>|||You may also want to check the following article:
Microsoft SQL Server 2000 Index Defragmentation Best
Practices
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
-Sue
On Tue, 5 Jul 2005 01:45:02 -0700, Tim Earnshaw
<TimEarnshaw@.discussions.microsoft.com> wrote:
[vbcol=seagreen]
>Thanks for the replies
>The reason I ask is someone where I work was shrinking and rebuilding
>indexes at 2pm and they said that its industry / microsoft standard to
>rebuild indexes whenever needed. I didn't believe them and thought that I
>would ask on here.
>
>"Mark Allison" wrote:
>|||Tim,
You might also want to check out the sample script under DBCC SHOWCONTIG in
BOL. It allows you to only reindex ones that really need it.
Andrew J. Kelly SQL MVP
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:s7tkc1t81de95nhc20tbl3ftdf8vam2ei2@.
4ax.com...
> You may also want to check the following article:
> Microsoft SQL Server 2000 Index Defragmentation Best
> Practices
> [url]http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx[/ur
l]
> -Sue
> On Tue, 5 Jul 2005 01:45:02 -0700, Tim Earnshaw
> <TimEarnshaw@.discussions.microsoft.com> wrote:
>
>|||Although even that example I provided doesn't take into account whether the
index is actually used for range scans and so will benefit from being
rebuilt/defragged.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:OAMduScgFHA.516@.TK2MSFTNGP09.phx.gbl...
> Tim,
> You might also want to check out the sample script under DBCC SHOWCONTIG
> in BOL. It allows you to only reindex ones that really need it.
>
> --
> Andrew J. Kelly SQL MVP
>
> "Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
> news:s7tkc1t81de95nhc20tbl3ftdf8vam2ei2@.
4ax.com...
>

Rebuilding Indexes and Shrinking Databases

Is there a best practice for the time of day to rebuild indexes and shrink
databases? i.e. not in the middle of the day
What performance hit would it have performing them actions on a 20Gb
Database have on disk I/O, Processor, etc.?
ThanksTim
Yes it is a good practice to rebuild indexes but when it depends on your
data load. We do it a twice a week.
Don't shrink database because it causes a fragmentation to be created of
the data pages. How do you increase a size of the database?
"Tim Earnshaw" <TimEarnshaw@.discussions.microsoft.com> wrote in message
news:1EBF5F1D-C20C-4969-A5AF-2A52E784A0F5@.microsoft.com...
> Is there a best practice for the time of day to rebuild indexes and shrink
> databases? i.e. not in the middle of the day
> What performance hit would it have performing them actions on a 20Gb
> Database have on disk I/O, Processor, etc.?
> Thanks|||Tim,
Depends on what maintenance windows you have - do it then. I usually
rebuild indexes weekly and never, ever, ever shrink databases unless
there's an emergency (run out of disk space).
--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html
Tim Earnshaw wrote:
> Is there a best practice for the time of day to rebuild indexes and shrink
> databases? i.e. not in the middle of the day
> What performance hit would it have performing them actions on a 20Gb
> Database have on disk I/O, Processor, etc.?
> Thanks|||Thanks for the replies
The reason I ask is someone where I work was shrinking and rebuilding
indexes at 2pm and they said that its industry / microsoft standard to
rebuild indexes whenever needed. I didn't believe them and thought that I
would ask on here.
"Mark Allison" wrote:
> Tim,
> Depends on what maintenance windows you have - do it then. I usually
> rebuild indexes weekly and never, ever, ever shrink databases unless
> there's an emergency (run out of disk space).
> --
> Mark Allison, SQL Server MVP
> http://www.markallison.co.uk
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602m.html
>
> Tim Earnshaw wrote:
> > Is there a best practice for the time of day to rebuild indexes and shrink
> > databases? i.e. not in the middle of the day
> >
> > What performance hit would it have performing them actions on a 20Gb
> > Database have on disk I/O, Processor, etc.?
> >
> > Thanks
>|||Hello Tim,
It is wrong to rebuild Indexes just because there is a command "DBCC Rebuild
... " - Atleast not everyday !!.
We used to load the contracts data into the Reinsurance Accounting DB on a
daily basis. Before the load, we used
to drop the Indexes and recreate them after loading the data. This process
used to take care of Rebuilding the Indexes
However, for the transaction accounting tables (contract tables in the
Reinsurance Accounting becomes Read Only ),
I used to manually drop them recreate them on a weekly basis. Manually
because the "Rebuild Index" process fills
the transaction log pretty fast if the table is huge. The application/DB was
a 24/7 application and one hour (6:30 PM EST)
was allocated for all sort of maintenance.
Hope this helps.
Gopi
"Tim Earnshaw" <TimEarnshaw@.discussions.microsoft.com> wrote in message
news:F97F5310-D81B-4995-A7B6-C7DEA329DBFD@.microsoft.com...
> Thanks for the replies
> The reason I ask is someone where I work was shrinking and rebuilding
> indexes at 2pm and they said that its industry / microsoft standard to
> rebuild indexes whenever needed. I didn't believe them and thought that I
> would ask on here.
>
> "Mark Allison" wrote:
>> Tim,
>> Depends on what maintenance windows you have - do it then. I usually
>> rebuild indexes weekly and never, ever, ever shrink databases unless
>> there's an emergency (run out of disk space).
>> --
>> Mark Allison, SQL Server MVP
>> http://www.markallison.co.uk
>> Looking for a SQL Server replication book?
>> http://www.nwsu.com/0974973602m.html
>>
>> Tim Earnshaw wrote:
>> > Is there a best practice for the time of day to rebuild indexes and
>> > shrink
>> > databases? i.e. not in the middle of the day
>> >
>> > What performance hit would it have performing them actions on a 20Gb
>> > Database have on disk I/O, Processor, etc.?
>> >
>> > Thanks|||You may also want to check the following article:
Microsoft SQL Server 2000 Index Defragmentation Best
Practices
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
-Sue
On Tue, 5 Jul 2005 01:45:02 -0700, Tim Earnshaw
<TimEarnshaw@.discussions.microsoft.com> wrote:
>Thanks for the replies
>The reason I ask is someone where I work was shrinking and rebuilding
>indexes at 2pm and they said that its industry / microsoft standard to
>rebuild indexes whenever needed. I didn't believe them and thought that I
>would ask on here.
>
>"Mark Allison" wrote:
>> Tim,
>> Depends on what maintenance windows you have - do it then. I usually
>> rebuild indexes weekly and never, ever, ever shrink databases unless
>> there's an emergency (run out of disk space).
>> --
>> Mark Allison, SQL Server MVP
>> http://www.markallison.co.uk
>> Looking for a SQL Server replication book?
>> http://www.nwsu.com/0974973602m.html
>>
>> Tim Earnshaw wrote:
>> > Is there a best practice for the time of day to rebuild indexes and shrink
>> > databases? i.e. not in the middle of the day
>> >
>> > What performance hit would it have performing them actions on a 20Gb
>> > Database have on disk I/O, Processor, etc.?
>> >
>> > Thanks|||Tim,
You might also want to check out the sample script under DBCC SHOWCONTIG in
BOL. It allows you to only reindex ones that really need it.
Andrew J. Kelly SQL MVP
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:s7tkc1t81de95nhc20tbl3ftdf8vam2ei2@.4ax.com...
> You may also want to check the following article:
> Microsoft SQL Server 2000 Index Defragmentation Best
> Practices
> http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
> -Sue
> On Tue, 5 Jul 2005 01:45:02 -0700, Tim Earnshaw
> <TimEarnshaw@.discussions.microsoft.com> wrote:
>>Thanks for the replies
>>The reason I ask is someone where I work was shrinking and rebuilding
>>indexes at 2pm and they said that its industry / microsoft standard to
>>rebuild indexes whenever needed. I didn't believe them and thought that I
>>would ask on here.
>>
>>"Mark Allison" wrote:
>> Tim,
>> Depends on what maintenance windows you have - do it then. I usually
>> rebuild indexes weekly and never, ever, ever shrink databases unless
>> there's an emergency (run out of disk space).
>> --
>> Mark Allison, SQL Server MVP
>> http://www.markallison.co.uk
>> Looking for a SQL Server replication book?
>> http://www.nwsu.com/0974973602m.html
>>
>> Tim Earnshaw wrote:
>> > Is there a best practice for the time of day to rebuild indexes and
>> > shrink
>> > databases? i.e. not in the middle of the day
>> >
>> > What performance hit would it have performing them actions on a 20Gb
>> > Database have on disk I/O, Processor, etc.?
>> >
>> > Thanks
>|||Although even that example I provided doesn't take into account whether the
index is actually used for range scans and so will benefit from being
rebuilt/defragged.
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:OAMduScgFHA.516@.TK2MSFTNGP09.phx.gbl...
> Tim,
> You might also want to check out the sample script under DBCC SHOWCONTIG
> in BOL. It allows you to only reindex ones that really need it.
>
> --
> Andrew J. Kelly SQL MVP
>
> "Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
> news:s7tkc1t81de95nhc20tbl3ftdf8vam2ei2@.4ax.com...
>> You may also want to check the following article:
>> Microsoft SQL Server 2000 Index Defragmentation Best
>> Practices
>> http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
>> -Sue
>> On Tue, 5 Jul 2005 01:45:02 -0700, Tim Earnshaw
>> <TimEarnshaw@.discussions.microsoft.com> wrote:
>>Thanks for the replies
>>The reason I ask is someone where I work was shrinking and rebuilding
>>indexes at 2pm and they said that its industry / microsoft standard to
>>rebuild indexes whenever needed. I didn't believe them and thought that I
>>would ask on here.
>>
>>"Mark Allison" wrote:
>> Tim,
>> Depends on what maintenance windows you have - do it then. I usually
>> rebuild indexes weekly and never, ever, ever shrink databases unless
>> there's an emergency (run out of disk space).
>> --
>> Mark Allison, SQL Server MVP
>> http://www.markallison.co.uk
>> Looking for a SQL Server replication book?
>> http://www.nwsu.com/0974973602m.html
>>
>> Tim Earnshaw wrote:
>> > Is there a best practice for the time of day to rebuild indexes and
>> > shrink
>> > databases? i.e. not in the middle of the day
>> >
>> > What performance hit would it have performing them actions on a 20Gb
>> > Database have on disk I/O, Processor, etc.?
>> >
>> > Thanks
>>
>

Rebuilding Indexes

I am trying to rebuild indexes on system tables by using a script that will be called from a batch job. Does anyone have any ideas of how to do this? I know DBCC DBREINDEX does not support use on sytem tables.What version of SQL?

I'm also wondering why you want to do this. I've never even thought about it. SQL 2000 is supposed to update this stuff automatically. Maybe I shouldn't AssUme? hmm.

I really can't find anything on the subject.|||Never ever play with system tables using DBCCs, even MS discourages and does not support to do so.

As referred why do you want screw up your system?

Rebuilding Indexes

Hello all,

I need to diagnose a problem, this Sunday a regular Database Maintenance plan which is supposed to rebuild indexes took exactly 6 hours and 32 minutes. Now thats a hell lot of time and during all that process users were denied access to those tables. This is a production server. I want to know what caused that plan to run for so long and how can I avoid this to happen again plus if it ever happens again how can I make sure that atleast it doesnt lock tables. I know DBCC INDEXDEFRAG doesnt lock tables but how can I make Database Maintenance plan to run DBCC INDEXDEFRAG instead of DBCC DBREINDEX but more importantly why it took 6 hours.

Thanks allThere a lots of reasons that the process could have lasted so long. Do you have any evidence to indicate that this length of time is longer than normal (ie, what did it take last weekend and the weekend before that)?

Some things to possible look for:
1. A transaction that hung
2. Disk space (for both the Data and TLog files)
3. Disk space (for the TempDB)
4. Other jobs or indicators that ran over-long during this period

Also, look at your SQL Error Log for the time period and determine if there are any errors or warnings related to the problem. Look at you your System and Applcation Error Logs for indications that are related to the problem.

As for DBREINDEX vs. INDEXDEFRAG, I might suggest saving the former for quarterly or otherwise routine maintenance periods when you are guaranteed a "clean" box to work on (ie, no user connections, no activity). You can script off a T-SQL that will do an INDEXDEFRAG on specified tables (or all of them if you want).

Regards,

hmscott|||more data? that's usually the number one reason ;)

Rebuilding indexes

Hi
I got the advice to rebuild the indexes on the databases once a year.
Espesially if the database have grown much. The question is: How do I
do that?
If I try to run the indexscript wich was run when the databases were
created, I only get the message that the indexes already exists.
Are there a command to automatically rebuild the indexes
automatically?

Roger"Roger" <roger.valand@.tiscali.no> wrote in message
news:3ite40tfa67m2of2qq5m5uc8vlvreilko3@.4ax.com...
> Hi
> I got the advice to rebuild the indexes on the databases once a year.
> Espesially if the database have grown much. The question is: How do I
> do that?
> If I try to run the indexscript wich was run when the databases were
> created, I only get the message that the indexes already exists.
> Are there a command to automatically rebuild the indexes
> automatically?
> Roger

See DBCC DBREINDEX in Books Online, or use a maintenance plan. Once a year
sounds like a very conservative schedule, so you may want to consider weekly
rebuilds if you believe you need them.

Simon|||Checkout the whitepaper below - it will help you decide whether it's even
worth rebuilding the indexes and explain the pros and cons of the different
methods of doing so.

http://www.microsoft.com/technet/tr...ze/ss2kidbp.asp

--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.

"Roger" <roger.valand@.tiscali.no> wrote in message
news:3ite40tfa67m2of2qq5m5uc8vlvreilko3@.4ax.com...
> Hi
> I got the advice to rebuild the indexes on the databases once a year.
> Espesially if the database have grown much. The question is: How do I
> do that?
> If I try to run the indexscript wich was run when the databases were
> created, I only get the message that the indexes already exists.
> Are there a command to automatically rebuild the indexes
> automatically?
> Roger|||Hi
Thank you
I'll dig into it

On Fri, 5 Mar 2004 10:28:48 -0800, "Paul S Randal [MS]"
<prandal@.online.microsoft.com> wrote:

>Checkout the whitepaper below - it will help you decide whether it's even
>worth rebuilding the indexes and explain the pros and cons of the different
>methods of doing so.
>http://www.microsoft.com/technet/tr...ze/ss2kidbp.aspsql

rebuilding index not doing anything

There are 25 indexes in my database which continue to report they are
severely fragmented even after I rebuild them. The operation completes
without error, so I don't understand why it is still fragmented. It does not
matter if I use REBUILD or REORGANIZE, the result is the same. Anyone know
how to fix this? I am using SQL Server 2005.
BTW I should mention that most indexes in the database will REBUILD and
report no fragmentation afterwards. Only 25 of them have this issue.
If I drop and recreate the index, obviously that would fix it, but I'd
rather not.
Chris
Hi Chris
What type of fragmentation are you seeing? How many pages are in these
indexes? Small indexes cannot be totally defrag'ed, and the fragmentation
doesn't really matter.
REBUILD is exactly the same as drop and recreate so if REBUILD doesn't help,
drop and recreate won't either.
Can you show us the output from sys.dm_index_physical_stats for these
indexes?
Why is it so important that these indexes be defrag'ed? What operations are
being negatively impacted because of the fragmentation?
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"Chris" <fake@.email.com> wrote in message
news:O0doxNrMIHA.2064@.TK2MSFTNGP06.phx.gbl...
> There are 25 indexes in my database which continue to report they are
> severely fragmented even after I rebuild them. The operation completes
> without error, so I don't understand why it is still fragmented. It does
> not matter if I use REBUILD or REORGANIZE, the result is the same. Anyone
> know how to fix this? I am using SQL Server 2005.
> BTW I should mention that most indexes in the database will REBUILD and
> report no fragmentation afterwards. Only 25 of them have this issue.
> If I drop and recreate the index, obviously that would fix it, but I'd
> rather not.
> Chris
|||In addition to what Kalen stated if they are Heaps then rebuilding the
indexes will do nothing for the table itself. You need a clustered index for
that.
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"Chris" <fake@.email.com> wrote in message
news:O0doxNrMIHA.2064@.TK2MSFTNGP06.phx.gbl...
> There are 25 indexes in my database which continue to report they are
> severely fragmented even after I rebuild them. The operation completes
> without error, so I don't understand why it is still fragmented. It does
> not matter if I use REBUILD or REORGANIZE, the result is the same. Anyone
> know how to fix this? I am using SQL Server 2005.
> BTW I should mention that most indexes in the database will REBUILD and
> report no fragmentation afterwards. Only 25 of them have this issue.
> If I drop and recreate the index, obviously that would fix it, but I'd
> rather not.
> Chris
|||To add to Kalen and Andrew's comments, you should check the size (number of
pages) in the 25 indexes. If the indexes are very small, they're stored in
mixed extents. Mixed extents are shared by up to 8 objects, so your ability
to completely remove fragmentation is somewhat limited in this case whether
you reorganize or rebuild.
You might want to review this whitepaper on fragmentation
(http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx).
It's written for SQL Server 2000 but is still valid for SQL Server 2005.
They recommend not worrying about fragmentation on indexes with fewer than
1000 pages because the workload performance gain isn't significant enough to
warrant it.
Gail Erickson [MS]
SQL Server Documentation Team
This posting is provided "AS IS" with no warranties, and confers no rights
Download the latest version of Books Online from
http://technet.microsoft.com/en-us/sqlserver/bb428874.aspx
"Chris" <fake@.email.com> wrote in message
news:O0doxNrMIHA.2064@.TK2MSFTNGP06.phx.gbl...
> There are 25 indexes in my database which continue to report they are
> severely fragmented even after I rebuild them. The operation completes
> without error, so I don't understand why it is still fragmented. It does
> not matter if I use REBUILD or REORGANIZE, the result is the same. Anyone
> know how to fix this? I am using SQL Server 2005.
> BTW I should mention that most indexes in the database will REBUILD and
> report no fragmentation afterwards. Only 25 of them have this issue.
> If I drop and recreate the index, obviously that would fix it, but I'd
> rather not.
> Chris
|||I think the most important thing not mentioned yet is how much free space to
you have in the database? If you are like every single client I have been
at the answer is essentially none. You are allowing autogrowth (possibly at
the default setting) to grow your database. If there isn't empty space in
the database, there is no contiguous blocks of disk space in which to
defragment anything. Double the size of the database and try again with the
rebuild. I think you will be pleased with the results.
Kevin G. Boles
TheSQLGuru
Indicium Resources, Inc.
"Chris" <fake@.email.com> wrote in message
news:O0doxNrMIHA.2064@.TK2MSFTNGP06.phx.gbl...
> There are 25 indexes in my database which continue to report they are
> severely fragmented even after I rebuild them. The operation completes
> without error, so I don't understand why it is still fragmented. It does
> not matter if I use REBUILD or REORGANIZE, the result is the same. Anyone
> know how to fix this? I am using SQL Server 2005.
> BTW I should mention that most indexes in the database will REBUILD and
> report no fragmentation afterwards. Only 25 of them have this issue.
> If I drop and recreate the index, obviously that would fix it, but I'd
> rather not.
> Chris
|||This was part of his original post:

>BTW I should mention that most indexes in the database will REBUILD and
>report no fragmentation afterwards. Only 25 of them have this issue.
While it is absolutely true that you need plenty of free space in the data
files when rebuilding an index it is unlikely the cause here or the results
would not be so consistent. He also mentioned that a REORG has no effect
either. Since that works by swapping on a page by page basis the lack of
free space would not be be much of a factor.
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"TheSQLGuru" <kgboles@.earthlink.net> wrote in message
news:13kuhuki5tflk88@.corp.supernews.com...
>I think the most important thing not mentioned yet is how much free space
>to you have in the database? If you are like every single client I have
>been at the answer is essentially none. You are allowing autogrowth
>(possibly at the default setting) to grow your database. If there isn't
>empty space in the database, there is no contiguous blocks of disk space in
>which to defragment anything. Double the size of the database and try
>again with the rebuild. I think you will be pleased with the results.
> --
> Kevin G. Boles
> TheSQLGuru
> Indicium Resources, Inc.
>
> "Chris" <fake@.email.com> wrote in message
> news:O0doxNrMIHA.2064@.TK2MSFTNGP06.phx.gbl...
>
|||But does a page by page swap not still leave fragmentation as long as only 1
index is being page swapped at a time? Or does a reorg allow for page moves
for multiple objects? Never really thought about it deeply enough.
For example, say there are index objects A, B and C. They are physically on
disk as follows (the number is the 'correct' Btree order of the index):
A2B1C1C2A3B2A1.
If index A is is currently being REORGd, how do the pages actually get
manipulated during the operation? Let us assume there is no other free
space in the database.
Does B1 get swapped for A1, leaving this: A2A1C1C2A3B2B1
And then A1 and A2 swap, leaving this: A1A2C1C2A3B2B1, etc, etc?
Kevin G. Boles
TheSQLGuru
Indicium Resources, Inc.
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:OyTW6KuMIHA.2208@.TK2MSFTNGP06.phx.gbl...
> This was part of his original post:
>
> While it is absolutely true that you need plenty of free space in the data
> files when rebuilding an index it is unlikely the cause here or the
> results would not be so consistent. He also mentioned that a REORG has no
> effect either. Since that works by swapping on a page by page basis the
> lack of free space would not be be much of a factor.
>
> --
> Andrew J. Kelly SQL MVP
> Solid Quality Mentors
>
> "TheSQLGuru" <kgboles@.earthlink.net> wrote in message
> news:13kuhuki5tflk88@.corp.supernews.com...
>
|||During reorg, pages are only swapped with other pages from the same index.
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"TheSQLGuru" <kgboles@.earthlink.net> wrote in message
news:13kup01apko432d@.corp.supernews.com...
> But does a page by page swap not still leave fragmentation as long as only
> 1 index is being page swapped at a time? Or does a reorg allow for page
> moves for multiple objects? Never really thought about it deeply enough.
> For example, say there are index objects A, B and C. They are physically
> on disk as follows (the number is the 'correct' Btree order of the index):
> A2B1C1C2A3B2A1.
> If index A is is currently being REORGd, how do the pages actually get
> manipulated during the operation? Let us assume there is no other free
> space in the database.
> Does B1 get swapped for A1, leaving this: A2A1C1C2A3B2B1
> And then A1 and A2 swap, leaving this: A1A2C1C2A3B2B1, etc, etc?
> --
> Kevin G. Boles
> TheSQLGuru
> Indicium Resources, Inc.
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:OyTW6KuMIHA.2208@.TK2MSFTNGP06.phx.gbl...
>
|||Which would leave fragmentation in place if there is no free space in the
file. Hmm, come to think of it, if page SWAPPING is all that can be done
then even huge amounts of free space won't do any good. It would need to be
able to move pages to empty space and lay them down contiguously to really
defrag the index, but if it can only swap pages that isn't good enough.
Curious.
Kevin G. Boles
TheSQLGuru
Indicium Resources, Inc.
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:OSG1InvMIHA.2308@.TK2MSFTNGP05.phx.gbl...
> During reorg, pages are only swapped with other pages from the same index.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.InsideSQLServer.com
> http://sqlblog.com
>
> "TheSQLGuru" <kgboles@.earthlink.net> wrote in message
> news:13kup01apko432d@.corp.supernews.com...
>
|||Defrag or Reorg (depending on the version) does not rebuild the pages and
extents like a Rebuild does. It simply swaps one page with another and this
can happen multiple times before it is done. None of this requires free
space (actually except for the very first first page I believe) to happen.
But since it does the reorg in two phases (compaction & defrag) it can
actually free up some pages if it compacts enough to do so. A reorg can can
remove virtually all of the Logical fragmentation but it not necessarily fix
extent fragmentation in which the next and previous extents are physically
contiguous.
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"TheSQLGuru" <kgboles@.earthlink.net> wrote in message
news:13l05fijdqgpl71@.corp.supernews.com...
> Which would leave fragmentation in place if there is no free space in the
> file. Hmm, come to think of it, if page SWAPPING is all that can be done
> then even huge amounts of free space won't do any good. It would need to
> be able to move pages to empty space and lay them down contiguously to
> really defrag the index, but if it can only swap pages that isn't good
> enough. Curious.
> --
> Kevin G. Boles
> TheSQLGuru
> Indicium Resources, Inc.
>
> "Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
> news:OSG1InvMIHA.2308@.TK2MSFTNGP05.phx.gbl...
>