Rx_
Nothing In Moderation
- Local time
- Yesterday, 19:28
- Joined
- Oct 22, 2009
- Messages
- 2,803
Sometimes, the person on alert to look at your SQL Server hard disk space needs a vacation. That is when my database grew with some new EDI along with the automated test db.
What happens when a SQL Server runs out of hard disk space?
Lets not go there, ever.
This is some code to prevent that from happening and to provide some nice trending informaiton. Granted, it is only about as exciting as rotating your car tires. But, maybe as useful as that too.
The first post will cover some basics of what to do in SQL Server back end. Afterwards, I plan to add a function on my splash screen that will notify each user at the form startup about low disk space.
On the SQL Server (back end) - first create a tracking table. Only the first four fields are actually used. The rest if for some Triggers that will populate additional SQL Server system information:
ID_Sys_Info - just an autocounter field. Later, the function will simply find the largest number. In my case, it is a virtual server with only a C:\ drive.
Date_Time has a default value
Created a new Job - Daily - Database Master, run as sa with command:
Once a day, the total space on C:\ for the SQL Server is logged.
I submitted part 2 as a Reply. It has not shown up yet. Let me know if it needs to be a new post.
What happens when a SQL Server runs out of hard disk space?
Lets not go there, ever.
This is some code to prevent that from happening and to provide some nice trending informaiton. Granted, it is only about as exciting as rotating your car tires. But, maybe as useful as that too.
The first post will cover some basics of what to do in SQL Server back end. Afterwards, I plan to add a function on my splash screen that will notify each user at the form startup about low disk space.
On the SQL Server (back end) - first create a tracking table. Only the first four fields are actually used. The rest if for some Triggers that will populate additional SQL Server system information:
Code:
[FONT=Calibri]-- your DB name for MyProductionDB[/FONT]
[FONT=Calibri]USE [MyProductionDB][/FONT]
[FONT=Calibri]GO[/FONT]
[FONT=Calibri]/****** Object: Table [dbo].[Sys_Info] Script Date: 08/06/2012 15:42:29 ******/[/FONT]
[FONT=Calibri]SET ANSI_NULLS ON[/FONT]
[FONT=Calibri]GO[/FONT]
[FONT=Calibri]SET QUOTED_IDENTIFIER ON[/FONT]
[FONT=Calibri]GO[/FONT]
[FONT=Calibri]CREATE TABLE [dbo].[Sys_Info]([/FONT]
[FONT=Calibri] [ID_Sys_Info] [int] IDENTITY(1,1) NOT NULL,[/FONT]
[FONT=Calibri] [FreeDisk] [int] NULL,[/FONT]
[FONT=Calibri] [Drive] [nvarchar](2) NULL,[/FONT]
[FONT=Calibri] [Date_Time] [datetime2](0) NULL,[/FONT]
[FONT=Calibri] [Desc_2] [nvarchar](75) NULL,[/FONT]
[FONT=Calibri] [Desc_3] [nvarchar](75) NULL,[/FONT]
[FONT=Calibri] [FlagTF] [bit] NULL,[/FONT]
[FONT=Calibri] [Notes] [nvarchar](255) NULL,[/FONT]
[FONT=Calibri] [SSMA_TimeStamp] [timestamp] NOT NULL[/FONT]
[FONT=Calibri]) ON [PRIMARY][/FONT]
[FONT=Calibri]GO[/FONT]
[FONT=Calibri]ALTER TABLE [dbo].[Sys_Info] ADD CONSTRAINT [DF_Sys_Info_Date_Time] DEFAULT (getdate()) FOR [Date_Time][/FONT]
Date_Time has a default value
Created a new Job - Daily - Database Master, run as sa with command:
Code:
INSERT INTO [MyProductionDB].[dbo].[Sys_Info]
([Drive]
,[FreeDisk]
)
EXEC master.sys.xp_fixeddrives
GO
-- Thank Rx_ only to remind him to add part 2
Once a day, the total space on C:\ for the SQL Server is logged.
I submitted part 2 as a Reply. It has not shown up yet. Let me know if it needs to be a new post.
Last edited: