SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

37
SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312

Transcript of SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Page 1: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

SQL Server AlwaysOn: Active Secondaries

Luis VargasProgram ManagerMicrosoft Corporation

DBI312

Page 2: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Understand the capabilities, limitations, and considerations

Understand how AlwaysOn (Availability Groups) Active Secondaries allow leveraging HA/DR hardware

Read WorkloadsBackups

Session Objectives

Page 3: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Agenda

AlwaysOn Active Secondaries

Offloading read workloads

Offloading backups

Page 4: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

AlwaysOn Active Secondaries

Cost-effectiveness is criticalIdle hardware represents wasted resourcesDatabase mirror server similar to primaryUtilization is low

AlwaysOn Active Secondaries allow using hardware for more than HA/DR: Offload work from primary

Read workloadsBackups

Page 5: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Active SecondariesOffloading Read Workloads

Page 6: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Running Read Workloads - BeforeDatabase Mirroring Transactional Replication

Run on primary Impacts workload

Run on mirror w/snapshotsData StalenessAdditional managementNo failover of read workloads

Run on a subscriberPros:

Large number of subscribersTargeted indexes

Cons: Separate solution to configure/manageNo failover of read workloads

Page 7: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Running Read Workloads - Now

DB2

DB1

SQL Server SQL Server

DB2

DB1

PrimaryActiveSecondary

ReportsLog Synchronization

DBs in active secondaries are readableCommitted transactions are visible eventually

When depends on log synchronization latency

Page 8: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Running Read Workloads - Now

DB2

DB1

SQL Server Primary

Up to 4 secondariesSync or async

Page 9: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Running Read Workloads - Now

DB2

DB1

SQL Server SQL Server

DB2

DB1

Primary Secondary

Log Synchronization

Reports

PrimarySecondary

Reports

ManualFailover

Read workloads can be automatically routed to an active secondary

Page 10: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

ALLOW_CONNECTIONS setting

Configuring Secondary as Readable

NO Don’t allow connections

READ_ONLY Only allow connections specifying READ_ONLY intent

ALL Allow all connections

ALTER AVAILABILITY GROUP ag_nameMODIFY REPLICA ON 'server_instance'WITH (

SECONDARY_ROLE ( ALLOW_CONNECTIONS = { NO | READ_ONLY | ALL } ) )

Page 11: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Clients can connect to readable secondary without changesSet ALLOW_CONNECTIONS = ALL

Clients Connectivity

Application IntentNew connection string propertySpecifies workload type: READ_ONLY / READ_WRITEOpens new capabilities

Disallow connectionsAutomatically route READ_ONLY connections to an active secondary

Page 12: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Configure Routing URL for each secondary

Configuring Routing of Read-Only Connections

ALTER AVAILABILITY GROUP ag_nameMODIFY REPLICA ON 'server_name'WITH (

SECONDARY_ROLE ( READ_ONLY_ROUTING_URL = ‘TCP://system-

address:port’ ) )

Page 13: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Create Routing List at each replica that can be primary

Configuring Routing of Read-Only Connections

ALTER AVAILABILITY GROUP ag_nameMODIFY REPLICA ON 'server_name'WITH (

PRIMARY_ROLE ( READ_ONLY_ROUTING_LIST = {'server_name'

[,..n]} ) )

Page 14: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

demo AlwaysOn: Active SecondariesOffloading Read Workloads

Page 15: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Log Synchronization to Secondary

Page 16: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Impact of Read Workload

Workload can take resources from Redo threadRedo can fall behind impact RTO

Mitigations:Use Resource GovernorNo workload on auto failover target

Page 17: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

DDL Redo can still be blocked by read workloadXEvent lock_redo_blocked

Contention between Redo and read workload avoided internally

Workload executed on Snapshot IsolationLocking hints ignoredRedo thread never a deadlock victim

Impact of Read Workload

Page 18: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Row versions must be created on the active secondaryStored in TempDB14 bytes needed for version pointer

Snapshot Isolation and Row Versioning

Primary and secondary must have same physical structureIf secondary is configured as active:

14 bytes added to rows on the primary (already if SI/RCSI enabled)

Page 19: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Query Optimization on Active Secondary

Query optimization relies on statisticsCreated by indexes and read workloads

Statistics created on primary are redone on secondary But, read workloads at secondaries are different from primary workloads

So, auto-create statistics on secondaryStore on TempDBsys.stats: is_temporary=‘true’

Use most recent statisticsRemove on failover, restart, or DROP STATISTICS

Page 20: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Active Secondaries

Offloading Backups

Page 21: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Creating Backups - Before

Primary Secondary

Failed

Backups Backups

Database Mirroring

R/W workload

Only on primaryImpacts primary workloadFails after failover

Page 22: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

R/W workload

PrimaryBackups

ActiveSecondary

Backups

ActiveSecondary

Backups

Creating Backups - Now

On primary or any secondaryNo need to configure secondaries as readable

Page 23: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Capabilities

Backup on sync or async secondaries

Full Backup (Copy-Only)Log Backup

Backup automation

No Differential Backup

Page 24: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Single Log Backup Chain

Page 25: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Backup Strategy

Full Backup (Copy-Only) and Log Backup on secondary

If Differential Backup is needed:Full Backup and Differential Backup on primaryLog Backup on secondary

Page 26: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Replica Priority0 (never) ... 100 (highest)

Backup Automation

Role PreferencePrimary OnlySecondary OnlySecondary If PossibleNone

Page 27: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Backup Automation

Filter out replicas that are not onlinedon’t meet role preference

Select highest-priority replicaReplica name as tie-breaker

Not enforced by BACKUPImplemented as a system function

sys.fn_hadr_backup_is_preferred_replica ('dbname')

Used byMaintenance Plan Wizard Log Shipping Wizard

Page 28: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Recommendations

Use Recovery Advisor

Store backups centrally

Page 29: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

demo

AlwaysOn: Active SecondariesOffloading Backups

Page 30: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Active Secondaries make AlwaysOn cost-effective

Summary

Use hardware for more than HA/DR: Offload work from primary

Read workloadsBackups

Page 31: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Resources

AlwaysOn Resource Center http://msdn.microsoft.com/en-us/sqlserver/gg490638.aspx

SQL Server 2012 Whitepapershttp://msdn.microsoft.com/en-us/library/hh403491

AlwaysOn Team Bloghttp://blogs.msdn.com/b/sqlalwayson/

Page 32: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Contacts

[email protected]

social.msdn.microsoft.com/Forums/en-gb/sqlhadr/

Page 34: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

Complete an evaluation on CommNet and enter to win!

Page 35: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

MS Tag

Scan the Tagto evaluate thissession now onmyTechEd Mobile

Page 36: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to

be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS

PRESENTATION.

Page 37: SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.