www.informatik-aktuell.de
Analyse eines Microsoft SQL Server
Uwe Ricken
www: http://www.db-berater.de
email: uwe.ricken@db-berater.de
blog: http://db-berater.blogspot.de
twitter: https://twitter.com/@dbberater
xing: http://www.xing.com/profile/Uwe_Ricken
I am working with IT-systems since early 1990's and
with the main focus on Microsoft SQL Server since
version 6.0. I started with development of database
applications in 1998 with a professional CRM-System
based on Microsoft products (Microsoft Office and
Microsoft SQL Server).
Since 2008 I'm focused exclusively on Microsoft SQL
Server and since 2008 I'm working in 3rd level support
teams for banks, insurances and global industries.
Since May 2013 I'm a Microsoft Certified Master: SQL
Server 2008 which was an amazing way into the
depth of Microsoft SQL Server.
In July 2013 I have been awarded with the MVP
Award for Microsoft SQL Server.
Uwe Ricken
db Berater GmbH
The Microsoft Certified Solutions Master (MCSM) and Microsoft Certified Master
(MCM) programs recognize the most experienced IT professionals who demonstrate
and validate their deep technical skills to successfully design and implement technical
solutions in a complex business environment.
Microsoft Certified Solutions Expert (MCSE) certifications are designed to recognize IT
professionals who can design and build solutions across multiple technologies, both
on-premises and in the cloud.
The Microsoft Most Valuable Professional (MVP) Award is our way of saying thank you
to exceptional, independent community leaders who share their passion, technical
expertise, and real-world knowledge of Microsoft products with others.
Uwe Ricken
db Berater GmbH
Wann ist eine Untersuchung erforderlich?
• Berater / Consultant
• Abnahme eines durch Drittanbieter installierten Systems
• Problemanalyse
• Optimierungsanalyse
• DBA
• Problemanalyse
• Optimierungsanalyse (na ja)
Agenda
• Betriebssystem
• Überprüfung der Umgebung des Dienstkontos
001 - A01 - System Environment - Security.sql
• Formatierte Blockgröße der vorhandenen Speichermedien
001 - A01 - System Environment - Security.sql
• Berechtigungen des Dienstkontos
001 - A01 - System Environment - Security.sql
• Systemkonfiguration
• CPU / RAM / IO
001 - A02 - System Environment - Drive Latency.sql
Agenda
• Datenbankkonfiguration
• System- / Benutzerdatenbanken
• TEMPDB (!!!)
• Sizing / Growth / Storage
• Verwendung
• CPU / Memory / PLE / Storage / Serverprotokolle
• SQL Server Agent Jobs
• Backups
Agenda
• Indexierung
• Wie viele Indexe sind in der Datenbank vorhanden?
• Wie viele Indexe werden für einzelne Tabellen genutzt?
• Wie werden Indexe genutzt?
• Welche Indexe können gelöscht werden?
• Wo können neue Indexe die Performance verbessern
• Statistiken
Agenda
• Wie wird der Plan Cache verwendet
• Werden AdHoc-Abfragen verwendet?
• Werden parametrisierte Abfragen verwendet?
Workflow eines Datenbank-Requests
Abbildung: http://rusanu.com/2013/08/01/understanding-how-sql-server-executes-a-query/
When SQL Server waits
running
suspendedrunnable
60: RUNNING
54: WAITFOR
56: ASYNC_...
68: LCK_M_S
70: PAGELA..
55: RUNNABLE
59: RUNNABLE
72: RUNNABLE
51: RUNNABLE
When SQL Server waits
running
suspendedrunnable
55: RUNNING
>4ms
54: WAITFOR
56: ASYNC_...
70: PAGELA..
59: RUNNABLE
72: RUNNABLE
51: RUNNABLE
68: RUNNABLE
When SQL Server waits
running
suspendedrunnable
59: RUNNING
54: WAITFOR
56: ASYNC_...
70: PAGELA..
72: RUNNABLE
51: RUNNABLE
68: RUNNABLE
55: RUNNABLE
Quantum: 4ms
SOS_SCHEDULER_YIELD
CXPACKET
• occurs when a parallel query is executing
• Examine the long-running parallel query and tune it if
necessary.
• To ensure “efficient” parallelism, check that the statistics
on tables and indexes used by the query are up to date.
CXPACKET
Transaction
1.000 records
1.000 records
1.000 records
1.000 records
CONTROLLER THREAD
SOS_SCHEDULER_YIELD
• This common wait isn’t necessarily a problem
• It indicates that SQL Server CPU scheduling is working
efficiently.
• RUNNING | SUSPENDED | RUNNABLE
ASYNC_IO_COMPLETION
• This occurs when SQL Server is waiting for asynchronous I/O
operations to finish
• Look for additional waits in the top ranking
• IO_COMPLETION
• LOGMGR
• WRITELOG
• PAGEIOLATCH_*
ASYNC_NETWORK_IO
• Your application code may not be retrieving data correctly!
• There are very large data sets being requested by the client!
• An application is requesting large amounts of data!
THREADPOOL
• SQL Server assigns a scheduler to each CPU core
to manage internal threads.
• Some of these threads are worker threads that
are assigned to query requests on a one-to-one
basis.
• If every worker thread is busy, additional
requests can't be assigned straight away.
• SQL Server attempts to manage requests more
efficiently by creating a pool of worker threads,
so the next available worker thread from the
pool will pick up the task.
• If every worker thread remains busy, SQL Server
can't accept new requests and will hang.
Cores 32 bit 64 bit
<=4 256 512
5 – 8 288 576
9 – 16 352 704
32 480 960
WRITELOG
• This wait occurs when data in the log cache is being flushed to
disk.
• Whenever a data page is updated, it’s written to the buffer
cache and the log cache.
• Data in the log cache is then written to the transaction log file
on the physical disk once the transaction is complete.
PAGEIOLATCH_??
• Buffer Latch for a page object on the disk
• DT (destroy)
• EX (exclusive)
• KP (keep)
• SH (shared)
• UP (update)
PAGELATCH_??
• PAGELATCH_* latches are lightweight, non-configurable
internal locks used by SQL Server’s storage engine to protect
concurrent access to pages in the BUFFER POOL
Untersuchung des Betriebssystems
• Physikalische / Virtuelle Umgebung
• Wie viele CORES / RAM?
• Gibt es mehrere HDD im System?
• Wie sind die HDD formatiert?
Betriebsumfeld des SQL Server
• Wie viel RAM wird dem SQL Server zugeteilt?
• Kann SQL Server alle Prozessoren verwenden?
• Welche Sicherheitseinstellungen sind konfiguriert worden?
• Windows Authentifizierung
• Mixed Authentifizierung
• Welche Berechtigungen hat das Dienstkonto?
• Ist Instant File Initialization aktiviert?
• Ist „Lock Pages in Memory“ aktiviert?
Betriebsumfeld des SQL Server
• Datenbankeinstellungen
• FILLFACTOR
• Standardverzeichnisse für Datenbanken
• Erweiterte Konfigurationseinstellungen
• Max Degree of Parallelism
• AdHoc Workloads
• Gibt es konfigurierte Ressource-Governour-Einstellungen
Schwachstelle TEMPDB
• Verwendungsarten
• READ COMMITTED SNAPSHOT ISOLATION
• HASH- /SORT-Operationen
• Durch Benutzer angelegte temporäre Tabellen
• Tabellenvariablen
• …
• Alle Operationen wollen Platz in TEMPDB reservieren
• Reservierung erfolgt über PFS / GAM / SGAM
Konfiguration der Datenbanken
• Wie sind Datenbanken auf Storage verteilt?
• Gibt es eine Trennung zwischen DATA und LOG?
• Welchen Wachstumswert haben Datenbanken als Standard
eingestellt?
• Wie groß sind die Datenbanken?
• Wie viel Platz ist in den Datenbanken noch frei?
Dokumentation
• Beginnen Sie mit Informationen zu Ihrer Person
• Beschreiben Sie den Grund für die Erstellung des Berichts
• Gab es Probleme, die – plötzlich – aufgetreten sind?
• Ist es eine initiale Untersuchung vor einem Go Live?
• Weisen Sie darauf hin, dass eine Hardware- Untersuchung
nicht Bestandteil der Dokumentation ist, wenn Sie keinen
Zugriff auf die einzelnen Hardwarekomponenten haben
• Legen Sie einen Struktur für Ihr Dokument fest, dass der
Untersuchungsreihenfolge entspricht!
Dokumentation
• Begründungen durch Fußnoten mit Verweisen zur
Dokumentation begleiten
• BITTE KEINE FORENBEITRÄGE!
• Möglichst nur Links zum Hersteller

Uwe Ricken – IT-Tage 2015 – Workshop: MS SQL Server Optimierung

  • 1.
  • 2.
    Analyse eines MicrosoftSQL Server Uwe Ricken
  • 3.
    www: http://www.db-berater.de email: uwe.ricken@db-berater.de blog:http://db-berater.blogspot.de twitter: https://twitter.com/@dbberater xing: http://www.xing.com/profile/Uwe_Ricken I am working with IT-systems since early 1990's and with the main focus on Microsoft SQL Server since version 6.0. I started with development of database applications in 1998 with a professional CRM-System based on Microsoft products (Microsoft Office and Microsoft SQL Server). Since 2008 I'm focused exclusively on Microsoft SQL Server and since 2008 I'm working in 3rd level support teams for banks, insurances and global industries. Since May 2013 I'm a Microsoft Certified Master: SQL Server 2008 which was an amazing way into the depth of Microsoft SQL Server. In July 2013 I have been awarded with the MVP Award for Microsoft SQL Server. Uwe Ricken db Berater GmbH
  • 4.
    The Microsoft CertifiedSolutions Master (MCSM) and Microsoft Certified Master (MCM) programs recognize the most experienced IT professionals who demonstrate and validate their deep technical skills to successfully design and implement technical solutions in a complex business environment. Microsoft Certified Solutions Expert (MCSE) certifications are designed to recognize IT professionals who can design and build solutions across multiple technologies, both on-premises and in the cloud. The Microsoft Most Valuable Professional (MVP) Award is our way of saying thank you to exceptional, independent community leaders who share their passion, technical expertise, and real-world knowledge of Microsoft products with others. Uwe Ricken db Berater GmbH
  • 5.
    Wann ist eineUntersuchung erforderlich? • Berater / Consultant • Abnahme eines durch Drittanbieter installierten Systems • Problemanalyse • Optimierungsanalyse • DBA • Problemanalyse • Optimierungsanalyse (na ja)
  • 6.
    Agenda • Betriebssystem • Überprüfungder Umgebung des Dienstkontos 001 - A01 - System Environment - Security.sql • Formatierte Blockgröße der vorhandenen Speichermedien 001 - A01 - System Environment - Security.sql • Berechtigungen des Dienstkontos 001 - A01 - System Environment - Security.sql • Systemkonfiguration • CPU / RAM / IO 001 - A02 - System Environment - Drive Latency.sql
  • 7.
    Agenda • Datenbankkonfiguration • System-/ Benutzerdatenbanken • TEMPDB (!!!) • Sizing / Growth / Storage • Verwendung • CPU / Memory / PLE / Storage / Serverprotokolle • SQL Server Agent Jobs • Backups
  • 8.
    Agenda • Indexierung • Wieviele Indexe sind in der Datenbank vorhanden? • Wie viele Indexe werden für einzelne Tabellen genutzt? • Wie werden Indexe genutzt? • Welche Indexe können gelöscht werden? • Wo können neue Indexe die Performance verbessern • Statistiken
  • 9.
    Agenda • Wie wirdder Plan Cache verwendet • Werden AdHoc-Abfragen verwendet? • Werden parametrisierte Abfragen verwendet?
  • 10.
    Workflow eines Datenbank-Requests Abbildung:http://rusanu.com/2013/08/01/understanding-how-sql-server-executes-a-query/
  • 11.
    When SQL Serverwaits running suspendedrunnable 60: RUNNING 54: WAITFOR 56: ASYNC_... 68: LCK_M_S 70: PAGELA.. 55: RUNNABLE 59: RUNNABLE 72: RUNNABLE 51: RUNNABLE
  • 12.
    When SQL Serverwaits running suspendedrunnable 55: RUNNING >4ms 54: WAITFOR 56: ASYNC_... 70: PAGELA.. 59: RUNNABLE 72: RUNNABLE 51: RUNNABLE 68: RUNNABLE
  • 13.
    When SQL Serverwaits running suspendedrunnable 59: RUNNING 54: WAITFOR 56: ASYNC_... 70: PAGELA.. 72: RUNNABLE 51: RUNNABLE 68: RUNNABLE 55: RUNNABLE Quantum: 4ms SOS_SCHEDULER_YIELD
  • 14.
    CXPACKET • occurs whena parallel query is executing • Examine the long-running parallel query and tune it if necessary. • To ensure “efficient” parallelism, check that the statistics on tables and indexes used by the query are up to date.
  • 15.
    CXPACKET Transaction 1.000 records 1.000 records 1.000records 1.000 records CONTROLLER THREAD
  • 16.
    SOS_SCHEDULER_YIELD • This commonwait isn’t necessarily a problem • It indicates that SQL Server CPU scheduling is working efficiently. • RUNNING | SUSPENDED | RUNNABLE
  • 17.
    ASYNC_IO_COMPLETION • This occurswhen SQL Server is waiting for asynchronous I/O operations to finish • Look for additional waits in the top ranking • IO_COMPLETION • LOGMGR • WRITELOG • PAGEIOLATCH_*
  • 18.
    ASYNC_NETWORK_IO • Your applicationcode may not be retrieving data correctly! • There are very large data sets being requested by the client! • An application is requesting large amounts of data!
  • 19.
    THREADPOOL • SQL Serverassigns a scheduler to each CPU core to manage internal threads. • Some of these threads are worker threads that are assigned to query requests on a one-to-one basis. • If every worker thread is busy, additional requests can't be assigned straight away. • SQL Server attempts to manage requests more efficiently by creating a pool of worker threads, so the next available worker thread from the pool will pick up the task. • If every worker thread remains busy, SQL Server can't accept new requests and will hang. Cores 32 bit 64 bit <=4 256 512 5 – 8 288 576 9 – 16 352 704 32 480 960
  • 20.
    WRITELOG • This waitoccurs when data in the log cache is being flushed to disk. • Whenever a data page is updated, it’s written to the buffer cache and the log cache. • Data in the log cache is then written to the transaction log file on the physical disk once the transaction is complete.
  • 21.
    PAGEIOLATCH_?? • Buffer Latchfor a page object on the disk • DT (destroy) • EX (exclusive) • KP (keep) • SH (shared) • UP (update)
  • 22.
    PAGELATCH_?? • PAGELATCH_* latchesare lightweight, non-configurable internal locks used by SQL Server’s storage engine to protect concurrent access to pages in the BUFFER POOL
  • 23.
    Untersuchung des Betriebssystems •Physikalische / Virtuelle Umgebung • Wie viele CORES / RAM? • Gibt es mehrere HDD im System? • Wie sind die HDD formatiert?
  • 24.
    Betriebsumfeld des SQLServer • Wie viel RAM wird dem SQL Server zugeteilt? • Kann SQL Server alle Prozessoren verwenden? • Welche Sicherheitseinstellungen sind konfiguriert worden? • Windows Authentifizierung • Mixed Authentifizierung • Welche Berechtigungen hat das Dienstkonto? • Ist Instant File Initialization aktiviert? • Ist „Lock Pages in Memory“ aktiviert?
  • 25.
    Betriebsumfeld des SQLServer • Datenbankeinstellungen • FILLFACTOR • Standardverzeichnisse für Datenbanken • Erweiterte Konfigurationseinstellungen • Max Degree of Parallelism • AdHoc Workloads • Gibt es konfigurierte Ressource-Governour-Einstellungen
  • 26.
    Schwachstelle TEMPDB • Verwendungsarten •READ COMMITTED SNAPSHOT ISOLATION • HASH- /SORT-Operationen • Durch Benutzer angelegte temporäre Tabellen • Tabellenvariablen • … • Alle Operationen wollen Platz in TEMPDB reservieren • Reservierung erfolgt über PFS / GAM / SGAM
  • 27.
    Konfiguration der Datenbanken •Wie sind Datenbanken auf Storage verteilt? • Gibt es eine Trennung zwischen DATA und LOG? • Welchen Wachstumswert haben Datenbanken als Standard eingestellt? • Wie groß sind die Datenbanken? • Wie viel Platz ist in den Datenbanken noch frei?
  • 28.
    Dokumentation • Beginnen Siemit Informationen zu Ihrer Person • Beschreiben Sie den Grund für die Erstellung des Berichts • Gab es Probleme, die – plötzlich – aufgetreten sind? • Ist es eine initiale Untersuchung vor einem Go Live? • Weisen Sie darauf hin, dass eine Hardware- Untersuchung nicht Bestandteil der Dokumentation ist, wenn Sie keinen Zugriff auf die einzelnen Hardwarekomponenten haben • Legen Sie einen Struktur für Ihr Dokument fest, dass der Untersuchungsreihenfolge entspricht!
  • 29.
    Dokumentation • Begründungen durchFußnoten mit Verweisen zur Dokumentation begleiten • BITTE KEINE FORENBEITRÄGE! • Möglichst nur Links zum Hersteller