1.
Background
sending email notification whenever insufficient disk space found in any of the
drive of the server/computer. This notification is useful while supporting and
maintenance of servers. Here we are using xp_fixeddrives system stored procedure for getting the disk
space information from the server/computer and Database Mail for sending
notification. For configuring the Database mail, you can refer the below link:
2.
Pre-requisite
Database Mail configuration should be configured
for sending email notification.
SQL Server Agent service should run.
3.
What is xp_fixeddrives?
an extended stored procedure that provides free space availability details of
all the disk drives available in server/computer. This stored procedure returns
amount of free space available in MB.
4. Step by Step procedure to send Insufficient Disk Space Notification:
i. We have created a stored procedure named “GetServerSpaceStatus” that will return
the disk drive name and its available free space in MB if any of the disk space
is equal or less than 100 MB.
set the criteria for insufficient disk space is equal or less than 100 MB.
Below is the stored procedure that uses xp_fixeddrives extended stored
procedure with filter condition of 100 MB or less free space of disk drive.
HISTORY
having insufficient disk space.
for insufficient disk space- 100 MB
NVARCHAR(4000)
INT
NVARCHAR(100)
INT
table variable for storing Disk space information
disk space availability details into table variable
variable.
than 100 MB
= MB_Free
SQLCircuit Blogspot Server’
encountered
Server, Please take necessary action to avoid any further issues’ +
@recipients=‘sqlcircuit@gmail.com’,
@subject
= @SUBJECTMESSAGE,
@Profile_Name=‘sqlcircuit’, –Profile of SMTP Server
@body
= @tableHTML,
@body_format
= ‘HTML’ ;
BEGIN CATCH
–logging Error information
INSERT INTO [dbo].[ErrorLog]
([MessageID],[ErrorNumber],[ErrorSeverity],[ErrorState],
[ErrorProcedure],[ErrorLine],[ErrorMessage],[CreatedBy],
[CreatedDate])
VALUES
(1,ERROR_NUMBER(),ERROR_SEVERITY(),ERROR_STATE(),ISNULL(ERROR_PROCEDURE(),
‘-
‘),ERROR_LINE(),ERROR_MESSAGE(),”,GETDATE())
RETURN @lReturnCode
SET NOCOUNT OFF
ii.
Execute the stored procedure and check the
email whether we have received mail or not.
Execution:
the email to confirm whether we have received email or not: Below screenshot is
showing that we have received Insufficient Disk Space notification:
5.
How to use this approach
in practical scenarios:
should run continuously or with minimum time interval (1 or 2 mins). In this job,
we can call the stored procedure GetServerSpaceStatus
that will return Disk drive name with insufficient disk space.
6.
Conclusion
the above steps, we can implement Insufficient Disk Space Notification.
of Document—————————————————