Donnerstag, der 25. April 2024 - 22:19 Uhr

WSUS Timeout bei der Bereinigung

erstellt am: 21.06.2016 | von: DevLink | Kategorie(n): Microsoft Server | Keine Kommentare

Problem:

Die Festplatten laufen voll und der WSUS hat schon lange die 200GB Grenze überschritten.
Die Serverbereinigung würde hier Abhilfe schaffen, vorrausgesetzt, sie wurde schon einmal durchgeführt.
In diesem Fall wurde der Server seit ca. 5 Jahren nicht mehr bereinigt,
in der Konfiguration wurde jeglicher Mist erlaubt und danach geschaut hat ja sowieso niemand.

Die Aktion brach dann ständig mit Meldungen über Timeouts ab.
Den Serverknoten zurückzusetzen bringt keine Abhilfe und das Problem besteht auch wenn man das Timeout der lokalen Datenbank auf 0 setzt.
Nach langer Recherche habe ich dann doch eine Lösung gefunden, die das Problem vorerst behebt.

Schritt 1: Lokale Datenbank bereinigen.

  1. In Microsoft SQL Server über Named Pipes mit der Internen Windows Datenbank verbinden.

    "\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query" (2003–2008) oder "\\.\pipe\MICROSOFT##WID\tsql\query"

  2. Eine neue Abfrage erstellen und untenstehenden Code einfügen
  3. Ausführen und warten.

Es kann bis zu 20 Stunden dauern, bis die Abfrage beendet wlrd.

Zum Testen, wie viele Einträge übrig sind folgende Abfrage ausführen:

USE SUSDB
GO
exec spGetObsoleteUpdatesToCleanup

Danach mit Schritt 2 fortfahren

Script

			USE SUSDB
			DECLARE @var1 INT 
			DECLARE @msg nvarchar(100) 
			CREATE TABLE #results (Col1 INT) INSERT INTO #results(Col1) 
			EXEC spGetObsoleteUpdatesToCleanup 
			DECLARE WC Cursor FOR SELECT Col1 FROM #results 
			OPEN WC 
			FETCH NEXT FROM WC INTO @var1 WHILE (@@FETCH_STATUS > -1) 
			BEGIN SET @msg = 'Deleting ' + CONVERT(varchar(10), @var1) RAISERROR(@msg,0,1) WITH NOWAIT 
			EXEC spDeleteUpdate @localUpdateID=@var1 
			FETCH NEXT FROM WC INTO @var1 
			END 
			CLOSE WC 
			DEALLOCATE WC 
			DROP TABLE #results
		

Quelle:
Technet removing unnecessary updates

Schritt 2: Die Updates entfernen

  1. Starte die Windows Server Update Services MMC
  2. Geht auf Alle Updates, ändert die Genehmigung auf Genehmigt und Status Installiert.

    Probiert verschiedene Ansichten aus, der Server kann auch hier schon die Verbindung kappen.

  3. Mit der rechten Maustaste auf die Symbolleiste klicken und "Ersatz aktivieren" und nach diesem sortieren

    wsus
    Bild in Originalgröße anzeigen
  4. Alle Updates die nicht dieses Symbol: wsus haben sondern z.B. dieses: wsus markieren.
  5. Updates ohne Symbol bleiben vorerst unberührt
  6. Mit rechter Maustaste markierte Updates ablehnen.
  7. Nach der Aktion unter Optionen die Serverbereinigung durchführen
  8. Schritte wiederholen und die Ansichten der Genehmigung am Schluss auf Alle und Alle
  9. Nach jeder Ablehnung der Updates ist es wichtig die Bereinigung durchzuführen.

    Treiber und anderer unnützer scheiß wie Service Packs etc kann bedenkenlos abgelehnt werden

Schritt 3: Die Datenbank initialisieren

  1. Wie in Schritt 1 beschrieben, mit SQL Manager auf die LDB verbinden.
  2. Unten stehendes Script in eine neue Abfrage kopieren und ausführen.
  3. Abwarten, Tee trinken und über den neuen Speicherplatz freuen
		USE SUSDB; 
		GO 	
		SET NOCOUNT ON; 
 
		-- Rebuild or reorganize indexes based on their fragmentation levels 
		DECLARE @work_to_do TABLE ( 
		objectid int 
		, indexid int 
		, pagedensity float 
		, fragmentation float 
		, numrows int 
		) 
 
		DECLARE @objectid int; 
		DECLARE @indexid int; 
		DECLARE @schemaname nvarchar(130);  
		DECLARE @objectname nvarchar(130);  
		DECLARE @indexname nvarchar(130);  
		DECLARE @numrows int 
		DECLARE @density float; 
		DECLARE @fragmentation float; 
		DECLARE @command nvarchar(4000);  
		DECLARE @fillfactorset bit 
		DECLARE @numpages int 
		
		-- Select indexes that need to be defragmented based on the following 
		-- * Page density is low 
		-- * External fragmentation is high in relation to index size 
		PRINT 'Estimating fragmentation: Begin. ' + convert(nvarchar, getdate(), 121)  
		INSERT @work_to_do 
		SELECT 
		f.object_id 
		, index_id 
		, avg_page_space_used_in_percent 
		, avg_fragmentation_in_percent 
		, record_count 
		FROM  
		sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'SAMPLED') AS f 
		WHERE 
		(f.avg_page_space_used_in_percent < 85.0 and f.avg_page_space_used_in_percent/100.0 * page_count < page_count - 1) 
		or (f.page_count > 50 and f.avg_fragmentation_in_percent > 15.0) 
		or (f.page_count > 10 and f.avg_fragmentation_in_percent > 80.0) 
 
		PRINT 'Number of indexes to rebuild: ' + cast(@@ROWCOUNT as nvarchar(20)) 
 
		PRINT 'Estimating fragmentation: End. ' + convert(nvarchar, getdate(), 121) 
 
		SELECT @numpages = sum(ps.used_page_count) 
		FROM 
		@work_to_do AS fi 
		INNER JOIN sys.indexes AS i ON fi.objectid = i.object_id and fi.indexid = i.index_id 
		INNER JOIN sys.dm_db_partition_stats AS ps on i.object_id = ps.object_id and i.index_id = ps.index_id 
 
		-- Declare the cursor for the list of indexes to be processed. 
		DECLARE curIndexes CURSOR FOR SELECT * FROM @work_to_do 
 
		-- Open the cursor. 
		OPEN curIndexes 
 
		-- Loop through the indexes 
		WHILE (1=1) 
		BEGIN 
		FETCH NEXT FROM curIndexes 
		INTO @objectid, @indexid, @density, @fragmentation, @numrows; 
		IF @@FETCH_STATUS < 0 BREAK; 
 
		SELECT  
        @objectname = QUOTENAME(o.name) 
        , @schemaname = QUOTENAME(s.name) 
		FROM  
        sys.objects AS o 
        INNER JOIN sys.schemas as s ON s.schema_id = o.schema_id 
		WHERE  
        o.object_id = @objectid; 
 
		SELECT  
        @indexname = QUOTENAME(name) 
        , @fillfactorset = CASE fill_factor WHEN 0 THEN 0 ELSE 1 END 
		FROM  
        sys.indexes 
		WHERE 
        object_id = @objectid AND index_id = @indexid; 
 
		IF ((@density BETWEEN 75.0 AND 85.0) AND @fillfactorset = 1) OR (@fragmentation < 30.0) 
        SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REORGANIZE'; 
		ELSE IF @numrows >= 5000 AND @fillfactorset = 0 
        SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD WITH (FILLFACTOR = 90)'; 
		ELSE 
        SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD'; 
		PRINT convert(nvarchar, getdate(), 121) + N' Executing: ' + @command; 
		EXEC (@command); 
		PRINT convert(nvarchar, getdate(), 121) + N' Done.'; 
		END 
 
		-- Close and deallocate the cursor. 
		CLOSE curIndexes; 
		DEALLOCATE curIndexes; 
 
 
		IF EXISTS (SELECT * FROM @work_to_do) 
		BEGIN 
		PRINT 'Estimated number of pages in fragmented indexes: ' + cast(@numpages as nvarchar(20)) 
		SELECT @numpages = @numpages - sum(ps.used_page_count) 
		FROM 
        @work_to_do AS fi 
        INNER JOIN sys.indexes AS i ON fi.objectid = i.object_id and fi.indexid = i.index_id 
        INNER JOIN sys.dm_db_partition_stats AS ps on i.object_id = ps.object_id and i.index_id = ps.index_id 
 
		PRINT 'Estimated number of pages freed: ' + cast(@numpages as nvarchar(20)) 
		END 	
		GO 
 
 
		--Update all statistics 
		PRINT 'Updating all statistics.' + convert(nvarchar, getdate(), 121)  
		EXEC sp_updatestats 
		PRINT 'Done updating statistics.' + convert(nvarchar, getdate(), 121)  
		GO 
	

Quellen:
DB initialize Script
Important Information for WSUS problems



, , , , ,

Keine Kommentare


Bis jetzt noch keine Kommentare

Einen Kommentar abgeben

Themen:

54 Artikel in 6 Kategorien:

  • Exchange Server (16)
  • Linux (6)
  • Microsoft Server (6)
  • Scripting (3)
  • Tutorials (10)
  • Windows (13)