Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Fragment, reindex

Author  Topic 

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-12 : 22:02:08

I have found the Fragmentation for which I have defragmented later again on checking, I found some Index keys with Fragmentation over 80 Percent along with some other Primary Key based as well.

I was not perturbed with PK's based average fragmentation but I could not understood why even after defragmenting some indexes show still fragmentation over 80 Percent.

Users didnt complain about the data accessibility, should I ignore this average fragment?

Is it necessary to do Reindex process after successful Defragmentation?

Is is necessary to do Shrink after Defrag and reindex?

While Doing Defragmentation, how to maintain the LDF size as it decrease and goes low disk size?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-12 : 22:50:36
You need to read up on defragmenting (REORGANIZE) and rebuilding (REBUILD) as they do similar but different things. You do not run them both right after each other.

Do not shrink after defrag or reindex! In fact never shrink in production unless absolutely necessary for disk space reasons or if you deleted a large amount of data and want to reclaim space.

To maintain the transaction, perform frequent tlog backups. We backup ours every 15 minutes.

Depending upon your database design, tables can quickly get fragmented. Fragmented isn't necessarily a cause for performance issues though, so don't get too concerned about it.

How big is the table?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2009-12-13 : 04:58:52
How big are the indexes that don't show a reduction in fragmentation (how many pages)?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-13 : 16:23:31
These are some of the rows that were returned when I executed for knowing the Fragmentation.

TableName TableIndexName avg_frag_% rows

PITGRAY SE_PITGRAY_IDX0 99.97668454 366667
PITGRAY SE_PITGRAY_IDX0 99.97668454 366667
PITGRAY SE_PITGRAY_IDX0 99.97668454 366667
PITGRAY SE_PITGRAY_IDX0 99.97668454 366667
PITGRAY SE_PITGRAY_IDX0 100 366667
PITGRAY SE_PITGRAY_IDX0 100 366667
PITGRAY SE_PITGRAY_IDX0 100 366667
PITGRAY SE_PITGRAY_IDX0 100 366667


I have just ignored some other similar rows which depict for TableIndexName Suffix as 'PK' between 70 - 100 Percent.

Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2009-12-13 : 17:54:11
What query did you use to get that? The same index appears to be there several times.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-13 : 18:47:07
I Have queried using sys.dm_db_index_physical_stats and sys.indexes DMVs to find the fragmentation.

I Use this query prior to defragment and later as well.

I get most of them got defragmented but still some stubborn Indexes still possess with fragmentation.

As Tara told earlier, I use Transaction log backup for every 15 minutes and get full backup during after hours.


Several big tables have around 1 or 2 GB and another having 8 GB.

Please advise.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-13 : 19:34:21
Add this to your DMV query: WHERE index_level = 0.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-13 : 20:17:13
Thanks Tara, I did added to the query and this time I have only SUFFIX as 'IDX' was reported and no 'PK' at the end amongst the results.

What exactly happened is we are trying to defragment later want to shrink the MDF and LDF.

It got it later the Reindex process did ate again the space(I Knew reindex will generate Transaction Log) but it got the same space before I did the Reindex.

As you suggested I should NOT do Reindex after Defrag, However, is it correct if I not do reindex which was defragmented and leave it once the defragmentation has been accomplished.

Earlier when we have the space swallowing problem identified with 100 percent fragmentation then I followed with Defrag + reindex which worked out for us.

But not this time, unable to understand between 2 scenarios.

What would be the correct methodology for fragmentation to defragmentation?

Thanks for your time.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-13 : 23:41:48
Well defrag+reindex is different than reindex+defrag. Defrag doesn't fix everything, it does much less work than the reindex.

Do not shrink after you've run either as you are going to create heavy fragmentation. This was mentioned to you by Gail in your other thread not too long ago.

I only run the reindex. I reindex everything every night that is over 50% fragmented.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-14 : 17:40:20
Even Reindex will cause a Heavy transaction registered onto my LDF.

I am still unable to contemplate between Defrag + Reindex OR Reindex + Defrag.

My Aim is to reduce the Fragmentation below 50 percent which is not working with either of the combination.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-14 : 17:45:58
Of course reindex will cause a ton of transaction logging.

You do not need to do a combination of both, especially not reindex + defrag as that's pointless.

Could you show us the table design of the tables in question?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-14 : 23:08:12

Thanks Tara.

I got this DB Diagram for one of the most populated table which has more than 2 Million Rows.


RecordNum Varchar25
citeID Numeric(10,0)
Delite Numeric(10,0)
UpdaterSNO Numeric(10,0)
DateCr8 Datetime
TimeCr8 Datetime
UpdateTime Datetime
UpdateDate Datetime
LocalID Numeric(10,0)
Suburbs Varchar51
Town Varchar51
Maintown Varchar51
StateAddress Varchar51
PostalCode Varchar51
Mlocality Numeric(10,0)
Dispensary Varchar11
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-14 : 23:17:42
What indexes are on that table, what's the fragmentation of them, and how random are inserts into those indexes?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-14 : 23:23:27
There are Clustered Indexes on the Concatenated Primary Key and couple of Non-Clustered Indexes and the fragmentation on them is around 99 percent most of them, Every day there would be around couple of 100's of DML operations altogether.

Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-15 : 00:12:17
Is the clustered index sequentially incrementing or decrementing? Or is it random?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-15 : 23:57:50
Some tables (Heavily populated) in the databases were Sequential and some tables (Less Populated) were at random of Clustered index nature.

Some tables with PK as the suffix were having 100 percent too.

Very much Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-16 : 00:04:09
If it's random, then fragmentation is going to be normal. What's your fill factor set to?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2009-12-16 : 00:14:45
Fill Factor 80 PERCENT.

But will it be ok with the kind of output Above as I submitted.

Since Defragmentation is not removed overall and reindex however done, but after that the Fragmentation still appearing giving wrong connotations.

Thanks
Go to Top of Page
   

- Advertisement -