0% found this document useful (0 votes)
112 views

JSanchez - SQL Server Best Practices

Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

JSanchez - SQL Server Best Practices

Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 105

SQL SERVER

2008 / 2005 / 2000


BEST PRACTICES

Jorge Sánchez
Senior Technology Solutions Professional
Enterprise Data PlatformSpecialist
Microsoft Multi Country Americas
[email protected]
Cel. (787) 487-2977
Gartner Business Intelligence Platforms Magic Quadrant, 2008

Gartner, Inc. “Gartner Magic Quadrant for Business Intelligence Platforms, 2008,” James
Richardson et al., Feb. 1, 2008

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 time
period. It depicts Gartner’s analysis of how certain vendors measure against criteria for that marketplace, as defined by Gartner. Gartner does not endorse any vendor, product or service depicted
in 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 not
meant 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 particular
purpose.
“This Magic Quadrant graphic was published by Gartner, Inc. as part of a larger research note and should be
evaluated in the context of the entire report. The Gartner report is available upon request from Jennifer Pisani,
Microsoft.”
http://mediaproducts.gartner.com/reprints/microsoft/vol4/article2/article2.html
OLAP Market Leadership

Microsoft stands in 1st place,


almost at double from the next
OLAP vendor.

http://www.olapreport.com/market.htm#shares
NASDAQ – 5,000 txs/sec!!!

Video
BOVESPA – Mainframe Migration

Video
Microsoft’s End-to-End BI Offering
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, Load Balancing, 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, Data Cleansing, DW, Cubes, OLAP, Data Mining Algorithms, Web
Reports, Ad-hoc Reports)

Mainframe/ Others
Departmental
Systems
SQL Server is More Secure
Number of Security Bulletins

45 41
40
35 31
30
24
25 22

20 18 18
14 14
15 11
10 9 10
10 8 8
6 5 5
3 4 3 2
5 1 2 2
0 0 0 0
0
2002 2003 2004 2005 2006 2007 2008
Oracle SQL Server DB2 mySQL
Notes: Updated as of 08/06/2008.
Vulnerabilities are included for:
SQL Server (any version), Oracle (8i, 9i, 9i, 10g, 11g), Source: National Institute of Standards and Technology (NIST)
IBM (Universal Database), mySQL (mySQL)
National Vulnerability Database (http://nvd.nist.gov/statistics.cfm)
SQL Server is More Secure
Number of Security Bulletins

45 41
40
SQL Server with the LOWEST security
35 31 advisories in 6 years!!!
30
24
25 22

20 18 18
14 14
15 11
10 9 10
10 8 8
6 5 5
3 4 3 2
5 1 2 2
0 0 0 0
0
2002 2003 2004 2005 2006 2007 2008
Oracle SQL Server DB2 mySQL
Notes: Updated as of 08/06/2008.
Vulnerabilities are included for:
SQL Server (any version), Oracle (8i, 9i, 9i, 10g, 11g), Source: National Institute of Standards and Technology (NIST)
IBM (Universal Database), mySQL (mySQL)
National Vulnerability Database (http://nvd.nist.gov/statistics.cfm)
Oracle 10g
IBM DB2

Base Product
$ 25K $ 40K $ 25K
Tuning
$3K
Diagnostics
$3K
Partitioning Performance
$10K Expert
(included)
$10K

Manageability

Base Product
$ 25K $ 56K
40K $ 35K
25K
DB2 OLAP
$35K
DB2
Warehouse
OLAP $75K
$20k Cube Views
Mining $9.5K
$20k
BI Bundle
$20k
Business
Intelligence
(included)

Manageability

Base Product
$ 25K $$116K
56K $ $154.5K
35K
Data Guard
$116K Recovery
Expert
$10k

High Availability

Business
Intelligence
(included)

Manageability

Base Product
$ 25K $ 232K
116K $ 164.5K
154.5K
$164.5K
$116K - $232K

Multi-core

Business
Intelligence

High Availability
(included)

Manageability

Base Product
$ 25K $ 232K
$348k - $464k $$164.5K
329K
Microsoft Data Factory Architecture
Microsoft Office Microsoft SQL Server 2008
Microsoft Office
PerformancePoint
Excel 2007 ProClarity Reporting Services
Server 2007

OLTP Analytical Applications Reports Portal

Office/SharePoint

CRM
ERP DW,
Marts Devices
ODS
Line Of Data Analysis
Business Data Tactical Strategic (OLAP,
Apps Transformation Data Mining)
(ETL) Analytic Platform
SQL Server 2008 SQL Server 2008 SQL Server 2008 SQL Server 2008
RDBMS .NET Framework
Integration Services and Development
RDBMS Tools
Analysis Services

BI Development and Management Tools SQL Server Management Tools


SQL Server
Installation and Configuration Best
Practices
1. 64-bit Editions
2. 32-bit Editions: Configure Memory
3. Volume Offset Alignment
4. SQLIO and SQLIOSim Utilities
5. Enterprise vs. Standard Editions
6. Local Installation Policies
7. Tempdb Database Relocation
8. SQL Server Reports
9. Stripe tempdb, User Data and Log Files
10. Instance Configuration
11. Simple Recovery Model
12. Check Database Integrity and Update Statistics
13. Stored Procedures
14. Indexes
15. Profiler + Database Engine Tuning Advisor
16. Best Practices Analyzer (BPA)
17. SQL Customer Advisory Team (SQL CAT)
18. SQL Server 2008 Performance New Features
Installation Tip #1
64-bit Editions
Your first option should be SQL Server for 64-bit machines unless the front-
end application has been certified only for 32-bit
Why?
64-bits has more addressable memory = 16,386 TB (16 Exabytes), instead of
x86 architecture which uses directly up to 4GB RAM (64GB RAM with /PAE &
AWE)
PAE is a function which enables Windows 2008/2003/2000 to show more memory to programs
(the memory it has requested is actually in the page file)
AWE API enables a program to use more than 4GB memory (non-pageable and is only accessible
to that program)

SQL Server has two 64-bit editions compiled natively:


X64 and IA64 (“Itanium”)
Installation Tip #1
64-bit Editions (cont.)
Deploy Windows Server and SQL Server in the same architecture
Windows Server 2008/2003 for x64 + SQL Server 2008/2005 for x64
Windows Server 2008/2003 for IA64 + SQL Server 2008/2005 for IA64
Install the latest service pack for Windows Server and SQL Server
Service Pack up to Oct-2008…
Windows Server 2008 RTM (has SP1 already installed)
Windows Server 2003 SP2 (Standard, Enterprise, Datacenter)
Windows Server 2000 SP4 (Standard, Advanced, Datacenter)
SQL Server 2008 RTM
SQL Server 2005 SP2
SQL Server 2000 SP4

All SQL Server Engines in 2008 and 2005 (RBDMS, Integration Services,
Analysis Services, Reporting Services) for 64-bits platform are compiled
natively and each one will use all memory available
Installation Tip #2
32-bit Editions: Configure Memory
Configure Windows Server (v2003 and v2000) to use memory efficiently
Change the Boot.ini file to activate…
Systems with less than 4GB RAM  use /3GB only!
/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) and Windows
Server 2000 (Datacenter and Advanced)
Note: Windows Server 2008/2003/2000 Standard Edition has 4GB RAM maximum; if the machine has greater
than 4GB RAM, Windows Server Standard Edition will not use it! In this case, upgrade (at least) to Windows
Server 2008/2003 (R2) Enterprise or Standard X64
Systems with between 4GB RAM and 16GB RAM  /3GB + /PAE + AWE
/PAE will instruct Windows and SQL Server to use address space higher than 4GB to map data (requires
reboot)
This option also requires (at least) Windows Server 2008 Enterprise , Windows Server 2003 (R2) Enterprise,
or Windows Server 2000 Advanced Editions
Systems with greater than 16GB RAM  /PAE + AWE (Don’t use /3GB!)
Note: In this case, don’t use /3GB since it will limit memory up to 16GB RAM.
For more info:
http://blogs.technet.com/vipulshah/archive/2007/05/10/3gb-pae-and-awe-on-32-bit-sy
stems.aspx
In 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).
Installation Tip #2
32-bit Editions: Configure Memory (cont.)
Configure SQL Server to use memory
Systems with less than 4GB RAM  use /3GB only!
Don’t have to configure SQL Server 2008/2005/2000 to work within RAM 4GB or less
Systems with between 4GB RAM and 16GB RAM  /3GB + /PAE + AWE
and Systems with greater than 16GB RAM  /PAE + AWE (Don’t use
/3GB!)
To enable Address Windowing Extensions (AWE) for Microsoft SQL
Server, you must run the SQL Server Database Engine under a Microsoft
Windows account that has been assigned the Lock Pages in Memory
option
Start / Administrative Tools / Local Security Policy / Local Policies / User
Rights Assignment
Lock Pages In Memory = [Your SQL Server Service Account; ex.
Domain\SQLAdmin]
Installation Tip #2
32-bit Editions: Configure Memory (cont.)

You have to turn AWE ON…


In SQL Server 2008/2005
Go to Server Properties / [Memory] page, and select Use AWE to allocate
memory
Restart the SQL Server service

In SQL Server 2000


EXECUTE sp_configure 'show advanced options', 1
RECONFIGURE
EXECUTE sp_configure 'awe enabled‘, 1
RECONFIGURE
--[Restart the SQL Server service]
EXECUTE sp_configure 'show advanced options', 0
RECONFIGURE
Installation Tip #2
32-bit Editions: Configure Memory (cont.)
If you need to use SQL Server 2008/2005/2000 in 32-bit Windows…
Do NOT run SQL Server 32-bit on Window Server 64-bit (this is call Window-
on-Window, or WOW); SQL Server will run with less performance
In this case, be sure to use Windows Server 2008/2003 for X86 (32-bit)
NOTE… WINDOWS SERVER 2008/2003/2000 STANDARD EDITION HAS A
MAXIMUM RAM UP TO 4GB! (See next slide) … TO USE /PAE AND AWE YOU
NEED RAM > 4GB!
For more than 4GB RAM, you need to change the OS (at least) to Windows Server
2008/2003 Standard Edition for X64… or Windows Server 2008/2003 X86 Enterprise
Edition
Installation Tip #2
32-bit Editions: Configure Memory (cont.)
  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 1TB
2003 (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 512GB
2003 (RTM) Enterprise 32GB 64GB
2003 (RTM) Standard 4GB 16GB
2000 (RTM) Datacenter 32GB X
2000 (RTM) Advanced 8GB X
2000 (RTM) Standard 4GB X

http://msdn.microsoft.com/en-us/library/aa366778.aspx
Installation Tip #3
Volume Offset Alignment
It may represent from 10%-30% performance difference!
Windows Server 2003
Use System Information (msinfo32.exe) to determine if the Partition Starting Offset
from each volume = 1,048,576 bytes.
Note: msinfo32.exe requires the Help and Support Windows Service. If
you need to install it, run the following script:
cd %windir%\PCHealth\HelpCtr\Binaries\
start /w helpsvc /svchost netsvcs /install
After installation, go to Services and start the Help and Support service.
More Info…
http://blogs.technet.com/sbs/archive/2007/03/20/help-and-support-service-missing-after-installing-windows-2003-s
ervice-pack-2.aspx

If the Starting Offset is less (ex. 32,256 bytes), then use DISKPART.EXE (in command
prompt) to re-create this volume but using an alignment of 1,024
Format the volume using NTFS with a Allocation Unit Size = 64 KB
To determine the Allocation Unit Size from a already formatted volume, run:
fsutil fsinfo ntfsinfo [drive_letter]:
For more information:
Support Site: http://support.microsoft.com/default.aspx?scid=kb;EN-US;929491
Diskpart: http://technet.microsoft.com/en-us/library/cc773140.aspx
Installation Tip #3
Volume Offset Alignment
Disk or Array Volume Alignment
Windows Server 2008
This version (as well as Windows Vista) aligns volumes automatically.
Format the volume using NTFS with a Allocation Unit Size = 64 KB
NOTE: DO NOT FORMAT WITH THE COMPRESS OPTION
To determine if the
Volume Offset Alignment
is different than the
default of 32K, run
msinfo32.exe
Notice that volume has a
Partition Starting Offset of
32,256 (31.5K) bytes instead of
1,048,576 bytes (1024K)
Use the following command to determine if the volume has been formatted as 64K:
C:\fsutil fsinfo ntfsinfo [drive_letter]:

Notice that the volume has


been formatted with the
default of 4096 (4K) Bytes
Per Cluster instead of 65536
(64K)
To change the Volume Offset Alignment to
1024K, run diskpart in a separate
Command Prompt window, but
CAREFULL… DISKPART WILL ERASE
THE VOLUME AND ALL DATA IN IT!
Do backup before if necessary.
Notice that now Disk 1 has
the focus (look for the “*”)

Use Align=1024 in the


Create Partition command

Use Unit=64K in the Format


command
Notice that the volume now
has a Partition Starting
Offset of 1,048,576 bytes
(1024K)
Use the following command to determine if the volume has been formatted as 64K:
C:\fsutil fsinfo ntfsinfo [drive_letter]:

Notice that the volume


has been formatted as
64K (65536)
Format the volume in
NTFS with an
Allocation Unit Size =
64 KB
Installation Tip #4
SQLIO and SQLIOSim Utilities
SQLIO.exe is a stress test tool to determine the hardware’s Input/Output capacity of
a disk subsystem in order to tune it for optimal performance BEFORE deploying
SQL Server
Note: SQLIO.exe will not simulate SQL Server I/O patterns, instead it will test I/O types
(Random Reads, Random Writes, Sequential Reads, Sequential Writes) and sizes (1K, 2K,
4K, 8K, 64K, 128K, 256K)
SQLIOSim.exe is a SQL Server stress test tool utility (upgraded from the old
SQLIOStress) which simulates SQL Server (versions 2005, 2000, and 7.0) read,
write, checkpoint, backup, sort, and read-ahead activities
For Downloads…
SQLIO Utility…
http://www.microsoft.com/downloads/details.aspx?familyid=9A8B005B-84E4-4F24
-8D65-CB53442D9E19&displaylang=en
SQLIOSim Utility
http://support.microsoft.com/kb/231619
http://sqlblog.com/blogs/linchi_shea/archive/2007/02/21/parse-the-sqlio-exe-output.aspx
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)
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:
RUNTEST.cmd) to automate all tests
The PARAM.txt file will contain the volume references to be examined, the name
of the test file to be created, how many threads to be used (per test file; 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]
For example… m:\data\testfile.dat 2 0x0 100
The batch file (RUNTEST.cmd) should include all tests
-k[Test] –s[Duration] –f[I/O Type] –o[Requests] –b[Size] –LS –F[file] [seconds]
Note… Wait at least one (1) minute between tests to let the I/O system return to idle

sqlio -kW -s10 -frandom -o8 –b2 -LS -Fparam.txt timeout /T 60 > Random_Writes_2K.txt
sqlio -kR -s10 -frandom -o8 –b4 -LS -Fparam.txt timeout /T 60 > Random_Reads_4K.txt
sqlio -kW -s10 -fsequential -o8 –b8 -LS -Fparam.txt timeout /T 60 > Sequential_Writes_8K.txt
sqlio -kR -s10 -fsequential -o8 –b64 -LS -Fparam.txt timeout /T 60 > Sequential_Reads_64K.txt
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)

Look on each report for the Throughput


and Latency metrics:
IOs/sec, MBs/sec
Min_Latency(ms), Avg_Latency(ms),
Max_Latency(ms)

Throughput: the amount of activity a system can sustain over time


Latency: the amount of time it takes for a data change to be propagated between nodes
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)

Regarding SQLIOSim…
Be sure to have sqliosim.exe and
sqliosim.com in a separate folder;
then run sqliosim.exe.
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)
Press F11 to configure which data and
log files to stress test
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)

Press F12 to start data and log files


stress tests
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)

After all test are finished, evaluate the


results report and watch for error and
warning messages
Installation Tip #4
SQLIO and SQLIOSim Utilities (cont.)
Installation Tip #5
SQL 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
Installation Tip #5
SQL Server DBMS Enterprise vs. Standard

http://download.microsoft.com/download/2/d/f/2df66c0c-fff2-4f2e-b739-bf4581cee533/SQLServer%202008CompareEnterpriseStandard.pdf
Installation Tip #5
SQL Server DBMS Enterprise vs. Standard

http://download.microsoft.com/download/2/d/f/2df66c0c-fff2-4f2e-b739-bf4581cee533/SQLServer%202008CompareEnterpriseStandard.pdf
Installation Tip #5
SQL Server DBMS Enterprise vs. Standard

http://download.microsoft.com/download/2/d/f/2df66c0c-fff2-4f2e-b739-bf4581cee533/SQLServer%202008CompareEnterpriseStandard.pdf
SQL Server Releases Version
http://support.microsoft.com/kb/321185/en-us SQL Server Releases
SQL Server 2008
SQL Server 2008 RTM 10.0.1600
SQL Server 2005
SQL Server 2005 SP2 9.00.3073
SQL Server Version TSQL Script
SQL Server 2005 SP1 9.00.2047
SQL Server 2005 RTM 9.00.1399 SQL Server 2008/2005
SQL Server 2000 SELECT
SQL Server 2000 SP4 8.00.2039 [ProductVersion] = SERVERPROPERTY('productversion')
SQL Server 2000 SP3a 8.00.760 ,[ProductLevel] =SERVERPROPERTY ('productlevel')
SQL Server 2000 SP3 8.00.760
,[Edition] = SERVERPROPERTY ('edition')
SQL Server 2000 SP2 8.00.534
SQL Server 2000 SP1 8.00.384
SQL Server 2000 RTM 8.00.194 SQL Server 2000
SQL Server 7.0 SELECT
SQL Server 7.0 SP4 7.00.1063 [ProductVersion] = SERVERPROPERTY('productversion')
SQL Server 7.0 SP3 7.00.961 ,[ProductLevel] =SERVERPROPERTY ('productlevel')
SQL Server 7.0 SP2 7.00.842
,[Edition] = SERVERPROPERTY ('edition')
SQL Server 7.0 SP1 7.00.699
SQL Server 7.0 RTM 7.00.623
SQL Server 6.5 SQL Server 7.0
SQL Server 6.5 SP5a Update 6.50.479 SELECT @@VERSION
SQL Server 6.5 SP5a 6.50.416
SQL Server 6.5 SP5 6.50.415
SQL Server 6.5 SP4 6.50.281 SQL Server 6.5
SQL Server 6.5 SP3 6.50.258 SELECT @@VERSION
SQL Server 6.5 SP2 6.50.240
SQL Server 6.5 SP1 6.50.213
SQL Server 6.5 RTM 6.50.201
Installation Tip #6
Local Installation Policies
Local Security Policy
Retain Operating System from paging its memory to disk
Start / Administrative Tools / Local Security Policy / Local Policies / User Rights
Assignment
Lock Pages In Memory = [Your SQL Server Service Account; ex.
Domain\SQLAdmin]
Enable Instant File Initialization for New Data Files or Extending Data Files
Start / Administrative Tools / Local Security Policy / Local Policies / User Rights
Assignment
Perform Volume Maintenance Tasks = [Your SQL Server Service Account; ex.
Domain\SQLAdmin]
Note: Instant File Initialization is available only in Windows Server 2003 or later
Installation Tip #7
tempdb Database Relocation
tempdb is used for
User Objects
User-defined tables and indexes, system tables and indexes, global
temporary tables and indexes, local temporary tables and indexes, table
variables, tables returned in table-valued functions
Internal Objects
Cursors, Hash Joins, Hash Aggregates, Sorts, GROUP BY, ORDER BY,
UNION queries, DBCC commands, Indexes, LOB, MARS, Stored
Procedures
Version Stores
That’s why tempdb files should be relocated into its own dedicated
storage
Installation Tip #7
tempdb Database Relocation (cont.)
Moving tempdb Script in SQL 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_files
WHERE [database_id] = DB_ID(N'tempdb')
ORDER BY [type] ASC, [file_id] 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...
Installation Tip #7
tempdb Database Relocation (cont.)
Moving tempdb Script in SQL Server 2000:
USE tempdb
GO
SELECT
[tempdb Logical Filename] = CAST([Name] AS VARCHAR(30))
,[Usage] = (case status & 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...
Installation Tip #8
SQL Server Reports

SQL Server 2008/2005


Management Studio

SQL Server 2000


Enterprise Manager
Installation Tip #8
SQL Server Reports (cont.)

SQL Server 2005 Reports


How?… right click the database, select
Reports, then Standard Reports, then the
report wanted
Installation Tip #8
SQL Server Reports (cont.)
Installation Tip #8
SQL Server Reports (cont.)

SQL Server 2000 Reports


How?… click the database, select View
menu, then Taskpad
Installation Tip #8
SQL Server Reports (cont.)

SQL Server 2000 Reports


How?… click the database, select View
menu, then Taskpad
Installation Tip #8
SQL Server Reports (cont.)
Installation Tip #9
Stripe tempdb, User Data & Log Files

Use Dedicated Storage (Direct Attached – DAS, or Storage Area Network – SAN)
with 15K rpm Disks
Note: Network Attached Storage – NAS are not recommended for SQL Server; for more
information… http://support.microsoft.com/kb/304261
RAID Recommendations
Use RAID 1+0 Volume for data files; if not possible, then use RAID 5
Note… data files are used in parallel; if all data files have empty space, SQL Server
will write in all of them at the same time; but when one data file gets filled, SQL
Server will increase this only file and by default will continue writing 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 order to be able to write in data files
at the same time, these data files need to have available space
Use RAID 1+0 Volume for log file; if not possible, then use RAID 1
Note… log files are used sequentially; SQL Server will not use multiple log files at
the same time; when the first log file fills up, then the second one is used.
Installation Tip #9
Stripe tempdb, User Data & Log Files (cont.)

Stripe tempdb and User data files


Note… every data file should have enough free space!
Create a data file per CPU in the Primary Filegroup
Create 1 data file per single-core CPU socket
Create 1 data file per single-core CPU socket which has Hyperthreading
ON
Create 2 data files per dual-core CPU socket
Create 4 data files per quad-core CPU socket
Single Table and/or Index Moved into separate Filegroup
You can create a separate filegroup attached to a dedicated storage, so you can
move a table and/or index into the new storage
DON’T PLACE DATA OR LOG FILES ON COMPRESSED
VOLUMES
Installation Tip #10
Instance Configuration
Run Jorge Sanchez’s SQL_Instance_Report script, version-2
SQL Server Options should be let
Processors - Boost SQL Server Priority should be disabled (default =
disabled), specially in failover clustering configuration
Where? Management Studio, right-click [server_name], Properties, then
Processors page
Advanced – Max Degree of Parallelism (default = 0, all available CPUs)
Note: this option does not requires restart the engine
Value = 0  uses all CPUs available
Value = 1  don’t use parallelism; use one (1) CPU per query
Value = n  uses “n” CPUs available
Recommendations
In OLTP, Test first with Value = 0 (all CPUs) then Value = 1 (No parallelism)
In DW, Reports, etc. Value = 0.5x of Cores (Example… 4 : 8 Cores)

http://support.microsoft.com/kb/319942
http://blogs.technet.com/mat_stephen/archive/2005/02/08/369120.aspx
Installation Tip #11
Simple Recovery Model
To maintain log file size into minimum, change the database’s Recovery
Model  SIMPLE
tempdb should be in SIMPLE Recovery Mode
Backup strategies should be changed because in this mode, Full,
Differential and Filegroup backups can be made… Log backups are not
permitted.
Also, remember that Transactional Replication, Log Shipping, and Database
Mirroring requires the Recovery Model to be FULL
Installation Tip #12
Check Database Integrity and Statistics

DBCC CheckDB
EXEC sp_updatestats
EXEC sp_spaceused
Installation Tip #13
Stored Procedures
Always use stored procedure for any SELECT, INSERT, UPDATE, or
DELETE activity
Since T-SQL command gets parsed before saving the stored procedure into the
database, the engine do not need to parse commands again
The stored procedure gets compiled into memory after the first run, so it runs
faster
Installation Tip #14
Indexes
Every table should have a Clustered Index by the column(s) more used… not
necessarily by the Primary Key
The rest of Non-Clustered Indexes (up to 249 per table) should be created after the
Clustered Index
Indexes should be reorganized (defragged) or reconstructed
If fragmentation is…
Between 5% and 30%  ALTER INDEX REORGANIZE
Greater than >30%  ALTER INDEX REBUILD WITH (ONLINE = ON)
Note… See a SQL Server 2008/2005 sample script in next slide

http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/clusivsh.mspx
Installation Tip #14
Indexes
FILLFACTOR and PAD_INDEX Options
FILLFactor will instruct that index pages in the leaf-level should be fill up to the
percentage specified
PAD_INDEX will instruct that the rest of index pages (non leaf-level) should be fill up to
the percentage specified

http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/clusivsh.mspx
Installation Tip #14 Works only in
SQL Server
Indexes (cont.) 2008/2005

-- Ensure a USE <databasename> 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

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, '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 slide’s speaker notes)
http://msdn.microsoft.com/en-us/library/ms188917(SQL.90).aspx
Installation Tip #14 Works only in
SQL Server
Indexes (cont.) 2008/2005

-- Loop through the partitions.


WHILE (1=1)
BEGIN;
FETCH NEXT
FROM partitions
INTO @objectid, @indexid, @partitionnum, @frag;
IF @@FETCH_STATUS < 0 BREAK;
SELECT @objectname = QUOTENAME(o.name), @schemaname = QUOTENAME(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 = QUOTENAME(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;

Continues in next slide…


(For the complete script, open this slide’s speaker notes)

http://msdn.microsoft.com/en-us/library/ms188917(SQL.90).aspx
Installation Tip #14 Works only in
SQL Server
Indexes (cont.) 2008/2005

-- 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 slide’s speaker notes)

http://msdn.microsoft.com/en-us/library/ms188917(SQL.90).aspx
Installation Tip #14
Indexes (cont.)

Script results from the AdventureWorksDW


database; some indexes REBUILD and some
REORGANIZE
Installation Tip #15
Profiler + Database Engine Tuning Advisor

Use Profiler to capture SQL Server activity and Analyze it with the
Database Engine Tuning Advisor
In Profiler, use the Tuning template
Installation Tip #15
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
Installation Tip #15
Profiler + Database Engine Tuning Advisor
In the [Events Selection] tab, click [Columns
Filters] commandbutton, select DatabaseName and in
the Like section, type the database’s name to be
evaluated; click OK and click Run
Installation Tip #15
Profiler + Database Engine Tuning Advisor

Now Profiler is waiting to capture any command


against the database evaluated
Installation Tip #15
Profiler + Database Engine Tuning Advisor

Run load against the database evaluated


Installation Tip #15
Profiler + Database Engine Tuning Advisor

Profiler captured commands against the database


evaluated; now, stop the trace
Installation Tip #15
Profiler + Database Engine Tuning Advisor

In Management Studio, click Tools and select


Database Engine Tuning Advisor
Installation Tip #15
Profiler + Database Engine Tuning Advisor

Create a new session, load the workload file


saved by Profiler, select the database to be
evaluated and click the [Start Analysis]
commandbutton
Installation Tip #15
Profiler + Database Engine Tuning Advisor

The Database Engine Tuning Advisor will present a


report of recommended CREATE and DROP indexes;
if you want to apply them, go to the Actions menu
and select Apply Recommendations
Installation Tip #16
Best Practices Analyzer
Install and Run the Best Practice Analyzer (BPA) tool
This tool will evaluate a SQL Server Instance and will report recommendations
based on best practices
For Download…
SQL Server 2005
http://www.microsoft.com/downloads/details.aspx?FamilyID=DA0531E4-E94C-499
1-82FA-F0E3FBD05E63&displaylang=en
SQL Server 2000
http://www.microsoft.com/downloads/details.aspx?FamilyID=b352eb1f-d3ca-44ee-8
93e-9e07339c1f22&DisplayLang=en
Installation Tip #16
Best Practices Analyzer (cont.)
Installation Tip #17
SQL CAT (Customer Advisory Team)

http://sqlcat.com/Default.aspx
Installation Tip #18
SQL Server 2008 Performance New Features

Resource Governor
Performance Data Collectors and Reports
Table and Index Compression
Backup Compression
FILESTREAM Data Type
Sparse Columns
Data (only) and Time (only) Data Types
Partition Table Parallelism
Query Optimization
Installation Tip #19
Web References

Best Practices
Host Bus Adapters (HBA)
Queue Length >= 32 (or = 256 in fiber channel connections)
 Best Practices (cont.)
Database Architecture
TempDB relocation
In DW, TempDB size should match at least, the size of largest fact table (1.5x
recommended)
Filegroups (Primary Filegroup with most important tables, Multiple filegroups
per table, etc.)
Data Files should have FILEGROWTH = 0
When all data files in a filegroup are full, only one data file will be increased, so one CPU (core)
will work at 100% will other CPUs (cores) are idle
Log File should enable FILEGROWTH to 50%.
Data files per CPU core (1 Data File :1 CPU Core)
TempDB Recorvery Model = SIMPLE
Separate TempDB, Data, Log (only one disk array), and Indexes into separate
data files
Initial Log File size should be big and Autogrow should be 50%.
Multiple instances for separate TempDBs
 Best Practices (cont.)
Table Architecture
Indexes (Clustered, Non-Clustered, Fill Factor, Pad Index
Primary Key, Foreign Key, Referential Integrity for OLTP
No RI for DW/DM.
Fact tables
Create Clustered Index on (DateKey)
Create Nonclustered Indexes including the clustered field (ej.
(CustomerKey, DateKey)
Dimension tables
Create Clustered Index on Business Key Instead of Dimension Key
Create Nonclustered Primary Key on Dimension Key
Query Architecture
Display Estimated Execution Plan
Profiler
Best Practices (cont.)
ETL – Integration Services
Deploy SSIS 64-Bit to address > 4GB RAM
SSIS 32-bit uses up to 3GB (boot.ini with /3GB)
Modular Architecture – Every table should have its own package
Shared Connectors
Include Audit

Cubes
Deploy SSAS 64-bit for to address > 4GB RAM
SSAS 32-bit uses up to 3GB (boot.ini with /3GB)
Have only natural hierarchies
Partitions
30% Aggregates
Best Practices (cont.)
Reporting Services
Scaling Up
2-PROCs with Local Catalog Database
4-PROCs with Remote Catalog Database
>4-PROCs, change to 64-Bit
Platform
32-Bit Systems: Use /3GB in C:\boot.ini
Use 64-Bit Systems: X64, IA64
Memory
Limit Max. RAM in the RDBMS if the same server uses also SSRS
Files
Partition the ReportServerTempDB database, by create data files equal CPUs
Partition the ReportServer database, separate data files and log files into different
arrays; also, spread data files into separate arrays
Best Practices (cont.)
Reporting Services
Images
Use .gif or .jpeg, instead of .bmp.

IIS Configuration
In the Application Pool
Increase the Idle Timeout property (for example: 1440 mins.)

Increase the Maximum Worker Processes to the Same Amount of CPUs (cores)

Cache
Execute Reports from Cached or Snapshot Data

Performance Tuning
Configure the Report Server Execution Log to determine the amount of time
executing the query (TimeDataRetrieval), the time processing the report
(TimeProcessing), the time rendering the report (TimeRendering).
Best Practices (cont.)
Reporting Services
Create Report Templates
Copy .rdl files in…
C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\PrivateAssemblies\ProjectItems\ReportProject\

More Information
Planning for Scalability and Performance with Reporting Services
http://www.microsoft.com/technet/prodtechnol/sql/2005/pspsqlrs.mspx
Certifications
MCITP: Database Administrator

http://www.microsoft.com/learning/mcp/mcitp/dbadmin/default.mspx
Certifications
MCITP: Database Developer

http://www.microsoft.com/learning/mcp/mcitp/dbdev/default.mspx
Certifications
MCITP: Business Intelligence Developer

http://www.microsoft.com/learning/mcp/mcitp/bid/default.mspx
Certifications
MCM: Master Program

http://www.microsoft.com/learning/mcp/master/register/default.mspx
Certifications
MCA: Architect Program

http://www.microsoft.com/learning/mcp/architect/database/default.mspx
Books
Microsoft Press - Inside Series
1. Inside Microsoft® SQL Server™ 2005: The Storage Engine
Author : Kalen Delaney (Solid Quality Learning)
Pages : 464
Level : Int/Adv
Published : 10/11/2006
ISBN : 9780735621053
ISBN-10 : 0-7356-2105-5
Web : http://www.microsoft.com/MSPress/books/7436.aspx

2. Inside Microsoft® SQL Server™ 2005: Query Tuning and Optimization


Author : Kalen Delaney, S. Agarwal, C. Freedman, A. Machanic, R. Talmage
Pages : 448
Level : Int/Adv
Published : 09/26/2007
ISBN : 9780735621961
ISBN-10 : 0-7356-2196-9
Web : http://www.microsoft.com/MSPress/books/8565.aspx
Books
Microsoft Press - Inside Series
3. Inside Microsoft® SQL Server™ 2005: T-SQL Querying
Author : Itzik Ben-Gan (Solid Quality Learning), Lubor Kollar, Dejan Sarka
Pages : 640
Level : Int/Adv
Published : 03/29/2006
ISBN : 9780735623132
ISBN-10 : 0-7356-2313-9
Web : http://www.microsoft.com/MSPress/books/9615.aspx

4. Inside Microsoft® SQL Server™ 2005: T-SQL Programming


Author : Itzik Ben-Gan (Solid Quality Learning), Dejan Sarka; Roger Wolter
Pages : 544
Level : Int/Adv
Published : 05/17/2006
ISBN : 9780735621978
ISBN-10 : 0-7356-2197-7
Web : http://www.microsoft.com/MSPress/books/8564.aspx
Jorge Sánchez
Senior Technology Solutions Professional
Enterprise Data PlatformSpecialist
Microsoft Multi Country Americas
[email protected]
Cel. (787) 487-2977

© 2008 Microsoft Corporation. All rights reserved.


This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

You might also like