Before creating a SQL Server alert, make sure that Database Mail and SQL Server Agent properties are properly configured

在创建SQL Server警报之前,请确保正确配置了数据库邮件SQL Server代理属性。

配置数据库邮件 (Configure Database Mail)

  1. Management node in SQL Server Management Studio管理”节点
  2. Right-click Database Mail and select Send Test Database mail
    If you receive the message that there are no Database mail profiles, you have to create an email profile first

    右键单击“ 数据库邮件”,然后选择“ 发送测试数据库邮件”
    如果收到消息说没有数据库邮件配置文件,则必须先创建一个电子邮件配置文件

  3. Yes. Another option is to right-click 。 另一个选项是右键单击“ Database Mail and select 数据库邮件”,然后选择“ Configure Database Mail配置数据库邮件”
  4. Create a database mail account using your mail server parameters and credentials

    使用您的邮件服务器参数和凭据创建数据库邮件帐户

  5. Create a database mail profile and add the mail account created in the previous step

    创建数据库邮件配置文件并添加在上一步中创建的邮件帐户

配置SQL Server代理 (Configure SQL Server Agent)

Another very important step, often skipped when creating an alert, is setting SQL Server Agent properties:

创建警报时通常会跳过的另一个非常重要的步骤是设置SQL Server代理属性:

  1. SQL Server Agent in 对象资源管理器”中的“ Object Explorer and select SQL Server代理” ,然后选择“ Properties属性”
  2. Alert System tab警报系统选项卡
  3. Enable mail profile option启用邮件配置文件选项
  4. Mail system is Database Mail邮件系统是数据库邮件
  5. Mail profile from the drop-down list邮件配置文件
  6. Make sure that Include body of e-mail in notification message is selected

    确保已选中在通知消息包括电子邮件正文

  7. Enable fail-safe operator option and select the operator from the list启用故障安全操作员”选项,然后从列表中选择操作员
  8. OK确定
  9. SQL Server Agent, as changes might not be applied automaticallySQL Server代理 ,因为更改可能不会自动应用

If the mail profile is not enabled for SQL Server Agent, you will be able to create SQL Server alerts and set email notifications successfully. There will be no error messages, nor warnings, yet emails will not be sent. To find out why the email notifications are not sent, you will have to check the SQL Server error logs, they will clearly indicate that the problem is that Database Mail is not enabled for SQL Server Agent notifications

如果未为SQL Server代理启用邮件配置文件,则可以创建SQL Server警报并成功设置电子邮件通知。 没有错误消息,也没有警告,但不会发送电子邮件。 要找出为什么不发送电子邮件通知的原因,您将必须检查SQL Server错误日志,它们将清楚表明问题是未为SQL Server代理通知启用数据库邮件

创建一个SQL Server警报 (Creating a SQL Server alert)

Alerts can be created using SQL Server Management Studio or T-SQL. When creating an alert, you have to specify its name, the event or threshold value that fires the alert, and the action executed when the alert is fired

可以使用SQL Server Management Studio或T-SQL创建警报。 创建警报时,必须指定其名称,触发警报的事件或阈值以及触发警报时执行的操作

  1. Make sure that SQL Server Agent is running. If not, right click SQL Server Agent in SQL Server Management Studio Object Explorer and select Start. Consider setting SQL Server Agent to start up automatically
  2. 确保SQL Server代理正在运行。 如果不是,请在SQL Server Management Studio 对象资源管理器中右键单击“ SQL Server代理” ,然后选择“ 启动” 。 考虑将SQL Server代理设置为自动启动
  3. Alerts node in the SQL Server代理”中的“ SQL Server Agent and select 警报”节点,然后选择“ New Alert新建警报”
  4. SQL Server performance condition as the alert type from the drop-down menu. Other two available options are SQL Server event and WMI eventSQL Server性能条件作为警报类型。 其他两个可用选项是SQL Server事件和WMI事件
  5. Buffer Manager. Other available objects are Access Methods, Availability Replica, Buffer Node, Catalog Metadata, Databases, General Statistics, Latches, Locks, and many more Buffer Manager 。 其他可用对象包括访问方法,可用性副本,缓冲区节点,目录元数据,数据库,常规统计信息,闩锁,锁等

    These object types can be obtained by executing

    这些对象类型可以通过执行

    
    select distinct object_name
    from sys.dm_os_performance_counters
  6. The list of available counters shows all Buffer Memory counters. Again, you can see them when querying the sys. dm_os_performance_counters view, or in Performance Monitor. In this example, we’ll select Page Life Expectancy
  7. 可用计数器列表显示所有缓冲存储器计数器。 再次,您可以在查询系统时看到它们 dm_os_performance_counters视图或在Performance Monitor中 。 在此示例中,我们将选择“预期页面寿命”
  8. The instance name is the database name, Total if the SQL Server alert is applied to all databases, counter specific information, or blank. This is the information returned in the instance_name column by the sys. dm_os_performance_counters view
  9. 实例名称是数据库名称,如果SQL Server警报应用于所有数据库,则为Total,计数器特定信息,或为空白。 这是sysinstance_name列中返回的信息 dm_os_performance_counters视图
  10. The Alert if counter field can have falls below, becomes equal to, or rises above values

    As the normal values for Page Life Expectancy are above 300 seconds (5 minutes), we’ll select falls under and enter 300 in the Value field

    Note that the counters are queried periodically and that there might be a slight delay before the alert is triggered

    Here is an example for setting Memory Grants Pending. Its value represents the total number of SQL Server processes waiting to be granted workspace in the memory. The threshold value is zero. If any processes are waiting for the memory workspace, they are queued and the Memory Grants Pending value is higher. The alert will be fired if the counter rises above 0

  11. 如果计数器字段可以低于,等于高于,则发出 警报

    由于“ 网页预期寿命”的正常值超过300秒(5分钟),因此我们将选择“ 低于” ,然后在“ 值”字段中输入300

    请注意,会定期查询计数器,并且触发警报之前可能会稍有延迟

    这是设置Memory Grants Pending的示例。 它的值表示等待在内存中被授予工作区SQL Server进程总数。 阈值为零。 如果有任何进程在等待内存工作空间,则它们会排队,并且“ 内存授权未决”值会更高。 如果计数器上升到0以上,则会触发警报

  12. Response tab, specify what event type you want to trigger by the alarm. Available options are to execute a SQL Server job, and to send a notification to an operator. You can select both for a single SQL Server alert. To be able to create a response, you must be a member of the sysadmin role响应”选项卡中,指定要由警报触发的事件类型。 可用选项包括执行SQL Server作业以及向操作员发送通知。 您可以为单个SQL Server警报选择两者。 为了能够创建响应,您必须是sysadmin角色的成员
  13. Execute job option, and an existing job from the drop-down list. If the job doesn’t exist, click the 执行作业选项,然后从下拉列表中选择一个现有的作业。 如果作业不存在,请单击“ New Job button and create a new job新建作业”按钮并创建一个新作业
  14. To send a notification, select Notify operators

    要发送通知,请选择“ 通知操作员”

  15. If the operator list is empty, select New Operator and fill in the records

    如果操作员列表为空,请选择“ 新操作员”并填写记录

  16. In the Notifications tab, select E-mail for the alert type

    在“ 通知”选项卡中,选择“电子邮件”作为警报类型

    Another way to add a notification is using the sp_add_notification stored procedure

    添加通知的另一种方法是使用sp_add_notification存储过程

    USE [msdb]
    GOEXEC dbo.sp_add_notification@alert_name = N'PLE_Alert',@operator_name = N'Millie',@notification_method = 1
    GO

    The @notification_method parameter can be 1,2, or 4 for emails, pager, and net send, respectively. Only members of the sysadmin SQL Server role can execute the sp_add_notification stored procedure

    对于电子邮件,寻呼机和网络发送,@ notification_method参数可以分别为1,2或4。 只有sysadmin SQL Server角色成员才能执行sp_add_notification存储过程

  17. OK and the new Operator will appear in the Operator list of the 确定 ,新的操作员将出现在“ Alert Properties dialog警报属​​性”对话框的“操作员”列表中
  18. Options tab in the 警报属​​性”对话框中打开“ Alert Properties dialog选项”选项
  19. Select to include the error message into emails sent and add additional text that will provide more details about the situation that triggered the alert

    选择以将错误消息包含在已发送的电子邮件中,并添加其他文本,以提供有关触发警报情况的更多详细信息

  20. Set the delay between responses. The default is 0 minutes and 0 seconds. Keep in mind that sending frequent email notifications until the issue is fixed and the condition doesn’t trigger the alarm might lead to sending too many emails, block your email client and affect the complete system performance设置响应之间的延迟。 默认值为0分钟0秒。 请记住,在问题解决之前,要频繁发送电子邮件通知,并且情况不会触发警报,否则可能会导致发送过多电子邮件,阻塞电子邮件客户端并影响整个系统性能
  21. Open the History tab, to see how many times the SQL Server alert has occurred, the last occurrence, and the last response to the alert. To reset the number of captured alerts and other parameters shown in this tab, check the Reset count check box

    打开“ 历史记录”选项卡,以查看SQL Server警报发生了多少次,最后一次发生以及对警报的最后响应。 要重置此选项卡中显示的已捕获警报的数量和其他参数,请选中“ 重置计数”复选框

The same alert can be created using T-SQL and the dbo.sp_add_alert stored procedure. Note that it has to be executed against the msdb database by a member of a sysadmin role

可以使用T-SQL和dbo.sp_add_alert存储过程来创建相同的警报。 请注意,它必须由sysadmin角色的成员针对msdb数据库执行

 USE [msdb]
GOEXEC msdb.dbo.sp_add_alert @name=N'PLE_Alert', @message_id=0, @severity=0, @enabled=1, @delay_between_responses=300, @include_event_description_in=1, @notification_message=N'Page Life Expectancy has fallen under 300 seconds', @category_name=N'[Uncategorized]', @performance_condition=N'Buffer Manager|Page life expectancy||<|300', @job_id=N'00000000-0000-0000-0000-000000000000'
GO

When an alert is fired on the FUJITSU\SQL2012 instance, you’ll get an email with the SQL Server Alert System: ‘PLE_Alert’ occurred on \\FUJITSU\SQL2012 subject and the following text in the email body:

在FUJITSU \ SQL2012实例上触发警报时,您将收到一封包含SQL Server警报系统的电子邮件:\\ FUJITSU \ SQL2012主题上出现了“ PLE_Alert”,并且电子邮件正文中包含以下文本:

DATE/TIME: 2/19/2014 1:08:41 PM

日期/时间:2014/2/19下午1:18:41

DESCRIPTION: The SQL Server performance counter ‘s’ (instance ‘s’) of object ‘s’ is now below the threshold of s (the current value is s).

描述:对象“ s”SQL Server性能计数器“ s”(实例“ s”)现在低于s的阈值(当前值为s)。

COMMENT: Page Life Expectancy has fallen under 300 seconds

评论:预期页面寿命低于300秒

JOB RUN: (None)

求职:(无)

Disabling an alert
To stop the alert from being fired, but still keep it as inactive, disable it. You can easily enable it and reuse later

禁用警报
要停止触发警报,但仍将其保持为非活动状态,请将其禁用。 您可以轻松启用它,以后再使用

  1. Expand the SQL Server Agent node in SQL Server Management Studio Object Explorer
  2. 在SQL Server Management Studio 对象资源管理器中展开“ SQL Server代理”节点
  3. Select the alert you want to disable and right-click it选择要禁用的警报,然后右键单击它
  4. Disable禁用

The same can be done using T-SQL. Only members of the sysadmin SQL server role can execute the sp_update_alert stored procedure

使用T-SQL可以完成相同的操作。 只有sysadmin SQL Server角色成员才能执行sp_update_alert存储过程


USE msdb
GOEXEC dbo.sp_update_alert@name = N'Test Alert',@enabled = 0
GO

When set to 0, the @enabled parameter disables the alarm. To enable the alarm, use same code except for @enabled = 1

设置为0时,@enabled参数禁用警报。 要启用警报,请使用相同的代码,但@enabled = 1除外

Note that all T-SQL commands given in this article, unless qualified as msdn. dbo.<procedure_name> have to be executed against the msdb database. Otherwise, you’ll get the error message that the procedure cannot be found

请注意,除非具有msdn的资格,否则本文中提供的所有T-SQL命令。 dbo。<procedure_name>必须针对msdb数据库执行。 否则,您将收到错误消息,指出找不到该过程

As shown, the Alert feature in SQL Server Agent is very useful for automating performance issue notifications. It enables creating SQL Server alerts for every available SQL Server performance counter. For each counter, you can set a custom threshold value and specify whether the expected values should be higher or lower. However, it is not possible to set two values for a counter in the same alert. For example, if the counter value is lower than the value A – fire an alarm with a notification about a medium severity issue, and if the counter value falls below the value B – fire a critical alarm

如图所示, SQL Server代理中警报功能对于自动执行性能问题通知非常有用。 它允许为每个可用SQL Server性能计数器创建SQL Server警报。 对于每个计数器,您可以设置一个自定义阈值并指定期望值应该更高还是更低。 但是,不可能在同一警报中为计数器设置两个值。 例如,如果计数器值小于值A –发出带有中等严重性问题通知的警报,并且如果计数器值小于值B则触发严重警报

Email notifications can be seamlessly sent to a number of operators, or to a mailing list. Also, sending pager and net send notifications are available, but will be depreciated in the future SQL Server versions

电子邮件通知可以无缝地发送给许多操作员或邮件列表。 此外,还可以使用发送寻呼机和网络发送通知,但在将来SQL Server版本中将不推荐使用

Setting multiple alarms is not very user friendly, as you have to create a single alarm for each counter you want to monitor, therefore go through a number of steps. The feature is supported only in Enterprise and Business Intelligence SQL Server editions

设置多个警报不是非常用户友好,因为您必须为要监视的每个计数器创建一个警报,因此需要执行许多步骤。 仅企业版和商业智能SQL Server版本支持该功能

翻译自: https://www.sqlshack.com/sql-server-alerts-troubleshooting-performance-issues-create-use-sql-server-alerts/

SQL Server警报解决性能问题:如何创建和使用SQL Server警报相关推荐

  1. 一招教你玩转SQL:通过找出数据的共同属性实现SQL需求

    关注我们,下载更多资源 预告:12月22日,ACOUG 联合创始人及多位核心专家将欢聚一堂,为"关键词解析2018技术圈的那些事儿"为主题的分享讨论,欢迎大家踊跃报名参会. 点击& ...

  2. 解决性能问题中SQL Server警报:SQL Server警报基础

    为什么SQL Server警报很重要? (Why is SQL Server alerting important?) 要了解系统的状况以及SQL Server的性能,必须进行监视. 但是,仅监视可能 ...

  3. 如何创建和配置SQL Server代理警报

    介绍 (Introduction) If you have ever wanted to run a job dependent on a certain performance condition, ...

  4. 在网上看到和篇关于sql server 2005的性能优化篇,觉得写得很好。

    在网上看到和篇关于sql server 2005的性能优化篇,觉得写得很好. SQL Server2005扩展函数已经不是一件什么新鲜的事了,但是我看网上的大部分都是说聚合函数,例子也比较浅,那么这里 ...

  5. sql server datetime取年月_快速定位数据库性能问题,RDS推出慢SQL统计分析

    在使用云的过程中,哪些指标最重要,是安全.弹性,还是计算能力? 其实这些都很关键.除此之外,云最重要的就是数据库了.数据库的性能直接关系到系统执行的效率和稳定性,更与业务紧密相关.如果数据库出现性能问 ...

  6. sql server 性能_如何在SQL Server中收集性能和系统信息

    sql server 性能 介绍 (Introduction) In this article, we're going through many of the tools we can use fo ...

  7. 转载SQL Server 数据库的性能优化

    你是否在千方百计优化SQL Server 数据库的性能?如果你的数据库中含有大量的表格,把这些表格分区放入独立的文件组可能会让你受益匪浅.SQL Server 2005引入的表分区技术,让用户能够把数 ...

  8. 《T-SQL性能调优秘笈——基于SQL Server 2012 窗口函数》——1.1 窗口函数的背景...

    本节书摘来自异步社区出版社<T-SQL性能调优秘笈--基于SQL Server 2012 窗口函数>一书中的第1章,第1.1节,作者: [美]Itzik Ben-Gan,更多章节内容可以访 ...

  9. 《T-SQL性能调优秘笈——基于SQL Server 2012 窗口函数》——1.7 小结

    本节书摘来自异步社区出版社<T-SQL性能调优秘笈--基于SQL Server 2012 窗口函数>一书中的第1章,第1.7节,作者: [美]Itzik Ben-Gan,更多章节内容可以访 ...

最新文章

  1. 分页技巧_实现第一个分页功能(回复列表中的分页)
  2. STL源代码分析(ch 1)组态2
  3. CodeForces - 1330D Dreamoon Likes Sequences(组合数学)
  4. 本地mysql新建用户名和密码错误_mysql新建用户本地无法登录
  5. 重新梳理下js中的深拷贝和浅拷贝
  6. 选课_ctsc1997_ssl1606_树形dp
  7. Flutter实战之FlutterPlugin插件入门指南
  8. jQuery性能优化指南(2)
  9. QTP/UFT11.5官方下载与安装教程及汉化
  10. 最简单代码,适合没学编程的人玩
  11. HP服务器连接显示器怎么连,笔记本如何外接显示器 外接显示器连接步骤【详解】...
  12. 【转】最落魄的日子你是怎样熬过来的?
  13. PTA 1075 链表元素分类
  14. 超越美国!中国AI初创企业融资额全球第一 人脸识别最受热捧【附报告全文】
  15. 从入门到断送职业生涯只差这几步
  16. 微软亚洲研究院推出“人立方”人物关系搜索
  17. unity3d-多人坦克对战
  18. minix3通过pkgin_cd安装二进制包
  19. 有效减少虚拟机镜像文件的大小
  20. 在HTML中打开windows计算器

热门文章

  1. linux重定向权限不够,linux – 如何使用sudo将输出重定向到一个我没有权限写入的位置?...
  2. nohup的程序能不能再转到前台查看啊?_职场:为何酒店前台工资低还要上通宵,却还有很多女孩愿意做...
  3. python开发总结
  4. 初学FineReport(二)
  5. 轻松学SQL Server数据库pdf
  6. HDU 4857 逃生 (反向拓扑排序 容器实现)
  7. [Audio processing] Harmonic change detection function (HCDF)
  8. 【Android Developers Training】 20. 创建一个Fragment
  9. 设备的开发【WP7学习札记之五】
  10. HTML5网站大观:10个精美的 HTML5 企业网站欣赏