online transaction processing system, there are two main reasons for the crash. On the one hand, due to the concurrency of multiple users and multi-tasks and the integrity requirements of transactions, when multiple transactions access multiple resources at the same time, if both parties have locked a part of resources but both of them need resources locked by the other party, they will be in an infinite waiting state if they cannot fully obtain the
Label:Restore a full backup first, but be sure to select with Nonerecovery in the full backup (option 2nd in Enterprise Manager) The SQL statement is: Restore Database MyData from disk = ' C:\temp\movedb.bak ' WITH NORECOVERY The database then becomes the recovery mode, so you can restore the trn file by adding it in one piece. Statement is: Restore log Mydata from disk =
"D:\Program Files\Microsoft SQL
Starting with SQL SERVER 2008, we are no longer able to use the previousDUMP TRAN database name with NO_LOGThis way to shrink the database, however, you can use another alternative method, the SQL statement is as follows:ALTER database name set RECOVERY simplealter database name set RECOVERY FULLDBCC shrinkdatabase (database name, 0)This way to doOriginal link: h
deadlock.
Keeping transactions in one batch can minimize the number of network communications to and from the transaction, reduce the possible latency of completing the transaction and release the lock.
Low isolation level
Determine whether the transaction can run at a lower isolation level. The committed read oper
', 50,150,7500,1002) go
Step Two: Create two transactions that will cause deadlocks
Transaction 1:
SET NOCOUNT on;
SET xact_abort on;
Go-use Try-catch to cause code errors and continue to run the
begin TRY
begin TRAN
UPDATE dbo.goods_sort SET ssortname= ' Women's Shoes ' WHERE isortid=1003;
WAITFOR DELAY ' 00:00:05 ';
UPDATE dbo.goods SET sgoodsname= ' fatty down jacket ' WHERE iid=2;
COMMIT TRAN End
TRY
BEGIN CATCH
IF (xact_state () =-1)
Sessions 1 and Session 2 cannot continue until the other party frees resources. Therefore, SQL Server chooses a session in the deadlock as the "deadlock victim."
Note: The deadlock victim's session will be killed and the transaction
SELECT statement in each window attempts to read all the data in the authors table, looking for data similar to the "test%" format in the Au_lname field value. Therefore, the SELECT statements in the two windows will attempt to read the inserted data in their connection-and also read the insertion data from the other connection.
The Read Committed isolation level ensures that the SELECT statement never reads the uncommitted data by publishing the shared lock. For the same resource, the shared
('UKRRM','UKRLE')))
Solution
The preceding symptoms are as follows:
1. The update statement is in a large transaction. if the transaction is too large, other sessions will wait for the exclusive lock for a longer time.
2. Everyone is using the same non-clustered index and scanning the PricingExpressProductCode Field
3. There are many duplicate values in the Index
From the above symptoms, we can basically t
'BEGIN TranUpdate [dbo]. [[Zping.com1]]Set a= ' AA 'where b= ' B2 'WAITFOR DELAY ' 00:00:05 'Update [dbo]. [[Zping.com2]]Set d= ' D5 'Where e= ' E1 'Create a new two window, execute the above statement within 5 seconds, and soon a deadlock prompt will appear. (Remember to roll back the transaction after the end)1.2 Deadlock caused by shared lockBEGIN TranUpdate
large transaction, the transaction is too large to allow other sessions to wait for exclusive lock time to become longer
2, everyone is using the same nonclustered index, and scan the Pricingexpressproductcode field
3, the index of repeated values are many
From the above symptoms can be basically judged, this nonclustered index is useless, you can disable the
ALTER INDEX [ix_pricingexpressproduc
sys.dm_tran_locks-- view transaction activity status DBCC OPENTRAN
Refer to: https://docs.microsoft.com/zh-cn/sql/relational-databases/system-dynamic-management-views/ sys-dm-tran-locks-transact-sql?view=sql-server-2017What is a
Label:The following occurs when performing a distributed transaction under WINDOWS2003. First, the problem phenomenonWhen you execute a distributed transaction, you receive the following error under SQL Server 2005: The OLE DB provider "SQLNCLI" of the linked server "xxxxxxx
Label:A transaction executes a sequence of operations as a unit, either succeeds or fails, and rolls back to its original state. In transactional terminology, a transaction is either committed or aborted. To commit a transaction, all participants must ensure that any changes to the data are permanent. Regardless of the system crash or other unforeseen events, the
What is a deadlock?
====================
A deadlock occurs when two system server process IDs (SPIDs) are waiting for a resource and neither process can advance because the other process is preventing it from getting the resource. for example, Andrew holds a lock on table A and requests a lock on table B; Lindsay holds a lock on table B and requests a lock on tab
Tags: blog http io ar os using SP data divA transaction executes a sequence of operations as a unit, either succeeds or fails, and rolls back to its original state. In transactional terminology, a transaction is either committed or aborted. To commit a transaction, all participants must ensure that any changes to the data are permanent. Regardless of the system c
writable (blocked) not apply (blocked) not apply (block)--1. Using an exclusive lock thread can read its locked record, read the latest version of the current transaction, and for a thread that does not apply an exclusive lock, it is also possible to read operations, which is a consistent, non-locking read.-that is, for the same record, the database records multiple versions, and the update operation within the t
SQL transaction (Transaction) usage introduction and rollback instanceThe transaction (Transaction) is a unit of concurrency control and is a user-defined sequence of operations. These operations are either done or not, and are an inseparable unit of work. With transactions
An SQL example that causes a deadlock is provided.Deadlock definition: in a broad sense, it includes the operating system application database. If two Process sessions hold each other's resources, they always wait for the other to release. This situation may cause a deadlock.Misunderstanding: Session blocking is not a deadlock, because one of the sessions can con
). Use SQL Server Profiler to parse deadlocks: Add the Deadlock Graph event class to the trace. This event class uses the TextData data columns in the trace to populate the XML data for the processes and objects involved in the deadlock. SQL
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.