Upload
sqlservercoil
View
1.463
Download
1
Tags:
Embed Size (px)
Citation preview
DDL Triggers & WMI Alerts
Kobi Cohen System DBA Manager
Spiral Solutions
Objectives
Implementing DDL Triggers.Implementing WMI Alerts.
ScopeAll server.
Database.
Fire in response to Data Definition Language (DDL).Create, Alter, Drop.
DDL event group (BOL).
For monitoring or preventing changes in the database.
Run only after T-SQL statement is completed.Cannot be used as INSTEAD OF triggers.
Do not create the inserted and deleted tables.Subsequent changes captured by EVENTDATA functionC:\Program Files\Microsoft SQL Server\100\Tools\Binn\schemas\sqlserver\2006\11\events\ orhttp://schemas.microsoft.com/sqlserver/
Generate XML data captured by XQuery.
DDL Triggers
Demo
Response to SQL Server eventsError message / error severity
Performance monitor counters
WMI events
Alert typesSQL Server event alert
SQL Server performance alert
WMI event alert
PermissionSysadmin server role
SQLAgentOperatorRole database role in msdb
Create alert – sp_add_alert in msdb
Drop Alert – sp_delete_alert in msdb
Get server alerts info – sp_help_alert in msdb
Alerts
WMI – Windows Management InstrumentationTurning SQL Server into a managed WMI object
Classes of properties and methods related to the system environment that you can access like a database
Raise alerts after WMI events occurrenceServer Events Classes (BOL)
Create WMI AlertWMI namespace to query for events
Default Instance – \\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER
Named Instance – \\.\root\Microsoft\SqlServer\ServerEvents\<Instance Name>
WMI Query Language (WQL) – Subset of structured query language (SQL) with WMI-specific extensions
Used to control the WMI Service
WMI Provider for Server Events translates the query into an event notification – service broker must be enabled on msdb.
WMI Alerts
SQL Agent registry parameters KEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\MSSQL.x\SQLServerAgent
EventWMILimit – how many events to consume every time it checks the WMI event queue (default to 5).
EventWMIPeekInterval – how often to look for WMI events (default to 30).
Adding DWORD registry entry alertAllowWMIRemoteEvents set to 1 and restart SQL Agent service (not supported).
WMI TokensFrom SQL Server 2005 changed from [X] to $(X) to avoid conflicts with database objects.
Allows users to send the info from a WMI event.
Strings in job step commands are parsed and replaced at run time.
Using SQL Server Agent Escape Macros (BOL).
WMI Alerts
Demo
Thanks