learn. connect. explore. - microsoft... · connect. explore. sql server 2014 : online operation...

26
Learn. Connect. Explore. Learn. Connect. Explore.

Upload: others

Post on 23-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Learn. Connect. Explore.Learn. Connect. Explore.

Page 2: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

SQL Server 2014 :Online Operation Enhancements

Vinod Kumar

Technical Architect – MTC

vinodk_sql

http://blogs.ExtremeExperts.com

Page 3: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

So is Online Truly Online??

Page 4: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Understand the changes to partition switching in SQL Server 2014

Understand the changes to online indexing options to manage OLTP workloads in SQL Server 2014

Session Objectives And Takeaways

Page 5: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Online

Operations

DemosBest PracticesManaged Lock

Priority

Single Partition Online

Index Rebuild

Page 6: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected
Page 7: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Partition SWITCHShort Sch-M lock on the source and

target tables

Online Index Rebuild (OIR) Short table S and Sch-M lock

Blocking transactions need to be

completed before DDL

SWITCH/OIR will block new

transactions

Workload slow down or timeouts

Impact to Tier1 mission-critical OLTP

workloads

Pro

ble

m

Sta

tem

en

tBlocking by online DDL operations Concurrency and throughput affected

Page 8: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Behavior without Managed Lock Priority

Lock QueueSession

Wait

Grant

51-SELECT

52-DDL

53-SELECT

54-SELECT

55-SELECT First In First Out

Page 9: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

MLP SWITCH/OIR – Options

Blocking user

transactions killed

Immediately or

specified wait time

MAX_DURATION* =n

minutes]

Wait for blockers

MAX_DURATION*

Regular lock queue

Kill all blockers Switch to normal queue

Wait for blockers

MAX_DURATION*

Terminates DDL

(SWITCH/OIR)

Exit DDL after wait

*If no blockers, lock granted immediately and the DDL statement will complete

successfully

Page 10: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

MLP SWITCH/OIR – Details

PARTITION SWITCHSch-M lock (source and destination)

Blocking by user transactions

Killed at source and destination tables

ONLINE INDEX REBUILDMAX_DURATION applies to every lock request

Time reset for every S & Sch-M lock

Only Sch-M lock conflict for read only workloads

BenefitsManaged by DBA for both partition switch and OIR

Lock request placed in lower priority queue

Decision to wait or kill self or blockers

Executed immediately if no blockers

Page 11: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

ALTER TABLE stgtab SWITCH PARTITION 1 TO parttab

PARTITION 1

WITH (WAIT_AT_LOW_PRIORITY (MAX_DURATION=

60 minutes,

ABORT_AFTER_WAIT=BLOCKERS))

ALTER INDEX clidx ON parttable REBUILD

WITH ( ONLINE=ON (WAIT_AT_LOW_PRIORITY

(MAX_DURATION= 300,

ABORT_AFTER_WAIT=SELF)) )

Examples

<low_priority_lock_wait>::=

{

WAIT_AT_LOW_PRIORITY ( MAX_DURATION =

<time>[MINUTES],

ABORT_AFTER_WAIT = { NONE | SELF | BLOCKERS } )

}

NONE - current behavior

SELF - abort DDL

BLOCKERS – abort user blockers

Syntax

MLP SWITCH/OIR – Syntax

New clause in existing T-SQL DDL for ALTER TABLE and

ALTER INDEX

SQL 2012 behavior – omit the

new clause or use

WITH (WAIT_AT_LOW_PRIORITY

(MAX_DURATION= 0

minutes,

ABORT_AFTER_WAIT=NONE))

Page 12: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Behavior with MLP

Lock QueueSession

Low Priority Wait

Grant

51-SELECT

52-DDL

53-SELECT

54-SELECT

55-SELECT

Page 13: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Permissions and Security

Current

ALTER TABLE

Requires ALTER permission on the table

Applies to both source and target tables

Switched data inherits the security of the target table

ALTER INDEX

ALTER permission on the table or view is required

MLP SWITCH/OIR

ABORT_AFTER_WAIT=BLOCKERS all blocking user transactions killed

ALTER ANY CONNECTION server wide permission

Page 14: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Limitations

Only user blocking sessions can be killed

• System sessions cause blocking

SQL transaction log truncation delayed by MLP

• MAX_DURATION=n time affects log truncation

• Best Practice: Additional disk space

• Best Practice: Properly define the MAX_DURATION time

SWITCH operation only supported between two tables or indexed views

MLP applies only to primary server

• AlwaysOn, Transactional Replication

Page 15: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected
Page 16: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected
Page 17: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

SPOIR - Benefits

• One or more partitionsGranularity

• Table accessible for DML and query operations

• Short term locks beginning and end of the index rebuildAccessibility

• Use Managed Lock Priority with SPOIRLock Priority

• Reduced down time for mission critical workloadsAvailability

• CPU, memory and disk space

• Log space usage reducedResource savings

Page 18: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

SPOIR - Syntax

ALTER INDEX clidx ON part_table REBUILD

PARTITION= 3

WITH ( ONLINE=ON

(WAIT_AT_LOW_PRIORITY

(MAX_DURATION= 300,

ABORT_AFTER_WAIT=NONE)) )

Example

<single_partition_rebuild_index_option> ::=

{

…. | ONLINE = { ON [ ( <low_priority_lock_wait> ) ] | OFF

}

}

<low_priority_lock_wait>::=

{

WAIT_AT_LOW_PRIORITY ( MAX_DURATION =

<time>[MINUTES],

ABORT_AFTER_WAIT = { NONE | SELF | BLOCKERS } )

}

Syntax

Page 19: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected
Page 20: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Best Practices

• Long running queries/transactions

• May not be beneficial in workloads with short

transactions

ABORT_AFTER_WAIT=BLOCKERS

• SWITCH acquires locks on source and target tables

• Wait on the second lock affects concurrency on first

• Dormant tables

Locking

• Nested transaction holds locks longer

DDL Transaction

• Log truncation affected by MAX_DURATION

• Extra logging OIR DDL operation

• Can lead to system performance issue

Transaction Log Growth

Page 21: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Tell us what you think

Scan the QR code to evaluate

this session.

Page 22: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected
Page 23: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected
Page 24: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

Lock Manager changes

Stores Kill, Low Priority Convert and Low Priority Wait requests

Scan GRANT queue and if no conflicting locks GRANT immediately

Place in KILL queue and sleep till all tasks with conflicting locks are aborted

Only one KILL request supported at a time

Scan KILL queue which has higher priority first

Grant, Convert and Wait queues scanned next and request placed accordingly

Wait behind existing KILL, normal priority and other low priority requests

Add to Low Priority Convert or Low Priority Wait as applicable

Page 25: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected

ReferencesRelated references for you to expand your knowledge on the subject• <Quote related references here>

technet.microsoft.com/en-in

aka.ms/mva

msdn.microsoft.com/

Page 26: Learn. Connect. Explore. - Microsoft... · Connect. Explore. SQL Server 2014 : Online Operation Enhancements Vinod Kumar Technical Architect –MTC ... •Log truncation affected