75
SQL Server 2008 for Developers UTS Short Course

SQL Server Database Mirroring Concept

Embed Size (px)

Citation preview

Page 1: SQL Server Database Mirroring Concept

SQL Server 2008 for DevelopersUTS Short Course

Page 2: SQL Server Database Mirroring Concept

Specializes in

C# and .NET (Java not anymore)

TestingAutomated tests

Agile, ScrumCertified Scrum Trainer

Technology aficionado • Silverlight• ASP.NET• Windows Forms

Peter Gfader

Page 3: SQL Server Database Mirroring Concept

http://sharepoint.ssw.com.au/Training/UTSSQL/Pages/

Course Timetable Course Materials

Course Website

Page 4: SQL Server Database Mirroring Concept

Course OverviewSession

Date Time Topic

1Tuesday03-08-2010

18:00 - 21:00

SQL Server 2008 Management Studio

2Tuesday10-08-2010

18:00 - 21:00

T-SQL Enhancements

3 Tuesday17-08-2010

18:00 - 21:00 High Availability

4Tuesday24-08-2010

18:00 - 21:00

CLR Integration

5Tuesday31-08-2010

18:00 - 21:00

Full-Text Search

Page 5: SQL Server Database Mirroring Concept

Basic T-SQL syntax

New Data Types

Inline variable assignment

Table Value Parameters

DDL (Data Definition Language) Triggers

CTE (Common Table Expressions)

TOP % WITH TIES

XML Queries

PIVOT/UNPIVOT

What we did last week

Page 6: SQL Server Database Mirroring Concept

Homework?

Page 7: SQL Server Database Mirroring Concept

CREATE DATABASE SSW_TrainingGO

USE SSW_TrainingGO

CREATE LOGIN LOG_USER WITH PASSWORD=N'LOG_u$er_01', DEFAULT_DATABASE=SSW_TrainingGO

CREATE USER LOG_USER FOR LOGIN LOG_USERGO

EXEC sp_addrolemember N'db_datareader', N'LOG_USER'GOEXEC sp_addrolemember N'db_datawriter', N'LOG_USER'GO

Page 8: SQL Server Database Mirroring Concept

CREATE TABLE [ServerLogins](ID bigint IDENTITY(1,1) NOT

NULL, [DateTime] datetime, PostTime nvarchar(100), LoginName nvarchar(100), EventType nvarchar(100), ClientHost nvarchar(100), [EVENTDATA] xml

) ON [PRIMARY]GO

Page 9: SQL Server Database Mirroring Concept

CREATE TRIGGER logon_trigger_login_logON ALL SERVER WITH EXECUTE AS 'LOG_USER'FOR LOGONAS

DECLARE @data xmlSET @data = EventData()INSERT INTO SSW_Training.dbo.ServerLogins([DateTime],

PostTime, LoginName, EventType, ClientHost, [EventData])VALUES(GETDATE(), CONVERT(nvarchar(100), @data.query('data(//PostTime)')), CONVERT(nvarchar(100), @data.query('data(//LoginName)')), CONVERT(nvarchar(100), @data.query('data(//EventType)')), CONVERT(nvarchar(2000), @data.query('data(//ClientHost)')), EVENTDATA())

GO

Page 10: SQL Server Database Mirroring Concept

SELECT geometry::STGeomFromText('LINESTRING (0 0,

0 2, 1 3, 2 2, 2 0, 0 2, 2 2, 0 0, 2 0)', 0)

Envelope;

Homework?

Page 11: SQL Server Database Mirroring Concept

SQL 2008 High Availability Features

Session 3

Page 12: SQL Server Database Mirroring Concept

What is High Availability?

What can go wrong?

What can we do about it?

AgendaAgenda

Page 13: SQL Server Database Mirroring Concept

Different people have different definitions

Perceived uptime Performance

What can go wrong?

How can we improve it?

What is high availability?

Page 14: SQL Server Database Mirroring Concept

Different people have different definitions

Perceived uptime Performance Issues

What can go wrong?

How can we improve it?

What is high availability?

Page 15: SQL Server Database Mirroring Concept

Hardware Disk failure Network failure Power Outages

What can go wrong? (continued)

Page 16: SQL Server Database Mirroring Concept

Software Virus (and Virus Scanners) – File locking issues Disk space Corrupted files Bad upgrades OS Upgrades

SQL poor tuning or design DB Maintenance

What can go wrong?

Page 17: SQL Server Database Mirroring Concept

People (PEBKAC)

Administrators Users

• Bottlenecks & Concurrency

Acts of God

Lightning Cleaners

What else can go wrong?

Page 18: SQL Server Database Mirroring Concept
Page 19: SQL Server Database Mirroring Concept

1. Hardware Solutions• UPS & Hardware Monitors• RAID / Mirroring• Off site server• Firewall• Physical Security

What can we do about it? (continued 3-1)

Page 20: SQL Server Database Mirroring Concept

2. Software Solutions• Database Mirroring• Log shipping

– Auto backup transaction log, and restore• Replication (Can also reduce availability)

– Monitor, Change• Database Snapshots• Alerts

– OS: Disk Space, ...– DB: Logs,...

• Partitioned Tables• Firewalls

What can we do about it? (continued 3-2)

Page 21: SQL Server Database Mirroring Concept

3. OS Level / Backup Solutions• Security• Change Management• Performance Monitoring/Tuning• Hot/Warm/Cold standby servers• Standard daily backups

– Verified procedure– Transaction logs

What can we do about it? (3-3)

Page 22: SQL Server Database Mirroring Concept

Implementing Database Snapshots

Configuring a Database Mirror

Partitioned Tables

SQL Agent Proxies

Performing Online Index Operations

Mirrored Backups

What Will We Cover?

Page 23: SQL Server Database Mirroring Concept

Database Snapshots

Page 24: SQL Server Database Mirroring Concept

Database Snapshots

Page 25: SQL Server Database Mirroring Concept

Mirroring for reporting

Recover from administrative error

Point-in-time reporting

Protection from application or user error

Page 26: SQL Server Database Mirroring Concept

Snapshots are NOT a substitute for your backup and

recovery setup

You cannot roll forward

If either the database or the database snapshot is

corrupted, reverting from a snapshot is unlikely to

correct the problem

Query from snapshot current database

Database Snapshots

Page 27: SQL Server Database Mirroring Concept

CREATE DATABASE AdventureWorks_dbss1800 ON( NAME = AdventureWorks2008_Data, FILENAME = 'C:\data\AdventureWorks_data_1800.ss' )AS SNAPSHOT OF AdventureWorks;GO

Database Snapshots

Page 28: SQL Server Database Mirroring Concept

Database Snapshots

Page 29: SQL Server Database Mirroring Concept

Snapshot vs. Backup vs. Detach

Snapshot• Only go back• SELECT statements

Backup• Rollback and Forward possible• Smaller

Detach database and copy• DB goes offline• Closes all connections

Page 30: SQL Server Database Mirroring Concept

Database mirror

Page 31: SQL Server Database Mirroring Concept

No special hardware

Configuring a Database Mirror

Page 32: SQL Server Database Mirroring Concept

Configuring a Database Mirror

Easy to setup

Zero committed work lost Maximum one mirror per DB

Transparent client redirect

Page 33: SQL Server Database Mirroring Concept

Virtually no distance limitations

No special hardware

Configuring a Database Mirror

Page 34: SQL Server Database Mirroring Concept

Clients

Principal Server

Witness Server

Mirror Server

Configuring a Database Mirror

Page 35: SQL Server Database Mirroring Concept

Configuring a Database Mirror

Clients

Witness Server

Mirror Server

Principal Server

Page 36: SQL Server Database Mirroring Concept

Clients

Witness Server

Mirror Server

Principal Server

Configuring a Database Mirror

Page 37: SQL Server Database Mirroring Concept

1. Principal

1. Take a full backup and a log backup as well2. Copy the full/log backups from Principal Instance to

Mirror instance

2. Mirror

1. Restore with NORECOVERY option the full backup2. Apply the log backup

Before you mirror your database

Page 38: SQL Server Database Mirroring Concept

Using the Mirror Wizard

Page 39: SQL Server Database Mirroring Concept
Page 40: SQL Server Database Mirroring Concept
Page 41: SQL Server Database Mirroring Concept
Page 42: SQL Server Database Mirroring Concept

Configure End Point on the Principal

Page 43: SQL Server Database Mirroring Concept

Configure End Point on the Mirror

Page 44: SQL Server Database Mirroring Concept

Set the service accounts

Use NT AUTHORITY\NETWORK SERVICE

Page 45: SQL Server Database Mirroring Concept
Page 46: SQL Server Database Mirroring Concept

Mirror is configured

Page 47: SQL Server Database Mirroring Concept

Warning about FQDN

Page 48: SQL Server Database Mirroring Concept

Mirror Operating Modes

High Performance (asynchronous)

Commits are done on the principal and transferred to the mirror

High Safety (synchronous)

Commits are written to both databases

Page 49: SQL Server Database Mirroring Concept
Page 50: SQL Server Database Mirroring Concept

Database Mirroring Failover

What happens when something bad happens to our principal server…

You can make it failover to the mirror

This means that the two servers swap roles for the time being

Page 51: SQL Server Database Mirroring Concept
Page 52: SQL Server Database Mirroring Concept

Database Mirroring Monitor

Lets you view the status and history of your current mirrors

Page 53: SQL Server Database Mirroring Concept
Page 54: SQL Server Database Mirroring Concept
Page 55: SQL Server Database Mirroring Concept

Thresholds

Page 56: SQL Server Database Mirroring Concept
Page 57: SQL Server Database Mirroring Concept

Might come in handy

Disable MirroringALTER DATABASE myDatabase SET PARTNER OFF

Put DB from "Recovering..." into available online modeRESTORE DATABASE myDatabase WITH RECOVERY

Page 58: SQL Server Database Mirroring Concept

Partitioned tables

Page 59: SQL Server Database Mirroring Concept

Partitioned Tables

Page 60: SQL Server Database Mirroring Concept

Allows for maximum concurrency

Partitioned Table parallelism Improved a lot in SQL 2008

Archive older data into different filegroups

Partitioned Tables

Page 61: SQL Server Database Mirroring Concept

SQL Server agent

Page 62: SQL Server Database Mirroring Concept

Windows Service

Executes SQL Server jobs

Administrative tasks

SQL Server Agent (recap)

Page 63: SQL Server Database Mirroring Concept

New credential system

Sits on Active Directory

Fine grained control of your jobs

Jobs can be run by proxies instead of user loginsPreviously to run cmd shell type functionality you needed a user in the administrator group which opened up security problems

SQL Agent Proxies

Page 64: SQL Server Database Mirroring Concept

Online Index Operations

Page 65: SQL Server Database Mirroring Concept

Online Index Operations

Table

Index Created

- Table is accessible for read and update- Non-clustered indexes are available during clustered index creation

- Table is accessible for read and update- Non-clustered indexes are available during clustered index creation

Page 66: SQL Server Database Mirroring Concept

CREATE NONCLUSTERED INDEX IX_TextTable_MyKey

ON [TestTable] ([MyKey])

WITH (ONLINE = ON);

GO

Page 67: SQL Server Database Mirroring Concept

Mirrored Backups

Page 68: SQL Server Database Mirroring Concept

Mirrored Backup media

Mirror 2

Backup

Page 69: SQL Server Database Mirroring Concept

Mirrored Backup media

Mirror 2

Mirror 1

Page 70: SQL Server Database Mirroring Concept

Mirror 2

Mirror 1

Mirrored Backup media

Page 71: SQL Server Database Mirroring Concept

Implementing Database Snapshots

Configuring a Database Mirror

Partitioned Tables

SQL Agent Proxies

Performing Online Index Operations

Mirrored Backups

Session Summary

Page 72: SQL Server Database Mirroring Concept

High Availability Features

Database snapshots Mirrored backups Online Index Operations

Download from Course Materials Site (to copy/paste scripts) or type manually:

http://tinyurl.com/utssql2009

Session 3 Lab

Page 73: SQL Server Database Mirroring Concept

• Free chats and webcasts

• List of newsgroups

• Microsoft community sites

• Community events and columns

• SQL Server user groups (www.sqlserver.org.au)

• www.microsoft.com/technet/community

Where Else Can I Get Help?

Page 74: SQL Server Database Mirroring Concept

3 things…

[email protected]

u

http://

peitor.blogspot.com

twitter.com/peitor

Page 75: SQL Server Database Mirroring Concept

Thank You!

Gateway Court Suite 10 81 - 91 Military Road Neutral Bay, Sydney NSW 2089 AUSTRALIA

ABN: 21 069 371 900

Phone: + 61 2 9953 3000 Fax: + 61 2 9953 3105

[email protected]