zoukankan      html  css  js  c++  java
  • 抓索引上的锁等待信息

    CREATE TABLE [dbo].[PageLockWait](
    id int identity primary key,
    [table_name] nvarchar NULL,
    [index_name] [sysname] NULL,
    [page_lock_count] [bigint] NOT NULL,
    [page_lock_wait_count] [bigint] NOT NULL,
    [page_block_pct] [decimal](6, 2) NULL,
    [page_lock_wait_in_ms] [bigint] NOT NULL,
    [page_avg_lock_wait_ms] [decimal](12, 2) NULL,
    captureTime datetime2 default getdate()
    ) ON [PRIMARY]
    GO

    CREATE TABLE [dbo].[RowLockWait](
    id int identity primary key,
    [table_name] nvarchar NULL,
    [index_name] [sysname] NULL,
    [row_lock_count] [bigint] NOT NULL,
    [row_lock_wait_count] [bigint] NOT NULL,
    [row_block_pct] [decimal](6, 2) NULL,
    [row_lock_wait_in_ms] [bigint] NOT NULL,
    [row_avg_lock_wait_ms] [decimal](12, 2) NULL,
    captureTime datetime2 default getdate()
    ) ON [PRIMARY]
    GO

    while(1=1)
    begin

    insert hao.dbo.RowLockWait(table_name,index_name,row_lock_count,row_lock_wait_count,row_block_pct,row_lock_wait_in_ms,row_avg_lock_wait_ms)
    SELECT OBJECT_SCHEMA_NAME(ios.object_id) + '.' + OBJECT_NAME(ios.object_id) as table_name
    ,i.name as index_name
    ,row_lock_count
    ,row_lock_wait_count
    ,CAST(100. * row_lock_wait_count / NULLIF(row_lock_count,0) AS decimal(6,2)) AS row_block_pct
    ,row_lock_wait_in_ms
    ,CAST(1. * row_lock_wait_in_ms / NULLIF(row_lock_wait_count,0) AS decimal(12,2)) AS row_avg_lock_wait_ms
    FROM sys.dm_db_index_operational_stats (DB_ID(), NULL, NULL, NULL) ios
    INNER JOIN sys.indexes i ON i.object_id = ios.object_id AND i.index_id = ios.index_id
    WHERE OBJECTPROPERTY(ios.object_id,'IsUserTable') = 1 and ios.row_lock_wait_count>0
    --ORDER BY row_lock_wait_count + page_lock_wait_count DESC, row_lock_count + page_lock_count DESC
    
    insert hao.dbo.PageLockWait(table_name,index_name,page_lock_count,page_lock_wait_count,page_block_pct,page_lock_wait_in_ms,page_avg_lock_wait_ms)
    SELECT OBJECT_SCHEMA_NAME(ios.object_id) + '.' + OBJECT_NAME(ios.object_id) as table_name
    ,i.name as index_name
    ,page_lock_count
    ,page_lock_wait_count
    ,CAST(100. * page_lock_wait_count / NULLIF(page_lock_count,0) AS decimal(6,2)) AS page_block_pct
    ,page_lock_wait_in_ms
    ,CAST(1. * page_lock_wait_in_ms / NULLIF(page_lock_wait_count,0) AS decimal(12,2)) AS page_avg_lock_wait_ms
    FROM sys.dm_db_index_operational_stats (DB_ID(), NULL, NULL, NULL) ios
    INNER JOIN sys.indexes i ON i.object_id = ios.object_id AND i.index_id = ios.index_id
    WHERE OBJECTPROPERTY(ios.object_id,'IsUserTable') = 1 AND ios.page_lock_wait_count>0
    --ORDER BY row_lock_wait_count + page_lock_wait_count DESC, row_lock_count + page_lock_count DESC
    WAITFOR DELAY '00:00:30'
    

    end

  • 相关阅读:
    python的不可变对象与可变对象及其妙用与坑
    WAAPI+Python使用中的相关问题和学习记录
    开发工具使用
    面试要点5
    面试要点4
    HTTP状态码——详解
    ElasticSearch使用curl导数据报400可能原因
    elasticsearch的安装、部署
    js二级联动
    aspose.words for java操作文档doc,设置一级二级三级标题以及段落表格等详情
  • 原文地址:https://www.cnblogs.com/sqlzh/p/14481542.html
Copyright © 2011-2022 走看看