24
Managing SQL Server (for Admins Managing SQL Server (for Admins Who Who d Really Rather Not) d Really Rather Not) Don Jones Don Jones Senior Partner & Principal Technologist Concentrated Technology, LLC

Managing SQLserver

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Managing SQLserver

Managing SQL Server (for Admins WhoManaging SQL Server (for Admins Who’’d d Really Rather Not)Really Rather Not)Don JonesDon JonesSenior Partner & Principal TechnologistConcentrated Technology, LLC

Page 2: Managing SQLserver

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC

Page 3: Managing SQLserver

IntroductionsIntroductions

Me: Don Jones, Concentrated Technology– Microsoft MVP Award recipient– Contributing Editor, TechNet Magazine– Author of 45+ IT books– Blogger at http://ConcentratedTech.com

You: The “Microsoft Person” in your environment– Not primarily concerned with supporting

Microsoft SQL Server…– …but more or less forced to do so anyway

Page 4: Managing SQLserver

AgendaAgenda

Peeking Under the Hood: How SQL Server Works

Backup and Restore Operations About the Query Optimizer Index Maintenance and Tuning Key Database Configuration Options SQL Server Security Model Key Server Configuration Options High Availability and Replication

Options

Page 5: Managing SQLserver

How SQL Server Works, Part 1How SQL Server Works, Part 1

SQL Server stores data in 8KB chunks called “pages”

It always deals with data in these 8KB chunks

Generally speaking, all data for a single table row must fit onto a single page– It’s actually possible for certain types of data to

spread across multiple pages– Sometimes, the page can contain a pointer to a

file on disk – the FILESTREAM data type

The pages live in one or more files (.MDF, .NDF) on disk, but are always read or written in 8KB units

Page 6: Managing SQLserver

How SQL Server Works, Part 2How SQL Server Works, Part 2

When a query is issued that results in data being changed, added, or deleted:1. SQL Server makes a note of the query in its

transaction log

2. The database engine determines what page(s) are affected by the change

3. The affected pages are loaded into server memory

4. The changes are made in memory

• At this stage, the changes have been completed only in RAM.

• If something else reads those pages, they’re already handy in memory.

Page 7: Managing SQLserver

How SQL Server Works, Part 3How SQL Server Works, Part 3

Eventually, the modified pages are written to disk.

When this happens, SQL Server “checks off” the associated query in the transaction log.

In the event of a sudden failure:– When SQL Server restarts, it looks to see

if any “un-checked” queries are in the log.– If so, it “re-plays” those queries to bring

the database up to speed.

If you have the transaction log, you can recover the data!

Page 8: Managing SQLserver

SQL Server BackupsSQL Server Backups

Three types:– Full – Backs up the entire database and

removes (“truncates”) all “checked” entries from the transaction log

– Differential: Only what’s changed since the last Full; also truncates the log

– Transaction log: Only grabs the current transaction log; truncates the active log afterward

Page 9: Managing SQLserver

Restoring a DatabaseRestoring a Database

1. Start with the most recent Full backup• Leave the database in “restore mode” if you

have other files

2. Apply the most recent differential• Stay in “restore mode” if you have more files

3. Apply any transaction logs since the differential was made• When finished, allow recovery to begin

• Maximum amount of data at-risk: Any changes made since the most recent transaction log backup

• Moral: Frequent T-Log backups!

Page 10: Managing SQLserver

IndexesIndexes

Two types:– Clustered

Every table has one, even if it’s just on the row ID number.

Governs the order in which data is logically stored

Should be on whatever column is used most for lookups or table joins

– Non-ClusteredEvery table can have zero or moreActs as a literal index, keeping

entries in order by the indexed column and pointing to the full data row

A “covering” index is one that contains entries for every column being queried

Page 11: Managing SQLserver

Indexes: Pros and ConsIndexes: Pros and Cons

Pros– Indexes can speed up the time it takes to find

data

– Also speed up sort times

– Ideally, index on all columns that are frequently used in a WHERE or ORDER BY clause

Cons– Indexes slow down data add/change/delete

operations, because indexes must also be updated

– Ideally, index nothing

The reality is a balancing act: Building indexes on columns that deliver the most benefit, with the least downside

Page 12: Managing SQLserver

Index Problem: FragmentationIndex Problem: Fragmentation

Occurs when index pages become full and data needs to be inserted into the middle

A “page split” occurs to make room for the new entry, causing the pages to be “out of order” – this decreases performanceAndrew

AndrewsBatistaBarbaraCharlesCharlie

FrankGary

GrossmanHughInaJack

JacksonJones

Kimberly

DonavanEricErin

NEW!NEW!

Page 13: Managing SQLserver

Fixing FragementationFixing Fragementation

Reorganizing or Rebuilding the index will put the entries and pages back into the correct order, improving performance

You can specify a “fill factor” that leaves empty space for new entries without splitting pages as often

However, emptier pages mean SQL Server has to work harder to read the same amount of data – so this is a balancing act

Page 14: Managing SQLserver

RulesRules

Fragmentation 30%+ = Rebuild– Rebuild with ONLINE option in 2005+ to

avoid locking table(s) (unless it has BLOBs)– Recomputes statistics– Takes more overhead– Needs free disk space

Fragmentation 10%-30% = Reorg– Requires less overhead (just swaps pages)– Always “online”– Less effective

14 • Don Jones • ConcentratedTech.com

Page 15: Managing SQLserver

Index TuningIndex Tuning

The indexes that made sense for a database on day 1 might not make sense after it has been in use for some time

You can use SQL Profiler to capture real-world, representative query traffic…

…and feed that to the Database Engine Tuning Advisor to get recommendations on index improvements

The Advisor can even help you implement those changes that you decide to proceed with

Page 16: Managing SQLserver

Key Database Options and Best Key Database Options and Best PracticesPractices Allow statistics to Auto-Create/Update

– This makes sure the Query Optimizer knows which indexes exist and what kind of condition they are in

Consider disabling auto-growth, or at least monitor it– Auto-Grow can consume time; better to

manually size the database files appropriately Disable Auto Close except on infrequently-used

databases– Closed databases incur a performance hit

when someone queries them since SQL Server has to open the file

Page 17: Managing SQLserver

SQL Server Security ModelSQL Server Security Model

Login: Map to a Windows user/group, or an in-server credential; gets you access to the server

Server Role: Contains logins, and defines server-wide privileges

Database user: Maps to a login, and gets you into a database

Database Role: Contains database users, and defines in-database privileges

Custom Database Role: Same as the built-in ones, but you define the permissions

App Role: Shortcut login+database user+permissions designed to be activated by an application that defines its own security layer for the data.

Page 18: Managing SQLserver

Server OptionsServer Options

Authentication Mode: “Windows” or “Windows+SQL Server”

Memory and Processor options (typically, leave alone)

Instances– Each “instance” is an independent installation of

SQL Server

– Has its own “server-wide” options (“instance-wide” is a better term)

– Default instance: Connect using server name

– Other instances: Connect using SERVER\INSTANCE format

– Review list of services to see instances – each instance has its own SQL Server service

Page 19: Managing SQLserver

High Availability OptionsHigh Availability Options

Log Shipping Database Mirroring Windows Clustering

Page 20: Managing SQLserver

Replication OptionsReplication Options

Snapshot Transactional Transactional with Updating

Subscribers Merge

Off-Topic: Microsoft Sync Framework / Sync Services for ADO.NET

Page 21: Managing SQLserver

Final ThoughtsFinal Thoughts

SQL Server Agent (and Jobs, Operators, and Alerts)

Multi-Server Admininstration

Page 22: Managing SQLserver

ConclusionConclusion

A few basic admin skills can help you perform the most often-needed SQL Server tasks

Keep in mind that the SQL Server Management Studio can connect to multiple servers for single-seat administration

Page 23: Managing SQLserver

Final Notes…Final Notes…

Please be sure to submit a session evaluation form!

Download slides & materials from www.ConcentratedTech.com within one week!

Blog, URLs, and other information is also available at www.ConcentratedTech.com for your reference

Thank you very much!

23 • Don Jones • ConcentratedTech.com

Page 24: Managing SQLserver

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC