ALTER EVENT SESSION (Transact-SQL)
Starts or stops an event session or changes an event session configuration.
ALTER EVENT SESSION event_session_name
ON SERVER
{
[ [ { <add_drop_event> [ ,...n] }
| { <add_drop_event_target> [ ,...n ] } ]
[ WITH ( <event_session_options> [ ,...n ] ) ]
]
| [ STATE = { START | STOP } ]
}
<add_drop_event>::=
{
[ ADD EVENT <event_specifier>
[ ( {
[ SET { event_customizable_attribute = <value> [ ,...n ] } ]
[ ACTION ( { [event_module_guid].event_package_name.action_name [ ,...n ] } ) ]
[ WHERE <predicate_expression> ]
} ) ]
]
| DROP EVENT <event_specifier> }
<event_specifier> ::=
{
[event_module_guid].event_package_name.event_name
}
<predicate_expression> ::=
{
[ NOT ] <predicate_factor> | {( <predicate_expression> ) }
[ { AND | OR } [ NOT ] { <predicate_factor> | ( <predicate_expression> ) } ]
[ ,...n ]
}
<predicate_factor>::=
{
<predicate_leaf> | ( <predicate_expression> )
}
<predicate_leaf>::=
{
<predicate_source_declaration> { = | < > | ! = | > | > = | < | < = } <value>
| [event_module_guid].event_package_name.predicate_compare_name ( <predicate_source_declaration>, <value> )
}
<predicate_source_declaration>::=
{
event_field_name | ( [event_module_guid].event_package_name.predicate_source_name )
}
<value>::=
{
number | 'string'
}
<add_drop_event_target>::=
{
ADD TARGET <event_target_specifier>
[ ( SET { target_parameter_name = <value> [ ,...n] } ) ]
| DROP TARGET <event_target_specifier>
}
<event_target_specifier>::=
{
[event_module_guid].event_package_name.target_name
}
<event_session_options>::=
{
[ MAX_MEMORY = size [ KB | MB ] ]
[ [,] EVENT_RETENTION_MODE = { ALLOW_SINGLE_EVENT_LOSS | ALLOW_MULTIPLE_EVENT_LOSS | NO_EVENT_LOSS } ]
[ [,] MAX_DISPATCH_LATENCY = { seconds SECONDS | INFINITE } ]
[ [,] MAX_EVENT_SIZE = size [ KB | MB ] ]
[ [,] MEMORY_PARTITION_MODE = { NONE | PER_NODE | PER_CPU } ]
[ [,] TRACK_CAUSALITY = { ON | OFF } ]
[ [,] STARTUP_STATE = { ON | OFF } ]
}
|
Term |
Definition |
||||||||
|
event_session_name |
Is the name of an existing event session. |
||||||||
|
STATE = START | STOP |
Starts or stops the event session. This argument is only valid when ALTER EVENT SESSION is applied to an event session object. |
||||||||
|
ADD EVENT <event_specifier> |
Associates the event identified by <event_specifier>with the event session. |
||||||||
|
[event_module_guid].event_package_name.event_name |
Is the name of an event in an event package, where:
Events appear in the sys.dm_xe_objects view as object_type 'event'. |
||||||||
|
SET { event_customizable_attribute = <value> [ ,...n] } |
Specifies customizable attributes for the event. Customizable attributes appear in the sys.dm_xe_object_columns view as column_type 'customizable ' and object_name = event_name. |
||||||||
|
ACTION ( { [event_module_guid].event_package_name.action_name [ ,...n] } ) |
Is the action to associate with the event session, where:
Actions appear in the sys.dm_xe_objects view as object_type 'action'. |
||||||||
|
WHERE <predicate_expression> |
Specifies the predicate expression used to determine if an event should be processed. If <predicate_expression> is true, the event is processed further by the actions and targets for the session. If <predicate_expression> is false, the event is dropped by the session before being processed by the actions and targets for the session. Predicate expressions are limited to 3000 characters, which limits string arguments. |
||||||||
|
event_field_name |
Is the name of the event field that identifies the predicate source. |
||||||||
|
[event_module_guid].event_package_name.predicate_source_name |
Is the name of the global predicate source where:
|
||||||||
|
[event_module_guid].event_package_name.predicate_compare_name |
Is the name of the predicate object to associate with the event, where:
|
||||||||
|
DROP EVENT <event_specifier> |
Drops the event identified by <event_specifier>. <event_specifier> must be valid in the event session. |
||||||||
|
ADD TARGET <event_target_specifier> |
Associates the target identified by <event_target_specifier>with the event session. |
||||||||
|
[event_module_guid].event_package_name.target_name |
Is the name of a target in the event session, where:
|
||||||||
|
SET { target_parameter_name = <value> [, ...n] } |
Sets a target parameter. Target parameters appear in the sys.dm_xe_object_columns view as column_type 'customizable' and object_name = target_name.
|
||||||||
|
DROP TARGET <event_target_specifier> |
Drops the target identified by <event_target_specifier>. <event_target_specifier> must be valid in the event session. |
||||||||
|
EVENT_RETENTION_MODE = { ALLOW_SINGLE_EVENT_LOSS | ALLOW_MULTIPLE_EVENT_LOSS | NO_EVENT_LOSS } |
Specifies the event retention mode to use for handling event loss. |
||||||||
|
MAX_DISPATCH_LATENCY = { seconds SECONDS | INFINITE } |
Specifies the amount of time that events are buffered in memory before being dispatched to event session targets. The minimum latency value is 1 second. However, 0 can be used to specify INFINITE latency. By default, this value is set to 30 seconds. |
||||||||
|
MAX_EVENT_SIZE = size [ KB | MB ] |
Specifies the maximum allowable size for events. MAX_EVENT_SIZE should only be set to allow single events larger than MAX_MEMORY; setting it to less than MAX_MEMORY will raise an error. size is a whole number and can be a kilobyte (KB) or a megabyte (MB) value. If size is specified in kilobytes, the minimum allowable size is 64 KB. When MAX_EVENT_SIZE is set, two buffers of size are created in addition to MAX_MEMORY. This means that the total memory used for event buffering is MAX_MEMORY + 2 * MAX_EVENT_SIZE.
|
||||||||
|
MEMORY_PARTITION_MODE = { NONE | PER_NODE | PER_CPU } |
Specifies the location where event buffers are created.
|
||||||||
|
TRACK_CAUSALITY = { ON | OFF } |
Specifies whether or not causality is tracked. If enabled, causality allows related events on different server connections to be correlated together. |
||||||||
|
STARTUP_STATE = { ON | OFF } |
Specifies whether or not to start this event session automatically when SQL Server starts.
|
The following example starts an event session, obtains some live session statistics, and then adds two events to the existing session.
-- Start the event session ALTER EVENT SESSION test_session ON SERVER STATE = start GO -- Obtain live session statistics SELECT * FROM sys.dm_xe_sessions SELECT * FROM sys.dm_xe_session_events GO -- Add new events to the session ALTER EVENT SESSION test_session ON SERVER ADD EVENT sqlserver.database_transaction_begin, ADD EVENT sqlserver.database_transaction_end GO

Important
Note