sql server效能調校

Click here to load reader

Upload: -

Post on 16-Feb-2017

2.783 views

Category:

Technology


0 download

TRANSCRIPT

SQL Server

SQL Server

SQL Server

?

NUMA

NUMA

SMBNUMA

IOPS(Input/Output Per Second)IOPSIOPS=1/(++)

IOPSSQLIO :IOMeter :SAN,SQLIOSim : SQL ServerI/OWmaRow :

(SSDSolid State Drive)SSDNANDHDDSSD

SSD

RamDisk,,:

-RamDiskANS-9010,Flash,

RamdiskBuffaloV.3.2.5.0FreeIE Cache,Dataram DiskV4.0.1.RC9Free/18.994GBImDisk Virtual DiskV1.6.0Free(),Primo RamdiskV5.6.029.95 ~69.95VSuite RamDisk,Qsoft RAM Disk5.3.2.1310~35 ,DriverSoftPerfect RAM Disk3.3.3FreeSuperSpeed RamDiskV11.7.975Free4GVSuite RamDiskV4.6.7531.1240Free/69.9511932bit

RamDisk

RAID(Redundant Array of Independent Disks)RAID

RAID

RAID

RIADRAID Workload RequirementRAID 10RAID 50RAID 5CapacityAvailabilitySequential ReadsSequential WritesRandom ReadsRandom WritesPerformance impact of drive failure or RAID reconstruction

RAID / / /

Primary(MDF)(NDF)(NDF)(NDF)(NDF)(NDF)(NDF)

LDF

:()InstanceInstance

(HAHigh Availability)

HA

Heartbeat

SQL ServerHA

:SQL Server(Hardware Compatibility List)ECCRAID(Network Interface Card)

-

B

A

Heartbeat

Single-InstanceActive/Passive,(),,,SQL ServerMultiple-InstanceActive/Active,(),,,,SQL ServerN+1Multiple-Instance(),Passive,,PassiveN+MN+1,MPassive

APSQL Native Client LibraryADO.Net 2.0(Principle),(Mirror),

TCP(Port),:

-

6435217(Principle)(Mirror)

DBLogLogDB

-

435214(Principle)(Mirror)

DBLogLogDB

SQL Server Agent,,

Witness

Primary

Secondary

Secondary

Secondary

Secondary

SQL Server 2012(AlwaysOn)

Windows Server Failover Clustering(WSFC)

Active/Active(VNN)-Active/ActiveConnStringStorage

SQL Server AlwaysOn(SQL FCI)()SMB(AG) DB: ,,Page,AP

FCI vs AG(SQL FCI)(AG)

AlwaysOnSQL Server 2012 AlwaysOn -

DB2DB1SQL ServerSQL Server

DB2DB1

SQL ServerSQL Server

SQL Server

SQL Server, ,SQL Server

SQL BrowserSQL Server,SQL Browser,UDP Port:1433,UDPSQL Browser;SQL Browser

masterSQL Server,,,modelSQL Server,,msdb()SQL Server,SQL Server,,tempdb,SQL Server,tempdb,

SQL ServerSQL Server:MDFNDFLDFSQL Server: ->->->->->/

SQL ServerMDFNDFLDF

SQL Server: MDF/NDFLDF: MDF: LDF

1

2

3

4,CheckPoint

SQL ServerSQL ServerB-Tree

bigintnumericBitdmallintDecimaldmallmoneyinttinyintmoney

Floatreal

datedatetimeoffsetdatetime2smalldatetimedatetimetime

()&charvarchartext

&(Unicode)ncharnvarcharntext

binaryvarbinaryimage

cursortimestamphierarchyIduniqueIdentifierSql_variantxmltable

()ByteINTTINYINT3 Bytes26 BytesINTSMALLINT2 Bytes48 BytesDATETIMESMALLDATETIME4 Bytes312 BytesNCHAR(10)CHAR(10)10 Bytes110 BytesVARCHAR(x)CHAR(X)2 Bytes714 Bytes: 50Bytes

: : :

(Collection)SQL Server:::,;,:,,,:

: Join: :

Simple,,,Full,,Bulk LoggedFull,,,

: : /

::Default, Check, Foreign Key, Null:Primary Key, Unique:Foreign Key, Check

:

SQL Server:SparseXML(SQL Server 2012)

I/O 1 Data Row = 200 Bytes(10 Bytes * 20 Columns)1 Data Page = 40 Data Rows (8K / 200 Bytes)Disk Space for Data Pages = 25,000 Data Pages (1,000,000 rows / 40 rows/Page) = 200 MB (8k & 25,000)I/O,

I/O 1 Index Row = 20 Bytes (10 Bytes * 2 Columns)1 Index Page = 400 Index Rows (8k / 20 Bytes)Disk Space for Index Pages = 2,500 Index Pages (1,000,000 rows / 400 rows/page) = 20 MB (8k * 2,500) I/O10%,

I/O 1 Index Row = 200 Bytes (10 Bytes * 20 Columns)1 Data Page = 40 Data Rows (8k / 200 Bytes)Disk Space for Data Pages = 25 Data Pages (1,000 rows / 40 rows/page) = 200KB (8k * 25)I/O0.1%,1%

I/O 1 Index Row = 20 Bytes (10 Bytes * 2 Columns)1 Index Page = 400 Index Rows (8k / 20 Bytes)Disk Space for Data Pages = 3 Index Pages (1,000 rows / 400 rows/page) = 24 KB (8k * 3)I/O12%

,

ProductIDProductNameCategoryID1Chai12Aniseed Syrup13Tofu24Pavlova3

,Group By/ Order By,,Join

: : : /:

- & SQL Server,8KB, ,,8KB,

: 50%:

0,,,Page

:

Schema

HRdboSelect * From HR.HumanResourceSelect * From HumanResourceHRdboHRdboSelect * From dbo.HumanResource

: ,: ,

SQL Server 2005 sysindexes rowmodctr SQL Server 2005/2008/2008 R2sys.sysrowsetcolumns rcmodified

: : SARG

Column Index(SQL Server 2012)

: :

SQL Server:

: CPU: OLTP,OLAP

Data BlockSQL ServerPage 8KB,8Page 64kBWindowsData Block8KB

Data Block: Data Block: RAID

T-SQL,DDL DML DCL

,: NoCount onsp

-:Create Procedure With RecompileAlter Procedure With Recompile:Exec [] With RecompileSP_Recompile:Sp_Recompile []

: : SQL,Exec:

,T-SQL,,DMLT-SQL,

-/

/

: Where: /,

,DDL,DML:

AfterInsert/Update/Delete,Instead OfInsert/Update/Delete,

: ,:

(View),,Select:

/SQL Server 2005,,,,,/,

//dm_exec_*dm_os_*dm_tran_*dm_io_*I/Odm_db_*

/dm_repl_*dm_broker_*SQL Server Brokerdm_fts_*Full Text Searchdm_qn_*Query Notificationsdm_clr_*CLR execution of managed code

(Atomicity)(Consistency)(Isolation)(Durability)SQL Server(Read UnCommitted)(Read Committed)(Repeatable Read)(Serializable)Read Committed using Statement-level Snapshot() Snapshot

Read_Committed_SnapshotOn

Allow_Snapshot_IsolationOn

(Dirty Read)(Phantom)

: ,,,

(S),: Select(U),(X),: Insert, Update Delete: (IS)(IX)(SIX): (Sch-M)(Sch-S)(BU),TabLockSerializable,,,Serializable

,::SQL Server,:sys.dm_exec_requests, sys.dm_tran_locksSQL Profiler:Lock,Deadlock, Deadlock Chain

: : :

Performance CounterSQL Profiler

Performance Counter

MemoryPages/Sec