sqlschool.gr logo

articles

Articles of SQLschool.gr Team

SPIDs with negative number (-2,-3,-4)

Antonios Chatzipavlis
Saturday 15 December 2018

Αφορμή για αυτό το άρθρο ήταν μια ερώτηση που έφτασε στο SQLschool.gr από κάποιο μέλος και η οποία ήταν η παρακάτω:

Έχουμε μια εφαρμογή που "χρησιμοποιεί" transaction coordinator.
Για κάποιο λόγο εμφανίζονται sessions με spid -2.
Πως μπορώ να κάνω kill session με spid=-2 μέσω stored procedure?

Η απάντηση μου

USE Master;
GO
SELECT DISTINCT(request_owner_guid) as οwner_guid
FROM sys.dm_tran_locks
WHERE request_session_id =-2;
GO

KILL '<paste here the value of owner_guid>';
GO

Cases with negative SPID

Οι περιπτώσεις που μπορεί να έχω αρνητικό νούμερο στο SPID είναι οι παρακάτω:

SPID = -2

Αυτό μπορεί να τύχει στην περίπτωση που έχω distributed transaction ορφανό και αυτό μπορεί να συμβεί όταν το MSDTC service για οποιοδήποτε λόγο κρασσάρει ή γίνει unplanned restart.

Είναι γνωστό ότι όλα τα distributed transactions σε περιβάλλον windows υλοποιούνται μέσω του MSDTC (Microsoft Distributed Transaction Coordinator) τον οποίο μπορούμε να δούμε και παραμετροποιήσουμε μέσα από τα Component Services > Computers > My Computer > Distributed Transaction Coordinator.

Aν υπάρχουν In Doubt transactions τότε θα έχουμε SPID=-2 στον SQL Server που πράγματι θα κρατάει locks και που μπορούμε μέσα από το περιβάλλον αν πάμε στα ενεργά transactions να το κάνουμε resolve abort και θα καθαριστεί και από τον SQL Server ή εναλλακτικά να κάνουμε αυτό που αναφέρω παραπάνω.

SPID = -3

Αυτό αφορά deferred transactions που μπορεί να έχω στις περιπτώσεις που δεν μπορεί αυτό να γίνει recover full.

Δεν θα το αναλύσω περισσότερο καθώς περιγράφεται εξαιρετικά στα SQL Server docs και έχει την επίλυση του

SPID = -4

Αυτό αφορά τις περιπτώσεις που έχω ένα blocked transaction που περιμένει latch αλλά δεν μπορεί να βρει τον owner του latch αυτού. Εδώ συγκεκριμένη λύση δεν υπάρχει.


//antonch

Antonios Chatzipavlis

Antonios Chatzipavlis

Antonios Chatzipavlis is a highly experienced Data Solutions Consultant and Trainer. He has been working in the IT industry since 1988, holding various roles such as senior developer, IT Manager, Data & AI Solutions Architect and Consultant.

Since 1995, Antonios has focused on modern technologies and software development tools, primarily by Microsoft. He has specialized in Data & AI since 2000, with expertise in Microsoft Data Platform (SQL Server, Azure SQL Databases, Azure Synapse Analytics, Microsoft Fabric, Power BI, AI) and Databricks.

Antonios is also a Microsoft Certified Trainer (MCT) for over 25 years, has been recognized as a Microsoft Most Valuable Professional (MVP) in Data Platform since 2010 and he is in the Data Expert 40 Powerlist 2024 by Boussias. He is the co-founder and visionary behind XLYTiCA, a company dedicated to Data & AI solutions.

Episode

Task Flows in Microsoft Fabric

image

More Episodes...

Tip

What's New in SQL Server 2022 - Episodes

More Tips...

Become a member

If you want to receive updates from us become a member to our community.

Connect

Explore

Learn


sqlschool.gr © 2010-2025 All rights reserved

This site uses cookies for operational and analytics purposes only. By continuing to browse this site, you agree to their use.