I have a quite big database (150GB) that is running 24/24 7/7 with each day 2 windows of about 2 hours in which people are working little.
So doing a complete indexrebuild during the weekend is not possible. The only option is the rebuild/defrag indexes is during those windows. Problem is:I can't do it on all tables because it takes too much time.
So I was thinking about creating several SQL scripts and each of those is doing some tables/indexes. Problem is that I have a few hundreds of tables and if I want to move an index from 1 window to another, I have to change those scripts manually. Quite a time costing and error-prone procedure.
So I was hoping there is some tool that shows me all existing indexes and give me the possibility to add them to a script and once I have done that, generate the scripts to be run.
I have launched some searches on the forum but I didn't find any mentioning of the existence of such a tool.
Does someone know of such a tool or have a better idea how to do this?
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
0
Comments
I would like to invite you to have a look at our tools at www.sqlperform.com.
It does a reindex but smart. With analysing the need. It also clears the zero sift records and updates the statistics. Very usefull.
I have installed it at approx. 10 customers in 3 months and no one takes more than 2 hours. Even big ones.
Good luck.
BTW : once I am ready with tuning the DB for SQL, I am sure the size will go under 100GB.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I've done a warehouse customer with 140 concurrent users for example.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I guess we would need to implement our reindex function per table. This is not implemented yet but is on the roadmap.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Check this post.
http://dynamicsuser.net/blogs/nunomaia/ ... dexes.aspx
I don't know if it help you.
Freelance Dynamics AX
Blog : http://axnmaia.wordpress.com/
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
/**
This TSQL script for SQL Server 2005 will rebuild or reorganize indexes in the
Dynamics - NAV database based the fragmentation percentage. If the fragmentation
Is over 30% it will rebuild thew index if it is under 30% it will reorganize the
index.
This script is in the form a Stored Procedure "sp_index_defrag" to use this script
1. Run the script against the Dynmaics - NAV database to build the Stored Procedure
2. To run the process just open a query window and select the Dynamics - NAV database
and type "maint_index_defrag" in the query window and click [Execute]
3. When it is finished running just close the query window.
TIP: You could setup a SQL Job that runs this Stored Procedure at set intervals
Such as once a week or once a month.
**/
IF EXISTS (SELECT * FROM sys.sysobjects WHERE id = object_id('dbo.maint_index_defrag') and sysstat & 0xf = 4)
DROP PROCEDURE maint_index_defrag
go
Create Procedure maint_index_defrag
as
SET NOCOUNT ON;
DECLARE @objectid int;
DECLARE @indexid int;
DECLARE @partitioncount bigint;
DECLARE @schemaname sysname;
DECLARE @objectname sysname;
DECLARE @indexname sysname;
DECLARE @partitionnum bigint;
DECLARE @partitions bigint;
DECLARE @frag float;
DECLARE @command varchar(8000);
DECLARE @percentage int
SET @percentage = 30 --You can change the precentage threshhold here
IF EXISTS (SELECT name FROM sys.objects WHERE name = 'work_to_do')
DROP TABLE work_to_do;
SELECT
object_id AS objectid,
index_id AS indexid,
partition_number AS partitionnum,
avg_fragmentation_in_percent AS frag
INTO work_to_do
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'DETAILED')
WHERE avg_fragmentation_in_percent > @percentage AND index_id > 0;
DECLARE partitions CURSOR FOR SELECT * FROM work_to_do;
OPEN partitions;
FETCH NEXT
FROM partitions
INTO @objectid, @indexid, @partitionnum, @frag;
@FETCH_STATUS = 0
BEGIN;
SELECT @objectname = o.name, @schemaname = s.name
FROM sys.objects AS o
JOIN sys.schemas as s ON s.schema_id = o.schema_id
WHERE o.object_id = @objectid;
SELECT @indexname = name
FROM sys.indexes
WHERE object_id = @objectid AND index_id = @indexid;
SELECT @partitioncount = count (*)
FROM sys.partitions
WHERE object_id = @objectid AND index_id = @indexid;
IF @frag < (@percentage)
BEGIN;
SELECT @command = 'ALTER INDEX ' + '' + ' ON ' + '' + '.' + '' + ' REORGANIZE';
--IF @partitioncount > 1
-- SELECT @command = @command + ' PARTITION=' + CONVERT (CHAR, @partitionnum);
EXEC (@command);
END;
IF @frag >= (@percentage)
BEGIN;
SELECT @command = 'ALTER INDEX ' + '' + ' ON ' + '' + '.' + '' + ' REBUILD';
--IF @partitioncount > 1
-- SELECT @command = @command + ' PARTITION=' + CONVERT (CHAR, @partitionnum);
EXEC (@command);
END;
PRINT 'Executed ' + @command;
FETCH NEXT FROM partitions INTO @objectid, @indexid, @partitionnum, @frag;
END;
CLOSE partitions;
DEALLOCATE partitions;
IF EXISTS (SELECT name FROM sys.objects WHERE name = 'work_to_do')
DROP TABLE work_to_do;
GO
http://weblogs.sqlteam.com/tarad/archive/2007/04/17/60176.aspx#3688568135596798454
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I found this script on blogs.msdn.com site and were using it for a while for some older NAV installations (SQL2005). Script says that it will reorganize all indexes fragmented less than @percentage and rebuild all indexes fragmented more than @percentage. But, while collecting indexes for rebuild, it filters-out all indexes fragmented more than @percentage.
In that case reorganize of some index will never occur?
I had a project like that, we were beginners and kind of clueless, the company was doing normal B2B but also had a Cash and Carry shop, so to win the deal we did not recommend Landsteinar just writing invoices to a generic customer and rewriting the name on each... made the DB big.
@Phenno: In this, I have a solution for the rebuild index. It is not perfect but is workable. Another (free) tool is using this or this this
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Thank you, I already switched to Hallengren's script.