Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT...

20
Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft SQL Server MCTS Web Development MCP

Transcript of Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT...

Page 1: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Implementing Database Snapshot & Database Mirroring in SQL Server 2005

Presented by Tarek GhazaliIT Technical SpecialistMicrosoft SQL Server MVPMicrosoft SQL Server MCTSWeb Development MCP

Page 2: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database Snapshot Recovering from Human Error

• Snapshot of an entire database at a point in time– Great to recover from User Error– Created instantly– Read only

• Works with– Single server– Database Mirroring– Failover Cluster

• Base database continues to change– Database Snapshot does not restrict the base database

• Multiple Snapshots are allowed

Page 3: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database Snapshot How it really works

dbSnap – Read-Only Database SnapshotUSE dbSnapUSE dbSnapSELECT SELECT (pages 4, 6, 9, 10, 14)(pages 4, 6, 9, 10, 14)

11

Page

22 33 44 55 66 77 88 99 1010 1111 1212 1313 1414 1515 1616

CREATE DATABASE dbSnap AS SNAPSHOT OF mydbCREATE DATABASE dbSnap AS SNAPSHOT OF mydb

mydb – Database

USE mydbUSE mydbUPDATEUPDATE (pages 4, 9, 10) (pages 4, 9, 10)

44 99 101011 22 33 44 55 66 77 88 99 1010 1111 1212 1313 1414 1515 1616

Page 4: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Value

R

D

B

H

J

L

Y

M

Space Used

Command

Create Northwind_SS

Northwind Northwind_SS

Update Northwind

0%

Value

DX

Read Northwind_SS

12.5%

Result:

Snapshot (Copy on Write)

DD

Page 5: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database Snapshot How it really works (Cont)

A sparse file is an essentially empty file that contains no user data andhas not yet been allocated disk space for user data. As more and more pages are updated in the source database, the size of the file grows.

Page 6: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Constraints on the Source Database

• DB snapshot and source database must be on the same instance

• If any db snapshots exist on a source database, the source database cannot be dropped or restored– first delete all the db snapshots

• However, backing up the source database works normally; it is unaffected by DB snapshots

Page 7: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Considerations of DB Snapshots

• None of the specifications of the files of the DB Snapshot can be changed

• A DB Snapshot inherits the security constraints of its source database– DB snapshots are read-only, inherited permissions cannot be changed– If you drop a user from the source DB, it is still in the snapshot

• To prevent future access you can drop\disable the login• Snapshots cannot be backed up (or restored)• Snapshots cannot be attached (or detached)• Snapshots cannot be created on FAT32 or RAW partitions• Full-text indexing is not supported on Database Snapshots, and full-

text catalogs are not propagated from the source database

Page 8: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database Snapshot How much Space Used?

• Size Based on Update Patterns– View the sparse files (sys.master_files)– View the Maximum Size Possible– View the Actual Size

• Select the size column from sys.master_files. The size column in sys.master_files reflects the maximum space, in SQL pages, that the snapshot can ever use; this value is equivalent to the Windows Size field, except that it is represented in terms of the number of SQL pages in the file; the size in bytes is:

( number_of_pages * 8192)

Page 9: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database Snapshot How much Space Used? (Cont)

Use Windows Explorer to right click on the NTFS sparse file 'C:\AWDW.SNP' and select PropertiesLook at the “Size” and you will see it is similar to the size of the source database fileHowever, look at the “Size on Disk” and you will see how much space is REALLY used

Page 10: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Demo

Page 11: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

High Availability Solutions Overview

• SQL Server provides several options for creating high availability for a server or database. – Failover clustering – Database mirroring – Log shipping – Replication

Page 12: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database MirroringNew for SQL Server 2005

• Instant Stand-By• Fault Tolerant Virtual Database• Very fast Failover (3 sec)– No Data-Loss• Automatic, Transparent Client-Redirect• Automatic Re-Sync after Failover

Principal

Client

Witness

MirrorClient

Page 13: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database MirroringOverview of Database Mirror

• Mirroring allows the user to create an exact copy of a database on a different server.

• The mirrored database must reside on different instance of SQL Server Database engine.

Page 14: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database MirroringSQL Server 2005 RTM ,SP1,SP2

• Microsoft fully supports database mirroring with SQL Server 2005 SP1,SP2 onwards.

• For the RTM release (prior to SP1), Microsoft support services will not support databases or applications that use database mirroring. The database mirroring feature should not be used in production environments. Prior to SP1, database mirroring is disabled by default, but can be enabled for evaluation purposes by using trace flag 1400.  The following T-SQL statement can be used to achieve this:DBCC TRACEON(1400)

Page 15: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Transparent Client Redirect

• No changes to application code• Client automatically redirected if

session is dropped• MDAC is aware of Principal and Mirror servers

– Upon initial connect to Principal, MDAC caches Mirror name

– When client attempts to reconnect• If Principal is available, connects• If not, MDAC automatically redirects connection to Mirror

Page 16: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database MirroringSynchronous Mode

• This is also called as high safety mode.– In this mode, every transaction applied to the

principal will also be committed on the mirror server.

• The transaction on the principal will be released only when it is also committed on the mirror.

• High safety mode with/without automatic failover

Page 17: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Database MirroringAsynchronous Mode

• This is also known as the high performance mode. – Here performance is achieved at the cost of availability.

• In this mode, the principal server sends log information to the mirror server, without waiting for an acknowledgement from the mirror server.

• This mode allows the principal server to run with minimum transactional latency and does not allow the user to use automatic failover

Page 18: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Failover SolutionsClustering and Mirroring Compared

• Both Provide– Automatic Detection and Failover– Manual Failover– Transparent Client Redirect– Zero Work Loss

• Database Mirroring– Database scope

– Standard servers

– Fastest failover

– Limited reporting on standby

– Duplicate copy of database

• Failover Clustering– System scope

– Certified hardware

– Fast failover

– No reporting on standby

– Single copy of database

Page 19: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Demo

Page 20: Implementing Database Snapshot & Database Mirroring in SQL Server 2005 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft.

Resources & Questions

• Microsoft Resources:- msdn.microsoft.com/sqlserver/

- www.microsoft.com/sql/community

• Contact me: - [email protected]

• Download Presentation :- www.sqlmvp.com