English 中文(简体)
如何在服务器中找到目前长期存在的问询,以及如何当场杀死这些询问?
原标题:How to find current long running queries in SQL Server and how to kill them instantly?
  • 时间:2017-07-24 09:27:11
  •  标签:
  • sql-server

有时我的申请进展缓慢。 主要问题是,一些昂贵的报告正在运行。 我如何看待这些报告以及如何当即杀害这些报告?

最佳回答

I always use sp_WhoIsActive from Adam Machanic for finding long running queries. sp_WhoIsActive is described in detail on dba.stackexchange.com.

虽然你也可以书写自己的文字或使用sp_who2

Update
You are interested in the first 2 columns of the output of sp_WhoIsActive. The first column defines how long the query is running. The second column is the session_id (or SPID) of the query.
You can use KILL 60 to kill session_id 60 for example.
Have a look over here for a detailed explanation of the stored procedure.

问题回答

你可以利用以下指挥系统来获得长期查询。

SELECT r.session_id,
       st.TEXT AS batch_text,
       qp.query_plan AS  XML Plan ,
       r.start_time,
       r.status,
       r.total_elapsed_time
FROM sys.dm_exec_requests AS r
     CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS st
     CROSS APPLY sys.dm_exec_query_plan(r.plan_handle) AS qp
WHERE DB_NAME(r.database_id) =  {db_name} 
ORDER BY cpu_time DESC;

然后,你可以使用

KILL 60 

例如,杀人罪可达60岁。

我向各位提出几点意见,但并非都是适合你们的。

  1. Reporting and CRUD operations must be separated. At least you can use nolock or something or run them at night and can work offline.
  2. Check your queries because if the data amount less then the 2 000 000, the main problem is queries for many time.
  3. Analyse the report types and if suitable for offline work, use offline system for reporting
  4. can use mirroring or other techniques for reporting.
  5. Best practice is always separate the databases for reporting and CRUD operations.




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签