jsanchez - sql server best practices
TRANSCRIPT
-
8/6/2019 JSanchez - SQL Server Best Practices
1/105
Jorge SnchezJorge Snchez
Senior Technology SolutionsSenior Technology Solutions ProfessionalProfessional
Enterprise DataEnterprise Data PlatformSpecialistPlatformSpecialist
MicrosoftMicrosoft Multi Country AmericasMulti Country Americas
[email protected]@microsoft.com
CelCel. (787) 487. (787) 487--29772977
-
8/6/2019 JSanchez - SQL Server Best Practices
2/105
This Magic Quadrant graphic was published by Gartner, Inc. as part of a larger research note and should beevaluated in the context of the entire report. The Gartner report is available upon request from JenniferPisani, Microsoft.
The Magic Quadrant is copyrighted February, 2008 by Gartner, Inc. and is reused with permission. The Magic Quadrant is a graphical representation of a marketplace at and for a specific timeperiod. It depicts Gartners analysis of how certain vendors measure against criteria for that marketplace, as defined by Gartner. Gartner does not endorse any vendor, product or service depictedin the Magic Quadrant, and does not advise technology users to select only those vendors placed in the Leaders quadrant. The Magic Quadrant is intended solely as a research tool, and is notmeant to be a specific guide to action. Gartner disclaims all warranties, express or implied, with respect to this research, including any warranties of merchantability or fitness for a particularpurpose.
Gartner, Inc. Gartner Magic Quadrant for Business Intelligence Platforms, 2008, JamesRichardson et al., Feb. 1, 2008
-
8/6/2019 JSanchez - SQL Server Best Practices
3/105
http://mediaproducts.gartner.com/reprints/microsoft/vol4/article2/article2.html
-
8/6/2019 JSanchez - SQL Server Best Practices
4/105
http://www.olapreport.com/market.htm#shares
Microsoft stands in 1st
place, almost at double fromthe next OLAP vendor.
-
8/6/2019 JSanchez - SQL Server Best Practices
5/105
NASDAQNASDAQ 5,0005,000 txstxs/sec!!!/sec!!!
-
8/6/2019 JSanchez - SQL Server Best Practices
6/105
BOVESPABOVESPA Mainframe MigrationMainframe Migration
-
8/6/2019 JSanchez - SQL Server Best Practices
7/105
DELIVERY
END USER TOOLS & PERFORMANCE MANAGEMENT APPS
(Reports, KPIs, Scorecards, Dashboards, Analytics, Forecasting, Budgeting, Financial Consolidations)
BI PLATFORM
(RDBMS, High Availability, Partitioning, Encryption, Compression (Data & Backup), Auditing, Policies, LoadBalancing, Resource Governor, IntelliSense, Spatial Data, Query Plan Guides, Performance Reports, Indexed Views, Filtered
Indexes, NULL Sparse Columns, HierarchyID Data Type, Change Data Capture, ETL, Data Profiling, DataCleansing, DW, Cubes, OLAP, Data Mining Algorithms, Web Reports, Ad-hoc Reports)
Mainframe/
Departmental
SystemsOt ers
-
8/6/2019 JSanchez - SQL Server Best Practices
8/105
0
5
10
15
2025
30
35
40
45
2002 2003 2004 2005 2006 2007 2008
31
10
41
8
18
2
18
24
31
0 0
2
00
6 5
14
4
22
3
85
911
14
10
2
Oracle SQLServer DB2 mySQL
SQL Server is More SecureSQL Server is More SecureNumber ofNumber ofSecurity BulletinsSecurity Bulletins
Notes: Updated as of 08/06/2008.
Vulnerabilities are included for:SQL Server(any version), Oracle (8i, 9i, 9i, 10g, 11g),IBM (Universal Database), mySQL (mySQL)
Source: National Institute ofStandards and Technology (NIST)National Vulnerability Database (http://nvd.nist.gov/statistics.cfm)
-
8/6/2019 JSanchez - SQL Server Best Practices
9/105
0
5
10
15
2025
30
35
40
45
2002 2003 2004 2005 2006 2007 2008
31
10
41
8
18
2
18
24
31
0 0
2
00
6 5
14
4
22
3
85
911
14
10
2
Oracle SQLServer DB2 mySQL
SQL Server is More SecureSQL Server is More SecureNumber ofNumber ofSecurity BulletinsSecurity Bulletins
Notes: Updated as of 08/06/2008.
Vulnerabilities are included for:SQL Server(any version), Oracle (8i, 9i, 9i, 10g, 11g),IBM (Universal Database), mySQL (mySQL)
SQL Server with the LOWESTsecurityadvisories in 6 years!!!
Source: National Institute ofStandards and Technology (NIST)National Vulnerability Database (http://nvd.nist.gov/statistics.cfm)
-
8/6/2019 JSanchez - SQL Server Best Practices
10/105
Base ProductBase Product
$ 25K $ 40K $ 25K
Oracle 10gIBM DB2
-
8/6/2019 JSanchez - SQL Server Best Practices
11/105
-
8/6/2019 JSanchez - SQL Server Best Practices
12/105
Base ProductBase Product
ManageabilityManageability
(included)(included)
$ 25K $ 35K$ 154.5K$ 56K$ 116K
BusinessBusinessIntelligenceIntelligence
OLAP$20k
Mining$20k
BI Bundle$20k
DB2 OLAP$35K
DB2Warehouse
$75K
Cube Views$9.5K
-
8/6/2019 JSanchez - SQL Server Best Practices
13/105
Base ProductBase Product
ManageabilityManageability
(included)(included)
$ 25K $ 154.5K$ 164.5K$ 232K$ 116K
BusinessBusinessIntelligenceIntelligence
HighA
vailabilityHighA
vailability
Data Guard$116K Recovery
Expert$10k
-
8/6/2019 JSanchez - SQL Server Best Practices
14/105
Base ProductBase Product
ManageabilityManageability
(included)(included)
High AvailabilityHigh Availability
BusinessBusiness
IntelligenceIntelligence
MultiMulti--corecore
$348k -$464k$ 232K$ 25K $ 164.5K$ 329K
$164.5K$116K -$232K
-
8/6/2019 JSanchez - SQL Server Best Practices
15/105
-
8/6/2019 JSanchez - SQL Server Best Practices
16/105
Office/SharePoint
Reports Portal
Analytic Platform
OLTP
ERP
Line OfBusiness
Apps
CRM
BI Development and Management Tools SQL Server Management Tools
.NET Framework and Development Tools
Microsoft Data Factory ArchitectureMicrosoft Data Factory Architecture
Devices
Analytical Applications
Data Analysis(OLAP,
Data Mining)
DataTransformation
(ETL)
ODS
DW,Marts
StrategicTactical
SQL Server 2008RDBMS
SQL Server 2008Integration Services
SQL Server 2008RDBMS
SQL Server 2008AnalysisServices
SQL Server 2008Reporting Services
Microsoft OfficeExcel 2007
Microsoft OfficePerformancePoint
Server 2007
MicrosoftProClarity
-
8/6/2019 JSanchez - SQL Server Best Practices
17/105
SQL ServerSQL Server
Installation and ConfigurationInstallation and ConfigurationBest PracticesBest Practices
1. 64-bit Editions2. 32-bit Editions: Configure Memory
3. Volume Offset Alignment4. SQLIO and SQLIOSim Utilities5. Enterprise vs.Standard Editions6. Local Installation Policies7. Tempdb Database Relocation8. SQL Server Reports9. Stripe tempdb, UserData and Log Files10. Instance Configuration
11. Simple Recovery Model12. Check Database Integrity and Update Statistics13. Stored Procedures14. Indexes15. Profiler + Database Engine TuningAdvisor16. Best Practices Analyzer(BPA)17. SQL CustomerAdvisory Team (SQL CAT)18. SQL Server 2008 Performance New Features
-
8/6/2019 JSanchez - SQL Server Best Practices
18/105
Installation Tip #1Installation Tip #16464--bit Editionsbit Editions
Your first option should be SQL Server for64Your first option should be SQL Server for64--bit machines unlessbit machines unlessthe frontthe front--end application has been certified only for 32end application has been certified only for 32--bitbit
Why?Why?
6464--bits has more addressable memory = 16,386 TB (16bits has more addressable memory = 16,386 TB (16ExabytesExabytes), instead of x86 architecture which uses directly up to 4GB), instead of x86 architecture which uses directly up to 4GBRAM (64GB RAM with /PAE & AWE)RAM (64GB RAM with /PAE & AWE)
PAE is a function which enables Windows 2008/2003/2000 to show more memory toPAE is a function which enables Windows 2008/2003/2000 to show more memory toprograms (the memory it has requested is actually in the page file)programs (the memory it has requested is actually in the page file)
AWE API enables a program to use more than 4GB memory (nonAWE API enables a program to use more than 4GB memory (non--pageablepageable and is onlyand is onlyaccessible to that program)accessible to that program)
SQL Server has two 64SQL Server has two 64--bit editions compiled natively:bit editions compiled natively:
X64X64 andand IA64IA64 (Itanium)(Itanium)
-
8/6/2019 JSanchez - SQL Server Best Practices
19/105
Installation Tip #1Installation Tip #16464--bit Editions (cont.)bit Editions (cont.)
Deploy Windows Server and SQL Server in the same architectureDeploy Windows Server and SQL Server in the same architecture
Windows Server 2008/2003Windows Server 2008/2003 for x64for x64 + SQL Server 2008/2005+ SQL Server 2008/2005 for x64for x64
Windows Server 2008/2003Windows Server 2008/2003 for IA64for IA64 + SQL Server 2008/2005+ SQL Server 2008/2005 for IA64for IA64
Install the latest service pack forWindows Server and SQL ServerInstall the latest service pack forWindows Server and SQL Server
Service Pack up to OctService Pack up to Oct--20082008Windows Server 2008Windows Server 2008 RTMRTM (has SP1 already installed)(has SP1 already installed)
Windows Server 2003Windows Server 2003 SP2SP2 (Standard, Enterprise, Datacenter)(Standard, Enterprise, Datacenter)
Windows Server 2000Windows Server 2000 SP4SP4 (Standard, Advanced, Datacenter)(Standard, Advanced, Datacenter)
SQL
Server 2008
SQL
Server 2008 RTMRTM
SQL Server 2005SQL Server 2005 SP2SP2
SQL Server 2000SQL Server 2000 SP4SP4
All SQL Server Engines in 2008 and 2005 (RBDMS, IntegrationAll SQL Server Engines in 2008 and 2005 (RBDMS, IntegrationServices, Analysis Services, Reporting Services) for64Services, Analysis Services, Reporting Services) for64--bits platformbits platformare compiled natively and each one will use all memory availableare compiled natively and each one will use all memory available
-
8/6/2019 JSanchez - SQL Server Best Practices
20/105
Installation Tip #2Installation Tip #23232--bit Editions: Configure Memorybit Editions: Configure Memory
ConfigureConfigure Windows Server (v2003 and v2000)Windows Server (v2003 and v2000) to use memoryto use memoryefficientlyefficiently
Change the Boot.ini file to activateChange the Boot.ini file to activate
Systems withSystems with less than 4GB RAMless than 4GB RAM useuse/3GB only!/3GB only!/3GB will instruct Windows to use data cached no more than 16GB RAM and let applications to use/3GB will instruct Windows to use data cached no more than 16GB RAM and let applications to use
up to 3GB RAM. Available in Windows Server 2008 & 2003 (Datacenter, Enterprise, Standard X64)up to 3GB RAM. Available in Windows Server 2008 & 2003 (Datacenter, Enterprise, Standard X64)and Windows Server 2000 (Datacenter and Advanced)and Windows Server 2000 (Datacenter and Advanced)
Note: Windows Server 2008/2003/2000 Standard Edition has 4GB RAM maximum; if the machineNote: Windows Server 2008/2003/2000 Standard Edition has 4GB RAM maximum; if the machinehas greater than 4GB RAM, Windows ServerStandard Edition will not use it! In this case, upgradehas greater than 4GB RAM, Windows ServerStandard Edition will not use it! In this case, upgrade(at least) to Windows Server 2008/2003 (R2) Enterprise orStandard X64(at least) to Windows Server 2008/2003 (R2) Enterprise orStandard X64
Systems withSystems with between 4GB RAM and 16GB RAMbetween 4GB RAM and 16GB RAM /3GB + /PAE + AWE/3GB + /PAE + AWE/PAE will instruct Windows and SQL Server to use address space higher than 4GB to map data/PAE will instruct Windows and SQL Server to use address space higher than 4GB to map data(requires reboot)(requires reboot)
This option also requires (at least) Windows Server 2008 Enterprise , Windows Server 2003 (R2)This option also requires (at least) Windows Server 2008 Enterprise , Windows Server 2003 (R2)Enterprise, orWindows Server 2000 Advanced EditionsEnterprise, orWindows Server 2000 Advanced Editions
Systems withSystems with greater than 16GB RAMgreater than 16GB RAM /PAE + AWE (Dont use /3GB!)/PAE + AWE (Dont use /3GB!)Note: In this case, dont use /3GB since it will limit memory up to 16GB RAM.Note: In this case, dont use /3GB since it will limit memory up to 16GB RAM.
For more info:For more info: http://blogs.technet.com/vipulshah/archive/2007/05/10/3gbhttp://blogs.technet.com/vipulshah/archive/2007/05/10/3gb--paepae--andand--aweawe--onon--3232--bitbit--systems.aspxsystems.aspx
In x86, only the RDBMS is the only SQL Server engine which uses /PAE andIn x86, only the RDBMS is the only SQL Server engine which uses /PAE and
AWE; (SSIS, SSAS, and SSRS will use up to 3GB RAM).AWE; (SSIS, SSAS, and SSRS will use up to 3GB RAM).
-
8/6/2019 JSanchez - SQL Server Best Practices
21/105
Installation Tip #2Installation Tip #23232--bit Editions: Configure Memory (cont.)bit Editions: Configure Memory (cont.)
ConfigureConfigure SQL ServerSQL Serverto use memoryto use memory
Systems withSystems with less than 4GB RAMless than 4GB RAM useuse/3GB only!/3GB only!
Dont have to configure SQL Server 2008/2005/2000 to work within RAM 4GB or lessDont have to configure SQL Server 2008/2005/2000 to work within RAM 4GB or less
S
ystems withS
ystems with between 4GB RAM and 16GB RAMbetween 4GB RAM and 16GB RAM
/3GB + /PAE +/
3GB + /PAE +AWEAWE andand Systems withSystems with greater than 16GB RAMgreater than 16GB RAM /PAE + AWE (Dont/PAE + AWE (Dont
use /3GB!)use /3GB!)
To enable Address Windowing Extensions (AWE) for Microsoft SQLTo enable Address Windowing Extensions (AWE) for Microsoft SQLServer, you must run the SQL ServerDatabase Engine under aServer, you must run the SQL ServerDatabase Engine under aMicrosoftWindows account that has been assigned theMicrosoftWindows account that has been assigned the Lock PagesLock Pages
in Memoryin Memory optionoptionStart / Administrative Tools / Local Security Policy / Local Policies /Start / Administrative Tools / Local Security Policy / Local Policies /User Rights AssignmentUser Rights Assignment
Lock Pages In MemoryLock Pages In Memory = [YourSQL ServerService Account; ex.= [YourSQL ServerService Account; ex.DomainDomain\\SQLAdminSQLAdmin]]
-
8/6/2019 JSanchez - SQL Server Best Practices
22/105
Installation Tip #2Installation Tip #23232--bit Editions: Configure Memory (cont.)bit Editions: Configure Memory (cont.)
You have to turn AWE ONYou have to turn AWE ON
InIn SQL Server 2008/2005SQL Server 2008/2005
Go toGo to Server PropertiesServer Properties / [/ [MemoryMemory] page, and select] page, and select Use AWE toUse AWE toallocate memoryallocate memory
RestartRestart thethe SQL Server serviceSQL Server service
InIn SQL Server 2000SQL Server 2000
EXECUTE sp_configure 'show advanced options', 1RECONFIGUREEXECUTE sp_configure 'awe enabled, 1RECONFIGURE--[Restart the SQL Server service]EXECUTE sp_configure 'show advanced options', 0RECONFIGURE
-
8/6/2019 JSanchez - SQL Server Best Practices
23/105
Installation Tip #2Installation Tip #23232--bit Editions: Configure Memory (cont.)bit Editions: Configure Memory (cont.)
If you need to use SQL Server 2008/2005/2000 inIf you need to use SQL Server 2008/2005/2000 in 3232--bit Windowsbit Windows
Do NOT run SQL Server 32Do NOT run SQL Server 32--bit on Window Server64bit on Window Server64--bit (this is callbit (this is callWindowWindow--onon--Window, orWOW); SQL Server will run with lessWindow, orWOW); SQL Server will run with lessperformanceperformance
In this case, be sure to use Windows Server 2008/2003 for X86(32In this case, be sure to use Windows Server 2008/2003 for X86(32--bit)bit)
NOTENOTEWINDOWSSERVER 2008/2003/2000 STANDARD EDITION HASAWINDOWSSERVER 2008/2003/2000 STANDARD EDITION HASAMAXIMUM RAM UP TO 4GB! (See next slide)MAXIMUM RAM UP TO 4GB! (See next slide) TO USE /PAE ANDAWE TO USE /PAE ANDAWEYOUNEED RAM > 4GB!YOUNEED RAM > 4GB!
For more than 4GB RAM, you need to change the OS(at least) to WindowsFor more than 4GB RAM, you need to change the OS(at least) to WindowsS
erver 2008/2003S
tandard Edition for X64 orW
indowsS
erver 2008/2003S
erver 2008/2003S
tandard Edition for X64 orW
indowsS
erver 2008/2003X86 Enterprise EditionX86 Enterprise Edition
-
8/6/2019 JSanchez - SQL Server Best Practices
24/105
Installation Tip #2Installation Tip #23232--bit Editions: Configure Memory (cont.)bit Editions: Configure Memory (cont.)
http://msdn.microsoft.com/en-us/library/aa366778.aspx
Maximum RAM
Windows Server Edition 32-bit 64-bit
2008 (RTM) Datacenter 64GB 2TB
2008 (RTM) Enterprise 64GB 2TB
2008 (RTM) Standard 4GB 32GB
2003 (R2) Datacenter 128GB 1TB2003 (R2) Enterprise 64GB 1TB
2003 (R2) Standard 4GB 32GB
2003 (SP1) Datacenter 128GB 1TB
2003 (SP1) Enterprise 64GB 1TB
2003 (SP1) Standard 4GB 32GB
2003 (RTM) Datacenter 128GB 512GB2003 (RTM) Enterprise 32GB 64GB
2003 (RTM) Standard 4GB 16GB
2000 (RTM) Datacenter 32GB X
2000 (RTM) Advanced 8GB X
2000 (RTM) Standard 4GB X
-
8/6/2019 JSanchez - SQL Server Best Practices
25/105
Installation Tip #3Installation Tip #3Volume Offset AlignmentVolume Offset Alignment
It may represent from 10%It may represent from 10%--30% performance difference!30% performance difference!
Windows Server 2003Windows Server 2003
Use System Information (msinfo32.exe) to determine if theUse System Information (msinfo32.exe) to determine if the Partition StartingPartition StartingOffsetOffset from each volume =from each volume = 1,048,576 bytes1,048,576 bytes..
Note: msinfo32.exe requires theNote: msinfo32.exe requires the Help and SupportHelp and Support WindowsWindows
Service. If you need to install it, run the following script:Service. If you need to install it, run the following script:cdcd %%windirwindir%%\\PCHealthPCHealth\\HelpCtrHelpCtr\\BinariesBinaries\\
start /wstart /w helpsvchelpsvc //svchostsvchost netsvcsnetsvcs /install/install
After installation, go toAfter installation, go to ServicesServices and start theand start the Help and SupportHelp and Support service.service.
More InfoMore Info http://blogs.technet.com/sbs/archive/2007/03/20/helphttp://blogs.technet.com/sbs/archive/2007/03/20/help--andand--supportsupport--serviceservice--missingmissing--afterafter--installinginstalling--windowswindows--20032003--serviceservice--packpack--2.aspx2.aspx
If the Starting Offset is less (ex. 32,256 bytes), then useIf the Starting Offset is less (ex. 32,256 bytes), then use DISKPART.EXEDISKPART.EXE (in(in
command prompt) to recommand prompt) to re--create this volume but using an alignment of 1,024create this volume but using an alignment of 1,024Format the volume usingFormat the volume using NTFSNTFS with awith a Allocation Unit Size = 64 KBAllocation Unit Size = 64 KB
To determine the Allocation Unit Size from a already formatted volume, run:To determine the Allocation Unit Size from a already formatted volume, run:
fsutilfsutil fsinfofsinfo ntfsinfontfsinfo [[drive_letterdrive_letter]:]:
For more information:For more information:
Support Site:Support Site: http://support.microsoft.com/default.aspx?scid=kb;ENhttp://support.microsoft.com/default.aspx?scid=kb;EN--US;929491US;929491
Diskpart
Diskpart:: http://technet.microsoft.com/enhttp://technet.microsoft.com/en--us/library/cc773140.aspxus/library/cc773140.aspx
-
8/6/2019 JSanchez - SQL Server Best Practices
26/105
Disk orArray Volume AlignmentDisk orArray Volume Alignment
Windows Server 2008Windows Server 2008
This version (as well as Windows Vista) aligns volumes automatically.This version (as well as Windows Vista) aligns volumes automatically.
Format the volume usingFormat the volume using NTFSNTFS with awith a Allocation Unit Size = 64 KBAllocation Unit Size = 64 KBNOTE:NOTE: DO NOTDO NOT FORMAT WITH THEFORMAT WITH THE COMPRESSCOMPRESS OPTIONOPTION
Installation Tip #3Installation Tip #3Volume Offset AlignmentVolume Offset Alignment
-
8/6/2019 JSanchez - SQL Server Best Practices
27/105
To determine if theVolume Offset
Alignment is differentthan the default of32K, run msinfo32.exe
-
8/6/2019 JSanchez - SQL Server Best Practices
28/105
Notice that volume has aPartition Starting Offset of32,256(31.5K) bytesinstead of 1,048,576 bytes(1024K)
-
8/6/2019 JSanchez - SQL Server Best Practices
29/105
Notice that the volume hasbeen formatted with thedefault of 4096(4K) BytesPer Clusterinstead of
65536(64K)
Use the following command to determine if the volume has been formatted as 64K:
C:\fsutil fsinfo ntfsinfo [drive_letter]:
-
8/6/2019 JSanchez - SQL Server Best Practices
30/105
To change the Volume OffsetAlignment to 1024K, run diskpart in aseparate Command Prompt window,
but CAREFULL DISKPARTWILLERASE THE VOLUME ANDALL DATAIN IT! Do backup before if necessary.
-
8/6/2019 JSanchez - SQL Server Best Practices
31/105
Notice that now Disk 1 has
the focus (look for the *)
Use Align=1024 in theCreate Partition command
Use Unit=64K in theFormat command
-
8/6/2019 JSanchez - SQL Server Best Practices
32/105
Notice that the volumenow has a PartitionStarting Offset of
1,048,576 bytes (1024K)
-
8/6/2019 JSanchez - SQL Server Best Practices
33/105
Notice that the volumehas been formatted as64K (65536)
Use the following command to determine if the volume has been formatted as 64K:
C:\fsutil fsinfo ntfsinfo [drive_letter]:
-
8/6/2019 JSanchez - SQL Server Best Practices
34/105
-
8/6/2019 JSanchez - SQL Server Best Practices
35/105
-
8/6/2019 JSanchez - SQL Server Best Practices
36/105
-
8/6/2019 JSanchez - SQL Server Best Practices
37/105
-
8/6/2019 JSanchez - SQL Server Best Practices
38/105
-
8/6/2019 JSanchez - SQL Server Best Practices
39/105
Format the volumein NTFS with an
AllocationUnit Size= 64 KB
-
8/6/2019 JSanchez - SQL Server Best Practices
40/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim UtilitiesUtilities
SQLIO.exeSQLIO.exe is a stress test tool to determine the hardwaresis a stress test tool to determine the hardwares Input/OutputInput/Outputcapacity of a disk subsystem in order to tune it for optimal performancecapacity of a disk subsystem in order to tune it for optimal performanceBEFORE deploying SQL ServerBEFORE deploying SQL Server
Note: SQLIO.exe will not simulate SQL Server I/O patterns, instead it will test I/ONote: SQLIO.exe will not simulate SQL Server I/O patterns, instead it will test I/O
typestypes (Random Reads, RandomW
rites,S
equential Reads,S
equentialW
rites)(Random Reads, RandomW
rites,S
equential Reads,S
equentialW
rites)andand sizessizes (1K, 2K, 4K, 8K, 64K, 128K, 256K)(1K, 2K, 4K, 8K, 64K, 128K, 256K)
SQLIOSim.exeSQLIOSim.exe is a SQL Server stress test tool utility (upgraded from the oldis a SQL Server stress test tool utility (upgraded from the oldSQLIOStressSQLIOStress) which) which simulates SQL Serversimulates SQL Server(versions 2005, 2000, and 7.0)(versions 2005, 2000, and 7.0)read, write, checkpoint, backup, sort, and readread, write, checkpoint, backup, sort, and read--aheadahead activitiesactivities
ForDownloadsForDownloads
SQLIO UtilitySQLIO Utility
http://www.microsoft.com/downloads/details.aspx?familyid=9A8B005Bhttp://www.microsoft.com/downloads/details.aspx?familyid=9A8B005B--84E484E4--4F244F24--8D658D65--CB53442D9E19&displaylang=enCB53442D9E19&displaylang=en
SQLIOSimSQLIOSim UtilityUtility
http://support.microsoft.com/kb/231619http://support.microsoft.com/kb/231619
http://sqlblog.com/blogs/linchi_shea/archive/2007/02/21/parse-the-sqlio-exe-output.aspx
-
8/6/2019 JSanchez - SQL Server Best Practices
41/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
To run SQLIO.exe you need to 1) copy in a folder the sqlio.exe file, then 2)To run SQLIO.exe you need to 1) copy in a folder the sqlio.exe file, then 2)create a text file called PARAM.txt, then 3) create a batch file (for example:create a text file called PARAM.txt, then 3) create a batch file (for example:RUNTEST.cmd) to automate all testsRUNTEST.cmd) to automate all tests
TheThe PARAM.txtPARAM.txt file will contain the volume references to be examined, thefile will contain the volume references to be examined, the
name of the test file to be created, how many threads to be used (per testname of the test file to be created, how many threads to be used (per testfile; it should be one per CPU), mask (use 0x0), and size of the test filefile; it should be one per CPU), mask (use 0x0), and size of the test file
[Path to test file] [Number of CPUs] 0x0 [Size of test file in MB][Path to test file] [Number of CPUs] 0x0 [Size of test file in MB]
For exampleFor example m:m:\\datadata\\testfile.dat 2 0x0 100testfile.dat 2 0x0 100
The batch file (The batch file (RUNTEST.cmdRUNTEST.cmd) should) should includeinclude allall teststests
--k[Test]k[Test] s[Duration]s[Duration] f[I/O Type]f[I/O Type] o[Requests]o[Requests] b[Size]b[Size] LSLS F[file] [seconds]F[file] [seconds]
NoteNote Wait at least one (1) minute between tests to let the I/O system return to Wait at least one (1) minute between tests to let the I/O system return toidleidle
sqliosqlio --kWkW --s10s10 --frandomfrandom --o8o8 b2b2 --LSLS --Fparam.txt timeout /T 60 > Random_Writes_2K.txtFparam.txt timeout /T 60 > Random_Writes_2K.txtsqliosqlio --kRkR --s10s10 --frandomfrandom --o8o8 b4b4 --LSLS --Fparam.txt timeout /T 60 > Random_Reads_4K.txtFparam.txt timeout /T 60 > Random_Reads_4K.txtsqliosqlio --kWkW --s10s10 --fsequentialfsequential --o8o8 b8b8 --LSLS --Fparam.txt timeout /T 60 > Sequential_Writes_8K.txtFparam.txt timeout /T 60 > Sequential_Writes_8K.txt
sqliosqlio --kRkR --s10s10 --fsequentialfsequential --o8o8 b64b64 --LSLS --Fparam.txt timeout /T 60 > Sequential_Reads_64K.txtFparam.txt timeout /T 60 > Sequential_Reads_64K.txt
-
8/6/2019 JSanchez - SQL Server Best Practices
42/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
-
8/6/2019 JSanchez - SQL Server Best Practices
43/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
-
8/6/2019 JSanchez - SQL Server Best Practices
44/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
Look on each report for theThroughput and Latency metrics:
IOs/sec, MBs/secMin_Latency(ms), Avg_Latency(ms),
Max_Latency(ms)
ThroughputThroughput: the amount of activity a system can sustain over time: the amount of activity a system can sustain over timeLatencyLatency: the amount of time it takes for a data change to be propagated between nodes: the amount of time it takes for a data change to be propagated between nodes
-
8/6/2019 JSanchez - SQL Server Best Practices
45/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
Regarding SQLIOSimBe sure to have sqliosim.exe andsqliosim.com in a separate folder;
then run sqliosim.exe.
-
8/6/2019 JSanchez - SQL Server Best Practices
46/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
Press F11 to configure which dataand log files to stress test
-
8/6/2019 JSanchez - SQL Server Best Practices
47/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
Press F12 to start data and logfiles stress tests
-
8/6/2019 JSanchez - SQL Server Best Practices
48/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
After all test are finished, evaluatethe results report and watch for
error and warning messages
-
8/6/2019 JSanchez - SQL Server Best Practices
49/105
Installation Tip #4Installation Tip #4SQLIO andSQLIO and SQLIOSimSQLIOSim Utilities (cont.)Utilities (cont.)
-
8/6/2019 JSanchez - SQL Server Best Practices
50/105
Installation Tip #5Installation Tip #5SQL Server DBMS Enterprise vs. StandardSQL Server DBMS Enterprise vs. Standard
Note: AWE support in Standard Edition is available in x64 only.
http://www.microsoft.com/sql/editions/enterprise/comparison.mspx
-
8/6/2019 JSanchez - SQL Server Best Practices
51/105
Installation Tip #5Installation Tip #5SQL Server DBMS Enterprise vs. StandardSQL Server DBMS Enterprise vs. Standard
http://download.microsoft.com/download/2/d/f/2df66c0c-fff2-4f2e-b739-bf4581cee533/SQLServer%202008CompareEnterpriseStandard.pdf
-
8/6/2019 JSanchez - SQL Server Best Practices
52/105
Installation Tip #5Installation Tip #5SQL Server DBMS Enterprise vs. StandardSQL Server DBMS Enterprise vs. Standard
http://download.microsoft.com/download/2/d/f/2df66c0c-fff2-4f2e-b739-bf4581cee533/SQLServer%202008CompareEnterpriseStandard.pdf
-
8/6/2019 JSanchez - SQL Server Best Practices
53/105
Installation Tip #5Installation Tip #5SQL Server DBMS Enterprise vs. StandardSQL Server DBMS Enterprise vs. Standard
http://download.microsoft.com/download/2/d/f/2df66c0c-fff2-4f2e-b739-bf4581cee533/SQLServer%202008CompareEnterpriseStandard.pdf
SQL S R lSQL S R l
-
8/6/2019 JSanchez - SQL Server Best Practices
54/105
SQL Server ReleasesSQL Server ReleasesSQL Server Releases Versionhttp://support.microsoft.com/kb/321185/en-us
SQL Server 2008
SQL Server 2008 RTM 10.0.1600
SQL Server 2005
SQL Server 2005 SP2 9.00.3073SQL Server 2005 SP1 9.00.2047
SQL Server 2005 RTM 9.00.1399
SQL Server 2000
SQL Server 2000 SP4 8.00.2039
SQL Server 2000 SP3a 8.00.760
SQL Server 2000 SP3 8.00.760
SQL Server 2000 SP2 8.00.534
SQL Server 2000 SP1 8.00.384SQL Server 2000 RTM 8.00.194
SQL Server 7.0
SQL Server 7.0 SP4 7.00.1063
SQL Server 7.0 SP3 7.00.961
SQL Server 7.0 SP2 7.00.842
SQL Server 7.0 SP1 7.00.699
SQL Server 7.0 RTM 7.00.623
SQL Server 6.5
SQL Server6.5 SP5a Update 6.50.479
SQL Server6.5 SP5a 6.50.416
SQL Server6.5 SP5 6.50.415
SQL Server6.5 SP4 6.50.281
SQL Server6.5 SP3 6.50.258
SQL Server6.5 SP2 6.50.240
SQL Server6.5 SP1 6.50.213SQL Server6.5 RTM 6.50.201
SQL Server Version TSQL Script
SQL Server 2008/2005SELECT[ProductVersion] = SERVERPROPERTY('productversion'),[ProductLevel] =SERVERPROPERTY ('productlevel'),[Edition] = SERVERPROPERTY ('edition')
SQL Server 2000S
ELECT[ProductVersion] = SERVERPROPERTY('productversion'),[ProductLevel] =SERVERPROPERTY ('productlevel'),[Edition] = SERVERPROPERTY ('edition')
SQL Server 7.0SELECT @@VERSION
SQL Server 6.5SELECT @@VERSION
-
8/6/2019 JSanchez - SQL Server Best Practices
55/105
Installation Tip #6Installation Tip #6Local Installation PoliciesLocal Installation Policies
Local Security PolicyLocal Security Policy
RetainRetain Operating System fromOperating System from pagingpaging its memory to diskits memory to disk
Start / Administrative Tools / Local Security Policy / Local Policies /Start / Administrative Tools / Local Security Policy / Local Policies / UserUserRights AssignmentRights Assignment
Lock Pages In MemoryLock Pages In Memory = [YourSQL ServerService Account; ex.= [YourSQL ServerService Account; ex.DomainDomain\\SQLAdminSQLAdmin]]
Enable InstantEnable Instant File InitializationFile Initialization forNew Data Files or Extending DataforNew Data Files or Extending DataFilesFiles
Start / Administrative Tools / Local Security Policy / Local Policies /Start / Administrative Tools / Local Security Policy / Local Policies / UserUser
Rights AssignmentRights Assignment
Perform Volume Maintenance TasksPerform Volume Maintenance Tasks = [YourSQL ServerService Account;= [YourSQL ServerService Account;ex. Domainex. Domain\\SQLAdminSQLAdmin]]
Note: Instant File Initialization is available only in Windows Server 2003 orNote: Instant File Initialization is available only in Windows Server 2003 orlaterlater
-
8/6/2019 JSanchez - SQL Server Best Practices
56/105
Installation Tip #7Installation Tip #7tempdbtempdb Database RelocationDatabase Relocation
tempdbtempdb is used foris used for
User ObjectsUser Objects
UserUser--defined tables and indexes, system tables and indexes, globaldefined tables and indexes, system tables and indexes, globaltemporary tables and indexes, local temporary tables andtemporary tables and indexes, local temporary tables andindexes, table variables, tables returned in tableindexes, table variables, tables returned in table--valued functionsvalued functions
Internal ObjectsInternal Objects
Cursors, Hash Joins, Hash Aggregates, Sorts, GROUP BY, ORDERCursors, Hash Joins, Hash Aggregates, Sorts, GROUP BY, ORDERBY, UNION queries, DBCCBY, UNION queries, DBCCcommands, Indexes, LOB, MARS, Stored Procedurescommands, Indexes, LOB, MARS, Stored Procedures
Version StoresVersion Stores
Thats whyThats why tempdbtempdb filesfiles should beshould be relocatedrelocated into itsinto its own dedicatedown dedicatedstoragestorage
-
8/6/2019 JSanchez - SQL Server Best Practices
57/105
Installation Tip #7Installation Tip #7tempdbtempdb Database Relocation (cont.)Database Relocation (cont.)
MovingMoving tempdbtempdb Script inScript in SQL Server 2008/2005SQL Server 2008/2005::
SELECT
[tempdb Logical Filename] = CAST([Name] AS VARCHAR(30))
,[Usage] = (case [type_desc]when 'LOG' then 'Log' else 'Data' end)
,[FileSize_MB] = CAST(CAST(([size] * 8)/1024 AS money) AS varchar(15)) + ' MB'
,[tempdb File Location] = physical_name
FROM sys.master_filesWHERE [database_id] = DB_ID(N'tempdb')
ORDER BY [type] ASC, [file_id] ASC
GO
USE master
GO
ALTER DATABASE tempdbMODIFY FILE (NAME = tempdev, FILENAME = 'E:\SQLData\tempdb.mdf');
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, FILENAME = 'F:\SQLLog\templog.ldf');
GO
-- RESTART MSSQLSERVER...
-
8/6/2019 JSanchez - SQL Server Best Practices
58/105
Installation Tip #7Installation Tip #7tempdbtempdb Database Relocation (cont.)Database Relocation (cont.)
MovingMoving tempdbtempdb Script inScript in SQL Server 2000SQL Server 2000::
USE tempdb
GO
SELECT
[tempdb Logical Filename] = CAST([Name] AS VARCHAR(30))
,[Usage] = (casestatus & 0x40 when 0x40 then 'Log' else 'Data' end)
,[FileSize_MB] = CAST(CAST(([size] * 8)/1024 AS money) AS varchar(15)) + ' MB',[tempdb File Location] = [Filename]
FROM sysfiles
ORDER BY [groupid] DESC, [fileid] ASC
GO
USE master
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev, FILENAME = 'E:\SQLData\tempdb.mdf');
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, FILENAME = 'F:\SQLLog\templog.ldf');
GO
-- RESTART MSSQLSERVER...
-
8/6/2019 JSanchez - SQL Server Best Practices
59/105
Installation Tip #8Installation Tip #8SQL Server ReportsSQL Server Reports
SQL Server 2008/2005SQL Server 2008/2005
ManagementManagementStudioStudio
SQLSQL Server 2000Server 2000
Enterprise ManagerEnterprise Manager
-
8/6/2019 JSanchez - SQL Server Best Practices
60/105
Installation Tip #8Installation Tip #8SQL Server Reports (cont.)SQL Server Reports (cont.)
SQL Server 2005 Reports
How? right click the database,select Reports, then Standard
Reports, then the report wanted
-
8/6/2019 JSanchez - SQL Server Best Practices
61/105
Installation Tip #8Installation Tip #8SQL Server Reports (cont.)SQL Server Reports (cont.)
-
8/6/2019 JSanchez - SQL Server Best Practices
62/105
Installation Tip #8Installation Tip #8SQL Server Reports (cont.)SQL Server Reports (cont.)
SQL Server 2000 Reports
How? click the database, selectView menu, then Taskpad
-
8/6/2019 JSanchez - SQL Server Best Practices
63/105
Installation Tip #8Installation Tip #8SQL Server Reports (cont.)SQL Server Reports (cont.)
SQL Server 2000 Reports
How? click the database, selectView menu, then Taskpad
-
8/6/2019 JSanchez - SQL Server Best Practices
64/105
Installation Tip #8Installation Tip #8SQL Server Reports (cont.)SQL Server Reports (cont.)
-
8/6/2019 JSanchez - SQL Server Best Practices
65/105
Installation Tip #9Installation Tip #9StripeStripe tempdbtempdb, User Data & Log Files, User Data & Log Files
Use Dedicated Storage (Direct AttachedUse Dedicated Storage (Direct Attached DASDAS, orStorage Area Network, orStorage Area Network SANSAN) with) with 15K rpm Disks15K rpm Disks
Note: Network Attached StorageNote: Network Attached Storage NAS are not recommended forSQL Server; forNAS are not recommended forSQL Server; formore informationmore information http://support.microsoft.com/kb/304261http://support.microsoft.com/kb/304261
RAID RecommendationsRAID RecommendationsUseUse RAID 1+0RAID 1+0 Volume forVolume fordata filesdata files; if not possible, then use; if not possible, then use RAID 5RAID 5
Note data files are used in parallel; if all data files have empty space, SQLNote data files are used in parallel; if all data files have empty space, SQLServer will write in all of them at the same time; but when one data file getsServer will write in all of them at the same time; but when one data file getsfilled, SQL Server will increase this only file and by default will continuefilled, SQL Server will increase this only file and by default will continuewriting only in this file; when this file gets filled, SQL Server will increasewriting only in this file; when this file gets filled, SQL Server will increase
other data file (by round robin method) and will write in only that file; in orderother data file (by round robin method) and will write in only that file; in orderto be able to write in data files at the same time, these data files need toto be able to write in data files at the same time, these data files need tohave available spacehave available space
UseUse RAID 1+0RAID 1+0 Volume forVolume forlog filelog file; if not possible, then use; if not possible, then use RAID 1RAID 1
Note log files are used sequentially; SQL Server will not use multiple logNote log files are used sequentially; SQL Server will not use multiple logfiles at the same time; when the first log file fills up, then the second one isfiles at the same time; when the first log file fills up, then the second one is
used.used.
-
8/6/2019 JSanchez - SQL Server Best Practices
66/105
-
8/6/2019 JSanchez - SQL Server Best Practices
67/105
Installation Tip #10Installation Tip #10Instance ConfigurationInstance Configuration
Run Jorge SanchezsRun Jorge Sanchezs SQL_Instance_ReportSQL_Instance_Report script,script, versionversion--22
SQL Server Options should be letSQL Server Options should be let
ProcessorsProcessors -- Boost SQL Server PriorityBoost SQL Server Priority should beshould be disableddisabled (default =(default =disabled), specially in failover clustering configurationdisabled), specially in failover clustering configuration
Where? Management Studio, rightWhere? Management Studio, right--click [click [server_nameserver_name],], PropertiesProperties,,thenthen ProcessorsProcessors pagepage
AdvancedAdvanced Max Degree of ParallelismMax Degree of Parallelism (default = 0, all available CPUs)(default = 0, all available CPUs)
Note: this option does not requires restart the engineNote: this option does not requires restart the engine
Value = 0Value = 0 uses all CPUs availableuses all CPUs available
Value = 1Value = 1 dont use parallelism; use one (1) CPU per querydont use parallelism; use one (1) CPU per query
Value = nValue = n uses n CPUs availableuses n CPUs available
RecommendationsRecommendations
InIn OLTPOLTP, Test first with, Test first with Value = 0Value = 0 (all CPUs) then Value = 1 (No(all CPUs) then Value = 1 (Noparallelism)parallelism)
InIn DW, ReportsDW, Reports, etc., etc. Value = 0.5x of CoresValue = 0.5x of Cores (Example 4 : 8 Cores)(Example 4 : 8 Cores)
http://support.microsoft.com/kb/319942http://blogs.technet.com/mat_stephen/archive/2005/02/08/369120.aspx
-
8/6/2019 JSanchez - SQL Server Best Practices
68/105
Installation Tip #11Installation Tip #11Simple Recovery ModelSimple Recovery Model
To maintain log file size into minimum, change the databasesTo maintain log file size into minimum, change the databasesRecovery ModelRecovery Model SIMPLESIMPLE
tempdbtempdb should be inshould be in SIMPLESIMPLE Recovery ModeRecovery Mode
Backup strategies should be changed because in this mode, Full,Backup strategies should be changed because in this mode, Full,Differential andDifferential and FilegroupFilegroup backups can be made Log backups arebackups can be made Log backups arenot permitted.not permitted.
Also, remember that Transactional Replication, Log Shipping, andAlso, remember that Transactional Replication, Log Shipping, andDatabase Mirroring requires the Recovery Model to be FULLDatabase Mirroring requires the Recovery Model to be FULL
-
8/6/2019 JSanchez - SQL Server Best Practices
69/105
Installation Tip #12Installation Tip #12Check Database Integrity and StatisticsCheck Database Integrity and Statistics
DBCCDBCC CheckDBCheckDB
EXECEXEC sp_updatestatssp_updatestats
EXECEXEC sp_spaceusedsp_spaceused
#13#13
-
8/6/2019 JSanchez - SQL Server Best Practices
70/105
Installation Tip #13Installation Tip #13Stored ProceduresStored Procedures
Always use stored procedure for any SELECT, INSERT, UPDATE,Always use stored procedure for any SELECT, INSERT, UPDATE,orDELETE activityorDELETE activity
Since TSince T--SQL command gets parsed before saving the stored procedureSQL command gets parsed before saving the stored procedureinto the database, the engine do not need to parse commands againinto the database, the engine do not need to parse commands again
The stored procedure gets compiled into memory after the first run, so itThe stored procedure gets compiled into memory after the first run, so itruns fasterruns faster
I ll i Ti #14I ll i Ti #14
-
8/6/2019 JSanchez - SQL Server Best Practices
71/105
Installation Tip #14Installation Tip #14IndexesIndexes
Every tableEvery table should haveshould have aa Clustered IndexClustered Index by the column(s) more usedby the column(s) more usednot necessarily by the Primary Keynot necessarily by the Primary Key
The rest ofNonThe rest ofNon--Clustered Indexes (up to 249 per table) should be created afterClustered Indexes (up to 249 per table) should be created afterthe Clustered Indexthe Clustered Index
Indexes should be reorganized (defragged) or reconstructedIndexes should be reorganized (defragged) or reconstructedIfIffragmentationfragmentation isis
Between 5% and 30%Between 5% and 30% ALTER INDEX REORGANIZEALTER INDEX REORGANIZE
Greater than >30%Greater than >30% ALTER INDEX REBUILD WITH (ONLINE = ON)ALTER INDEX REBUILD WITH (ONLINE = ON)
Note See a SQL Server 2008/2005 sample script in next slideNote See a SQL Server 2008/2005 sample script in next slide
http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/clusivsh.mspx
I t ll ti Ti #14I t ll ti Ti #14
-
8/6/2019 JSanchez - SQL Server Best Practices
72/105
Installation Tip #14Installation Tip #14IndexesIndexes
FILLFACTORFILLFACTOR andand PAD_INDEXPAD_INDEX OptionsOptions
FILLFactorFILLFactor will instruct that index pages in the leafwill instruct that index pages in the leaf--level should be fill up to thelevel should be fill up to thepercentage specifiedpercentage specified
PAD_INDEX will instruct that the rest of index pages (non leafPAD_INDEX will instruct that the rest of index pages (non leaf--level) should be filllevel) should be fill
up to the percentage specifiedup to the percentage specified
http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/clusivsh.mspx
I t ll ti Ti #14I t ll ti Ti #14
-
8/6/2019 JSanchez - SQL Server Best Practices
73/105
Installation Tip #14Installation Tip #14Indexes (cont.)Indexes (cont.)
http://msdn.microsoft.com/en-us/library/ms188917(SQL.90).aspx
-- Ensure a USE statement has been executed first.SET NOCOUNT ON;DECLARE @objectid int, @indexid int, @partitioncount bigint, @schemaname nvarchar(130);
DECLARE @objectname nvarchar(130), @indexname nvarchar(130), @partitionnum bigint;DECLARE @partitions bigint, @frag float, @command nvarchar(4000);-- Conditionally select tables and indexes from the sys.dm_db_index_physical_stats function-- and convert object and index IDs to names.
IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE Name LIKE '#work_to_do%')DROP TABLE #work_to_do
SELECTobject_id AS objectid,
index_id AS indexid,partition_number AS partitionnum,
avg_fragmentation_in_percent AS fragINTO #work_to_doFROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'LIMITED')WHERE avg_fragmentation_in_percent > 10.0 AND index_id > 0;
-- Declare the cursor for the list of partitions to be processed.DECLARE partitions CURSOR FOR SELECT * FROM #work_to_do;
-- Open the cursor.OPEN partitions;
Continues in next slide(For the complete script, open this slides speaker notes)
Works only inSQL Server2008/2005
I t ll ti Ti #14I t ll ti Ti #14
-
8/6/2019 JSanchez - SQL Server Best Practices
74/105
Installation Tip #14Installation Tip #14Indexes (cont.)Indexes (cont.)
http://msdn.microsoft.com/en-us/library/ms188917(SQL.90).aspx
-- Loop through the partitions.WHILE (1=1)
BEGIN;
FETCH NEXTFROM partitionsINTO @objectid, @indexid, @partitionnum, @frag;
IF @@FETCH_STATUS < 0 BREAK;SELECT @objectname = QUOTENAME(o.name), @schemaname = QUOTENAME(s.name)
FROM sys.objects AS oJOIN sys.schemas as s ON s.schema_id = o.schema_id
WHERE o.object_id = @objectid;SELECT @indexname = QUOTENAME(name)FROM sys.indexes
WHERE object_id = @objectid AND index_id = @indexid;SELECT @partitioncount = count (*)
FROM sys.partitionsWHERE object_id = @objectid AND index_id = @indexid;
Continues in next slide(For the complete script, open this slides speaker notes)
Works only inSQL Server2008/2005
I t ll ti Ti #14I t ll ti Ti #14
-
8/6/2019 JSanchez - SQL Server Best Practices
75/105
Installation Tip #14Installation Tip #14Indexes (cont.)Indexes (cont.)
http://msdn.microsoft.com/en-us/library/ms188917(SQL.90).aspx
-- 30 is an arbitrary decision point at which to switch between reorganizing and rebuilding.IF @frag < 30.0
SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N'
REORGANIZE';IF @frag >= 30.0
SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N'REBUILD';
IF @partitioncount > 1
SET @command = @command + N' PARTITION=' + CAST(@partitionnum AS nvarchar(10));EXEC (@command);
PRINT N'Executed: ' + @command;END;
-- Close and deallocate the cursor.CLOSE partitions;
DEALLOCATE partitions;
-- Drop the temporary table.DROP TABLE #work_to_do;GO
Script ends here(For the complete script, open this slides speaker notes)
Works only inSQL Server2008/2005
I t ll ti Ti #14I t ll ti Ti #14
-
8/6/2019 JSanchez - SQL Server Best Practices
76/105
Installation Tip #14Installation Tip #14Indexes (cont.)Indexes (cont.)
Script results from the AdventureWorksDWdatabase; some indexes REBUILD and
some REORGANIZE
I t ll ti Ti #15I t ll ti Ti #15
-
8/6/2019 JSanchez - SQL Server Best Practices
77/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning AdvisorProfiler + Database Engine Tuning Advisor
Use Profiler to capture SQL Server activity and Analyze it with theUse Profiler to capture SQL Server activity and Analyze it with theDatabase Engine Tuning AdvisorDatabase Engine Tuning Advisor
In Profiler, use theIn Profiler, use the TuningTuning templatetemplate
I t ll ti Ti #15I t ll ti Ti #15
-
8/6/2019 JSanchez - SQL Server Best Practices
78/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning Advisor (cont.)Profiler + Database Engine Tuning Advisor (cont.)Run Profiler(Start / Programs / Microsoft SQL
Server 2005 / Performance Tools), create a new
trace, select the Tuning template, save to file,then click the [Events Selection] tab
I t ll ti Ti #15I t ll ti Ti #15
-
8/6/2019 JSanchez - SQL Server Best Practices
79/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning AdvisorProfiler + Database Engine Tuning AdvisorIn the [Events Selection] tab, click [Columns
Filters] commandbutton, select DatabaseName
and in the Like section, type the databasesname to be evaluated; click OK and click Run
I t ll ti Ti #15I t ll ti Ti #15
-
8/6/2019 JSanchez - SQL Server Best Practices
80/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning AdvisorProfiler + Database Engine Tuning Advisor
Now Profileris waiting to capture any commandagainst the database evaluated
I t ll ti Ti #15I t ll ti Ti #15
-
8/6/2019 JSanchez - SQL Server Best Practices
81/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning AdvisorProfiler + Database Engine Tuning Advisor
Run load against the database evaluated
I t ll ti Ti #15I t ll ti Ti #15
-
8/6/2019 JSanchez - SQL Server Best Practices
82/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning AdvisorProfiler + Database Engine Tuning Advisor
Profilercaptured commands against thedatabase evaluated; now, stop the trace
Installation Tip #15Installation Tip #15
-
8/6/2019 JSanchez - SQL Server Best Practices
83/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning AdvisorProfiler + Database Engine Tuning Advisor
In Management Studio, click Tools and selectDatabase Engine Tuning Advisor
Installation Tip #15Installation Tip #15
-
8/6/2019 JSanchez - SQL Server Best Practices
84/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning AdvisorProfiler + Database Engine Tuning Advisor
Create a new session, load the workloadfile saved by Profiler, select the database
to be evaluated and click the [StartAnalysis] commandbutton
Installation Tip #15Installation Tip #15
-
8/6/2019 JSanchez - SQL Server Best Practices
85/105
Installation Tip #15Installation Tip #15Profiler + Database Engine Tuning AdvisorProfiler + Database Engine Tuning Advisor
The Database Engine Tuning Advisorwillpresent a report of recommended CREATE andDROP indexes; if you want to apply them, go to
the Actions menu and select ApplyRecommendations
Installation Tip #16Installation Tip #16
-
8/6/2019 JSanchez - SQL Server Best Practices
86/105
Installation Tip #16Installation Tip #16Best Practices AnalyzerBest Practices Analyzer
Install and Run theInstall and Run the Best Practice Analyzer (BPA)Best Practice Analyzer (BPA) tooltool
This tool will evaluate a SQL Server Instance and will reportThis tool will evaluate a SQL Server Instance and will reportrecommendations based on best practicesrecommendations based on best practices
ForDownloadForDownload
SQL ServerSQL Server20052005
http://www.microsoft.com/downloads/details.aspx?FamilyID=DA0531E4http://www.microsoft.com/downloads/details.aspx?FamilyID=DA0531E4--E94CE94C--49914991--82FA82FA--F0E3FBD05E63&displaylang=enF0E3FBD05E63&displaylang=en
SQL ServerSQL Server20002000
http://www.microsoft.com/downloads/details.aspx?FamilyID=b352eb1fhttp://www.microsoft.com/downloads/details.aspx?FamilyID=b352eb1f--d3cad3ca--44ee44ee--893e893e--9e07339c1f22&DisplayLang=en9e07339c1f22&DisplayLang=en
Installation Tip #16Installation Tip #16
-
8/6/2019 JSanchez - SQL Server Best Practices
87/105
Installation Tip #16Installation Tip #16Best Practices Analyzer (cont.)Best Practices Analyzer (cont.)
Installation Tip #17Installation Tip #17
-
8/6/2019 JSanchez - SQL Server Best Practices
88/105
Installation Tip #17Installation Tip #17SQL CAT (Customer Advisory Team)SQL CAT (Customer Advisory Team)
http://sqlcat.com/Default.aspx
Installation Tip #18Installation Tip #18
-
8/6/2019 JSanchez - SQL Server Best Practices
89/105
Installation Tip #18Installation Tip #18SQL Server 2008 Performance New FeaturesSQL Server 2008 Performance New Features
Resource GovernorResource Governor
PerformanceData Collectors and ReportsPerformanceData Collectors and Reports
Table and Index CompressionTable and Index Compression
Backup CompressionBackup Compression
FILESTREAMData TypeFILESTREAMData Type
Sparse ColumnsSparse Columns
Data (only) and Time (only) Data TypesData (only) and Time (only) Data Types
Partition Table ParallelismPartition Table Parallelism
Query OptimizationQuery Optimization
Installation Tip #19Installation Tip #19
-
8/6/2019 JSanchez - SQL Server Best Practices
90/105
Installation Tip #19Installation Tip #19Web ReferencesWeb References
Best PracticesBest Practices
-
8/6/2019 JSanchez - SQL Server Best Practices
91/105
Best PracticesBest Practices
Host BusA
dapters (HBA
)Host BusA
dapters (HBA
)Queue Length >= 32 (or = 256 in fiber channel connections)Queue Length >= 32 (or = 256 in fiber channel connections)
-
8/6/2019 JSanchez - SQL Server Best Practices
92/105
Best Practices (cont )Best Practices (cont )
-
8/6/2019 JSanchez - SQL Server Best Practices
93/105
Best Practices (cont.)Best Practices (cont.)
Table ArchitectureTable ArchitectureIndexes (Clustered, NonIndexes (Clustered, Non--Clustered, Fill Factor, Pad IndexClustered, Fill Factor, Pad Index
Primary Key, Foreign Key, Referential Integrity for OLTPPrimary Key, Foreign Key, Referential Integrity for OLTP
No RI forDW/DM.No RI forDW/DM.
Fact tablesFact tables
Create Clustered Index on (Create Clustered Index on (DateKeyDateKey))
CreateCreate NonclusteredNonclustered Indexes including the clustered field (Indexes including the clustered field (ejej..((CustomerKeyCustomerKey,, DateKeyDateKey))
Dimension tablesDimension tables
Create Clustered Index on Business Key Instead ofDimension KeyCreate Clustered Index on Business Key Instead ofDimension Key
CreateCreate NonclusteredNonclustered Primary Key on Dimension KeyPrimary Key on Dimension Key
Query ArchitectureQuery ArchitectureDisplay Estimated Execution PlanDisplay Estimated Execution Plan
ProfilerProfiler
Best Practices (cont )Best Practices (cont )
-
8/6/2019 JSanchez - SQL Server Best Practices
94/105
Best Practices (cont.)Best Practices (cont.)
ETLETL Integration ServicesIntegration ServicesDeploy SSIS64Deploy SSIS64--Bit to address > 4GB RAMBit to address > 4GB RAM
SSIS 32SSIS 32--bit uses up to 3GB (boot.ini with /3GB)bit uses up to 3GB (boot.ini with /3GB)
ModularArchitectureModularArchitecture Every table should have its own packageEvery table should have its own package
Shared ConnectorsShared Connectors
Include AuditInclude Audit
CubesCubesDeploy SSAS64Deploy SSAS64--bit for to address > 4GB RAMbit for to address > 4GB RAM
SSAS 32SSAS 32--bit uses up to 3GB (boot.ini with /3GB)bit uses up to 3GB (boot.ini with /3GB)Have only natural hierarchiesHave only natural hierarchies
PartitionsPartitions
30% Aggregates30% Aggregates
Best Practices (cont )Best Practices (cont )
-
8/6/2019 JSanchez - SQL Server Best Practices
95/105
Best Practices (cont.)Best Practices (cont.)
Reporting ServicesReporting ServicesScaling UpScaling Up
22--PROCs with Local Catalog DatabasePROCs with Local Catalog Database
44--PROCs with Remote Catalog DatabasePROCs with Remote Catalog Database
>4>4--PROCs, change to 64PROCs, change to 64--BitBit
PlatformPlatform3232--Bit Systems: Use /3GB in C:Bit Systems: Use /3GB in C:\\boot.iniboot.ini
Use 64Use 64--Bit Systems: X64, IA64Bit Systems: X64, IA64
MemoryMemoryLimit Max. RAM in the RDBMS if the same server uses also SSRSLimit Max. RAM in the RDBMS if the same server uses also SSRS
FilesFilesPartition thePartition the ReportServerTempDBReportServerTempDB database, by create data files equal CPUsdatabase, by create data files equal CPUs
Partition thePartition the ReportServerReportServerdatabase, separate data files and log files intodatabase, separate data files and log files intodifferent arrays; also, spread data files into separate arraysdifferent arrays; also, spread data files into separate arrays
-
8/6/2019 JSanchez - SQL Server Best Practices
96/105
Best Practices (cont )Best Practices (cont )
-
8/6/2019 JSanchez - SQL Server Best Practices
97/105
Best Practices (cont.)Best Practices (cont.)
Reporting ServicesReporting ServicesCreate Report TemplatesCreate Report Templates
Copy .Copy .rdlrdl files infiles in
C:C:\\Program FilesProgram Files\\Microsoft Visual StudioMicrosoft Visual Studio88\\Common7Common7\\IDEIDE\\PrivateAssembliesPrivateAssemblies\\ProjectItemsProjectItems\\ReportProjectReportProject\\
More InformationMore Information
Planning for Scalability and Performance with Reporting ServicesPlanning for Scalability and Performance with Reporting Services
http://www.microsoft.com/technet/prodtechnol/sql/2005/pspsqlrs.mspxhttp://www.microsoft.com/technet/prodtechnol/sql/2005/pspsqlrs.mspx
CertificationsCertifications
-
8/6/2019 JSanchez - SQL Server Best Practices
98/105
CertificationsCertificationsMCITP: DatabaseMCITP: Database AdministratorAdministrator
http://www.microsoft.com/learning/mcp/mcitp/dbadmin/default.mspx
CertificationsCertifications
-
8/6/2019 JSanchez - SQL Server Best Practices
99/105
CertificationsCertificationsMCITP: DatabaseMCITP: Database DeveloperDeveloper
http://www.microsoft.com/learning/mcp/mcitp/dbdev/default.mspx
CertificationsCertifications
-
8/6/2019 JSanchez - SQL Server Best Practices
100/105
CertificationsCertificationsMCITP:MCITP: Business Intelligence DeveloperBusiness Intelligence Developer
http://www.microsoft.com/learning/mcp/mcitp/bid/default.mspx
CertificationsCertifications
-
8/6/2019 JSanchez - SQL Server Best Practices
101/105
CertificationsCertificationsMCM:MCM: Master ProgramMaster Program
http://www.microsoft.com/learning/mcp/master/register/default.mspx
-
8/6/2019 JSanchez - SQL Server Best Practices
102/105
BooksBooks
-
8/6/2019 JSanchez - SQL Server Best Practices
103/105
BooksBooksMicrosoft PressMicrosoft Press -- Inside SeriesInside Series
1. Inside Microsoft SQL Server 2005: The Storage EngineAuthor : Kalen Delaney (Solid Quality Learning)Pages : 464Level : Int/AdvPublished : 10/11/2006ISBN : 9780735621053ISBN-10 : 0-7356-2105-5
Web : http://www.microsoft.com/MSPress/books/7436.aspx
2. Inside Microsoft SQL Server 2005: Query Tuning and OptimizationAuthor : Kalen Delaney, S. Agarwal, C. Freedman, A. Machanic, R. TalmagePages : 448Level : Int/AdvPublished : 09/26/2007
ISBN : 9780735621961ISBN-10 : 0-7356-2196-9Web : http://www.microsoft.com/MSPress/books/8565.aspx
BooksBooks
-
8/6/2019 JSanchez - SQL Server Best Practices
104/105
3. Inside Microsoft SQL Server 2005: T-SQL QueryingAuthor : Itzik Ben-Gan (Solid Quality Learning), Lubor Kollar, Dejan SarkaPages : 640Level : Int/AdvPublished : 03/29/2006ISBN : 9780735623132ISBN-10 : 0-7356-2313-9
Web : http://www.microsoft.com/MSPress/books/9615.aspx
4. Inside Microsoft SQL Server 2005: T-SQL ProgrammingAuthor : Itzik Ben-Gan (Solid Quality Learning), Dejan Sarka; RogerWolterPages : 544Level : Int/AdvPublished : 05/17/2006
ISBN : 9780735621978ISBN-10 : 0-7356-2197-7Web : http://www.microsoft.com/MSPress/books/8564.aspx
BooksBooksMicrosoft PressMicrosoft Press -- Inside SeriesInside Series
Jorge SnchezJorge Snchez
S i T h l S l tiS i T h l S l ti P f i lP f i l
-
8/6/2019 JSanchez - SQL Server Best Practices
105/105
20082008 Microsoft Corporation. All rights reserved.Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Senior Technology SolutionsSenior Technology Solutions ProfessionalProfessional
Enterprise DataEnterprise Data PlatformSpecialistPlatformSpecialist
MicrosoftMicrosoft Multi Country AmericasMulti Country Americas
[email protected]@microsoft.com
CelCel. (787) 487. (787) 487--29772977