Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

Schedule an Extended Event to run at a Specific Time

$
0
0

When you are using the extended event to capture some data for troubleshooting purpose, you may want to start or stop it at a specific time. Unfortunately, the Extended Event feature doesn’t provide you the option to schedule it. But, it can easily be accomplished by using “ALTER EVENT SESSION” T-SQL code and SQL Server Agent. You can use the below syntax to start and stop the xEvent session;

ALTER EVENT SESSION event_session_name ON SERVER STATE = {START | STOP} Demonstration:

To demonstrate it, I have created an extended event session “SP_Performance” on the server which is going to capture the provided stored procedure execution duration by the statements.


Schedule an Extended Event to run at a Specific Time

I know from the application team that the SP performance goes worst especially in the evening time so I am going to create an SQL Agent Job to start it at 3 PM and another SQL Job to stop it at 6 PM.

The first job has one step, which issues the START command.


Schedule an Extended Event to run at a Specific Time

My second job is to stop the session. There is one step, which issues the STOP command.


Schedule an Extended Event to run at a Specific Time

Here is schedules detail of the jobs;


Schedule an Extended Event to run at a Specific Time

Hope, you enjoyed learning of how you can schedule the timing of xEvent sessions.


Viewing all articles
Browse latest Browse all 3160

Trending Articles