SQL Server - Bài 10

27 365 0
SQL Server - Bài  10

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

SQL Server - Bài

Managing Transaction and LockVu Tuyet Trinhtrinhvt-fit@mail.hut.edu.vnHanoi University of Technology1 MicrosoftMicrosoftTransactionA sequence of tasks that together constitute a logical unit of workEnsuring the highest level of integrity and consistency within a databaseUsed when statements are processed MicrosoftMicrosoftACID PropertiesAtomicityAll or noneConsistencyLeave data in a consistent stateIsolationDon’t show data that’s ½ doneDurabilityModifications are permanent MicrosoftMicrosoftOverview√TransactionReview of Transaction LogIntroduction to Transactions and LocksManaging TransactionsSQL Server Locking & Managing Locks MicrosoftMicrosoftTransaction Log ArchitectureWrite-Ahead transaction logFlushing the page and dirty PagesUse of checkpointsMinimize what must be processed to recoverTruncating the transaction logShrinking the transaction logDBCC SHRINKDATABASEDBCC SHRINKFILE MicrosoftMicrosoftTransaction Recovery and Checkpoints Transaction Recovery Action RequiredNoneCheckpoint System Failure1122334455Roll forwardRoll backRoll forwardRoll back MicrosoftMicrosoftConcurrency ControlPessimistic concurrency controlHigh contention for dataOptimistic concurrency controlLow contention for data MicrosoftMicrosoftLockable Resources ItemItem DescriptionDescriptionRID Row identifierKey Row lock within an indexPageExtentTableData page or index pageGroup of pagesEntire tableDatabase Entire database MicrosoftMicrosoftTypes of LocksBasic locksShared (LS)Exclusive (LX)Special situation locksIntentUpdateSchemaBulk update MicrosoftMicrosoftLock CompatibilityLocks may or may not be compatible with other LocksExamplesShared locks are compatible with all locks except exclusiveExclusive locks are not compatible with any other locksUpdate locks are compatible only with shared locksfalsefalseLXfalsetrueLSLXLS [...]... blocking each other Deadlock  How SQL server ends a deadlock  How to minimize deadlocks      Access objects in same order Keep transactions short Use low isolation level Use bound connections How to customize the lock time-out setting  Microsoft SET LOCK_TIMEOUT function Remarks  Keep transactions short  Design transactions to minimize deadlocks  Use SQL Server defaults for locking  Be careful...Managing Locks Session-level locking options – READ UNCOMMITTED – READ COMMITTED (default) – REPEATABLE READ – SNAPSHOT – SERIALIZABLE Locking timeout – Limits time waiting for a locked resource – SET LOCK_TIMEOUT Microsoft Viewing Locking Information • Activity Monitor • sys.dm_tran_locks Dynamic Management View • EnumLocks • SQL Server Profiler • System Monitor Microsoft Considerations... ON ALTER DATABASE CREATE DELETE DROP FETCH GRANT ∙ ∙ ∙ ∙ ∙ ∙ INSERT OPEN REVOKE SELECT TRUNCATE TABLE UPDATE  Transaction must be explicitly completed with COMMIT or ROLLBACK TRANSACTION Microsoft SQL Server Locking   Microsoft Concurrency Problems Prevented by Locks Dealing with Deadlocks Concurrency Problems Prevented by Locks  Lost update   Uncommitted dependency (Dirty Read)   Selecting... EnumLocks • SQL Server Profiler • System Monitor Microsoft Considerations for Using Transactions  Transaction guidelines     Keep transactions as short as possible Use caution with certain Transact -SQL statements Avoid transactions that require user interaction Issues in nesting transactions  Allowed, but not recommended  Use @@trancount to determine nesting level Microsoft Transaction Types  . and LocksManaging Transactions SQL Server Locking & Managing Locks MicrosoftMicrosoftTransaction Log ArchitectureWrite-Ahead transaction logFlushing. Activity Monitor • sys.dm_tran_locks Dynamic Management View • EnumLocks• SQL Server Profiler • System Monitor MicrosoftMicrosoftConsiderations for Using

Ngày đăng: 15/11/2012, 10:59

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan