gpt4 book ai didi

sql-server - 关闭/终止交易

转载 作者:行者123 更新时间:2023-12-01 19:48:11 34 4
gpt4 key购买 nike

根据DBCC OPENTRAN,我有这个未完成的事务:

Oldest active transaction:
SPID (server process ID) : 54
UID (user ID) : -1
Name : UPDATE
LSN : (4196:12146:1)
Start time : Jul 20 2011 12:44:23:590PM
SID : 0x01

有办法杀死它/回滚它吗?

最佳答案

您应该首先弄清楚它在做什么,它来自哪里,以及如果适用,它预计运行多长时间:

SELECT 
r.[session_id],
c.[client_net_address],
s.[host_name],
c.[connect_time],
[request_start_time] = s.[last_request_start_time],
[current_time] = CURRENT_TIMESTAMP,
r.[percent_complete],
[estimated_finish_time] = DATEADD
(
MILLISECOND,
r.[estimated_completion_time],
CURRENT_TIMESTAMP
),
current_command = SUBSTRING
(
t.[text],
r.[statement_start_offset]/2,
COALESCE(NULLIF(r.[statement_end_offset], -1)/2, 2147483647)
),
module = COALESCE(QUOTENAME(OBJECT_SCHEMA_NAME(t.[objectid], t.[dbid]))
+ '.' + QUOTENAME(OBJECT_NAME(t.[objectid], t.[dbid])), '<ad hoc>'),
[status] = UPPER(s.[status])
FROM
sys.dm_exec_connections AS c
INNER JOIN
sys.dm_exec_sessions AS s
ON c.session_id = s.session_id
LEFT OUTER JOIN
sys.dm_exec_requests AS r
ON r.[session_id] = s.[session_id]
OUTER APPLY
sys.dm_exec_sql_text(r.[sql_handle]) AS t
WHERE
c.session_id = 54;

如果您有信心可以断开此连接,您可以使用:

KILL 54;

请注意,根据 session 正在执行的操作,它可能会使数据和/或调用它的应用程序处于奇怪的状态。

关于sql-server - 关闭/终止交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6833867/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com