SQL Server 監視資料檔案大小變化
SQL Server 監視資料檔案大小變化
資料庫檔案大小日誌表:
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)
--> 1USE [MyManagement] 2GO 3SET ANSI_NULLS ON 4GO 5SET QUOTED_IDENTIFIER ON 6GO 7SET ANSI_PADDING ON 8GO 9CREATE TABLE [dbo].[DatabaseFileLog](10 [id] [int] IDENTITY(1,1) NOT NULL,11 [LogTime] [datetime] NOT NULL CONSTRAINT [DF_DatabaseFileLog_LogTime] DEFAULT (getdate()),12 [DatabaseName] [varchar](50) NOT NULL,13 [FileLogicalName] [varchar](50) NOT NULL,14 [FilePath] [varchar](4000) NOT NULL,15 [SizeMB] [decimal](18, 4) NOT NULL,16 [FileGroupID] [int] NOT NULL,17 CONSTRAINT [PK_DatabaseFileLog] PRIMARY KEY CLUSTERED 18(19 [id] ASC20)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]21) ON [PRIMARY]2223GO24SET ANSI_PADDING OFF
Code highlighting produced by Actipro CodeHighlighter (freeware)
--> 1USE [MyManagement] 2GO 3SET ANSI_NULLS ON 4GO 5SET QUOTED_IDENTIFIER ON 6GO 7SET ANSI_PADDING ON 8GO 9CREATE TABLE [dbo].[DatabaseFileLog](10 [id] [int] IDENTITY(1,1) NOT NULL,11 [LogTime] [datetime] NOT NULL CONSTRAINT [DF_DatabaseFileLog_LogTime] DEFAULT (getdate()),12 [DatabaseName] [varchar](50) NOT NULL,13 [FileLogicalName] [varchar](50) NOT NULL,14 [FilePath] [varchar](4000) NOT NULL,15 [SizeMB] [decimal](18, 4) NOT NULL,16 [FileGroupID] [int] NOT NULL,17 CONSTRAINT [PK_DatabaseFileLog] PRIMARY KEY CLUSTERED 18(19 [id] ASC20)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]21) ON [PRIMARY]2223GO24SET ANSI_PADDING OFF
建立一個儲存過程,以便定時呼叫:
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)
--> 1declare @dbName varchar(50) 2declare @command varchar(1024) 3declare dbName_cursor CURSOR FOR 4 select [name] 5 from master.dbo.sysdatabases 6 where [name] not in ('master','tempdb','msdb','model') 7open dbName_cursor 8FETCH NEXT FROM dbName_cursor INTO @dbName 9WHILE @@FETCH_STATUS = 0 10begin11 set @command = '12 insert into MyManagement.dbo.DatabaseFileLog13 select 14 getdate(),15 '''+16 @dbName17 +''',18 name,19 filename, 20 convert(float,size) * (8192.0/1024.0)/1024.0 as ''MB'',21 groupid22 from '+@dbName +'.dbo.sysfiles ';23 exec ( @command );24 FETCH NEXT FROM dbName_cursor INTO @dbName ;25end26CLOSE dbName_cursor;27DEALLOCATE dbName_cursor;
Code highlighting produced by Actipro CodeHighlighter (freeware)
--> 1declare @dbName varchar(50) 2declare @command varchar(1024) 3declare dbName_cursor CURSOR FOR 4 select [name] 5 from master.dbo.sysdatabases 6 where [name] not in ('master','tempdb','msdb','model') 7open dbName_cursor 8FETCH NEXT FROM dbName_cursor INTO @dbName 9WHILE @@FETCH_STATUS = 0 10begin11 set @command = '12 insert into MyManagement.dbo.DatabaseFileLog13 select 14 getdate(),15 '''+16 @dbName17 +''',18 name,19 filename, 20 convert(float,size) * (8192.0/1024.0)/1024.0 as ''MB'',21 groupid22 from '+@dbName +'.dbo.sysfiles ';23 exec ( @command );24 FETCH NEXT FROM dbName_cursor INTO @dbName ;25end26CLOSE dbName_cursor;27DEALLOCATE dbName_cursor;
下一步計劃是做一個好一點的表現層,以便直觀地檢視。
如果嫌上面麻煩可以這麼用下面的語句:
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)
--> 1select 2 'select 3 getdate(), 4 '''+ 5 [name] 6 +''', 7 name, 8 filename, 9 convert(float,size) * (8192.0/1024.0)/1024.0 as ''MB'',10 convert(float,size) * (8192.0/1024.0)/1024.0/1024.0 as ''GB'',11 groupid12 from '+[name] +'.dbo.sysfiles union all '13from master.dbo.sysdatabases 14where [name] not in ('master','tempdb','msdb','model')15union all 16select 'select null,null,null,null,null,null,null where 1=2'
Code highlighting produced by Actipro CodeHighlighter (freeware)
--> 1select 2 'select 3 getdate(), 4 '''+ 5 [name] 6 +''', 7 name, 8 filename, 9 convert(float,size) * (8192.0/1024.0)/1024.0 as ''MB'',10 convert(float,size) * (8192.0/1024.0)/1024.0/1024.0 as ''GB'',11 groupid12 from '+[name] +'.dbo.sysfiles union all '13from master.dbo.sysdatabases 14where [name] not in ('master','tempdb','msdb','model')15union all 16select 'select null,null,null,null,null,null,null where 1=2'
執行以上的語句,將會再生成一大堆的語句,然後全部複製到新視窗中,再一次過執行。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8337095/viewspace-1032136/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 檢視Sql Server的log檔案大小SQLServer
- 通過Python實現對SQL Server 資料檔案大小的監控告警PythonSQLServer
- 資料庫資料恢復-SQL SERVER資料庫檔案大小變為“0”的資料恢復方案資料庫資料恢復SQLServer
- 檢視資料檔案大小
- SQL Server CDC配合Kafka Connect監聽資料變化SQLServerKafka
- 資料庫監視器(SQL Server Profilter)資料庫SQLServerFilter
- 【SQL Server】--SQL Server資料庫bak檔案還原SQLServer資料庫
- 檢視資料庫資料檔案的總大小資料庫
- vue 動態監聽視窗大小變化事件Vue事件
- SQL Server資料庫監控SQLServer資料庫
- SQL Server 2005 檢視資料庫表的大小 按照表大小排列SQLServer資料庫
- SQL Server統計資料庫中表大小SQLServer資料庫
- du df 檢視檔案和資料夾大小
- SQL Server 2005中使用DDL觸發器監控資料庫變化SQLServer觸發器資料庫
- SQL SERVER 效能監視器SQLServer
- DataGear 變更部署資料庫為SQL Server填坑指南(含轉寫後的SQL server程式碼及SQL server配置檔案)資料庫SQLServer
- SQL SERVER備份資料庫檔案(使用SSMS)SQLServer資料庫SSM
- SQL Server 無日誌檔案附加資料庫SQLServer資料庫
- 極簡 Node.js 入門 - 3.5 監視檔案變化Node.js
- SQL Server資料庫多資料檔案恢復技術SQLServer資料庫
- java 獲取資料夾大小、檔案大小、檔案個數Java
- resize 資料檔案的大小
- oracle資料檔案大小限制Oracle
- SQL Server 2008 效能監視和優化SQLServer優化
- node.js監聽檔案變化Node.js
- 檢視Windows檔案系統資料塊大小的方法Windows
- datafile.sql 檢視資料檔案和臨時檔案SQL
- 查詢資料檔案大小和實際大小,並收縮資料檔案(轉)
- SQL Server 資料儲存與 NTFS 簇的大小SQLServer
- SQL Server資料庫檔案與Windows系統透明檔案壓縮SQLServer資料庫Windows
- SQL Server 資料庫檔案的分離和附加SQLServer資料庫
- SQL Server資料檔案增長檢測(三)RFSQLServer
- SQL Server資料檔案增長檢測(一)FMSQLServer
- 在SQL Server tempdb滿時檢查資料檔案SQLServer
- 查詢資料檔案大小和實際大小,並收縮資料檔案(原創)
- SQL Server 檢視錶佔用空間大小SQLServer
- 用SQL命令檢視Mysql資料庫大小MySql資料庫
- 監視 SQL Server 2000 阻塞SQLServer