{"id":558,"date":"2010-12-06T22:43:00","date_gmt":"2010-12-06T22:43:00","guid":{"rendered":"\/blogs\/jonathan\/post\/An-XEvent-a-Day-(6-of-31)-Targets-Week-asynchronous_file_target.aspx"},"modified":"2017-04-13T15:49:07","modified_gmt":"2017-04-13T19:49:07","slug":"an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/","title":{"rendered":"An XEvent a Day (6 of 31) &#8211; Targets Week &#8211; asynchronous_file_target"},"content":{"rendered":"<p>Yesterday\u2019s post, <a href=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/extended-events-ring_buffer\/\" target=\"_blank\">Targets Week &#8211; ring_buffer<\/a>, looked at the ring_buffer Target in Extended Events and how it outputs the raw Event data in an XML document.&#160; Today I\u2019m going to go over the details of the other Target in Extended Events that captures raw Event data, the asynchronous_file_target.<\/p>\n<h2>What is the asynchronous_file_target?<\/h2>\n<p>The asynchronous_file_target holds the raw format Event data in a proprietary binary file format that persists beyond server restarts and can be provided to another person via ftp or email for remote disconnected analysis of the events.&#160; The asynchronous_file_target has two types of files that are associated with it, the log files which contain the Event data, and the metadata file which contains information about the Events contained in the log files, allowing correct parsing of the log files and the Events and associated Actions contained within them.&#160; Depending on the options configured for the asynchronous_file_target, there may be multiple log files associated with a started Event Session, but there will only be one metadata file created for the duration of that Event Sessions collection.&#160; Subsequent collections by the same Event Session, for example, stopping it and starting it again at a later time, will create a new metadata file associated with that collection by the Event Session.&#160; These files exist as a set and must be maintained together for the log files to be read.<\/p>\n<h2>Configuration Options<\/h2>\n<p>The asynchronous_file_target like the ring_buffer, has configuration options that can be found in the sys.dm_xe_object_columns DMV.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: green\">-- Target Configurable Fields\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span>oc<span style=\"color: gray\">.<\/span>name <span style=\"color: blue\">AS <\/span>column_name<span style=\"color: gray\">,\r\n    <\/span>oc<span style=\"color: gray\">.<\/span>column_id<span style=\"color: gray\">,\r\n    <\/span>oc<span style=\"color: gray\">.<\/span><span style=\"color: magenta\">type_name<\/span><span style=\"color: gray\">,\r\n    <\/span>oc<span style=\"color: gray\">.<\/span>capabilities_desc<span style=\"color: gray\">,\r\n    <\/span>oc<span style=\"color: gray\">.<\/span><span style=\"color: blue\">description\r\nFROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_packages <\/span><span style=\"color: blue\">AS <\/span>p\r\n<span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_objects <\/span><span style=\"color: blue\">AS <\/span>o \r\n    <span style=\"color: blue\">ON <\/span>p<span style=\"color: gray\">.<\/span><span style=\"color: blue\">guid <\/span><span style=\"color: gray\">= <\/span>o<span style=\"color: gray\">.<\/span>package_guid\r\n<span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_object_columns <\/span><span style=\"color: blue\">AS <\/span>oc \r\n    <span style=\"color: blue\">ON <\/span>o<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span>oc<span style=\"color: gray\">.<\/span><span style=\"color: magenta\">OBJECT_NAME \r\n    <\/span><span style=\"color: gray\">AND <\/span>o<span style=\"color: gray\">.<\/span>package_guid <span style=\"color: gray\">= <\/span>oc<span style=\"color: gray\">.<\/span>object_package_guid\r\n<span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>p<span style=\"color: gray\">.<\/span>capabilities <span style=\"color: gray\">IS NULL OR <\/span>p<span style=\"color: gray\">.<\/span>capabilities <span style=\"color: gray\">&amp; <\/span>1 <span style=\"color: gray\">= <\/span>0<span style=\"color: gray\">)\r\n  AND (<\/span>o<span style=\"color: gray\">.<\/span>capabilities <span style=\"color: gray\">IS NULL OR <\/span>o<span style=\"color: gray\">.<\/span>capabilities <span style=\"color: gray\">&amp; <\/span>1 <span style=\"color: gray\">= <\/span>0<span style=\"color: gray\">)\r\n  AND <\/span>o<span style=\"color: gray\">.<\/span>object_type <span style=\"color: gray\">= <\/span><span style=\"color: red\">'target'\r\n  <\/span><span style=\"color: gray\">AND <\/span>o<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'asynchronous_file_target'\r\n<\/span><\/pre>\n<\/blockquote>\n<p>&#160;<\/p>\n<p>In SQL Server 2008, 2008R2, and SQL Server Denali CTP1, there are five configuration options for the asynchronous_file_target.&#160; The filename specifies the path and name of the log files and is a required to add the asynchronous_file_target to an Event Session.&#160; The max_file_size option functions the same as SQL Trace maxfilesize option, limiting the size of each file before rollover occurs.&#160; The max_rollover_files option functions the same as the SQL Trace maxrolloverfiles option, specifying the number of rollover files to maintain in the file system, and can be used in conjunction with the max_file_size option to prevent the SQL Server from running out of disk space during Event collection.&#160; The increment option is similar to the AutoGrowth settings for a database in SQL Server, and specifies the size in megabytes that the log files grow, allowing the files to grow incrementally and reducing the number of times a log file has to grow while Events are being dispatched and buffered to the Target.&#160; The metadatafile option specifies the path and name of the metadata file for the target.<\/p>\n<\/p>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/111830a7\/image.png\"><img fetchpriority=\"high\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/4bff6370\/image_thumb.png\" width=\"641\" height=\"121\" \/><\/a> <\/p>\n<p>Notice that the only mandatory option for the file target is the filename for the log files.&#160; When the asynchronous_file_target is used in an Event Session, if the metadatafile option is not explicitly set, the asynchronous_file_target will use the same path and filename specified in the filename option with a .xem extension for the metadata file automatically.&#160; <\/p>\n<h2>Understanding the Target Data Format<\/h2>\n<p>Like the ring_buffer, the asynchronous_file_target stores Event data in its raw format.&#160; Inside the log files, the Event data is maintained in a binary format that minimizes the amount of space necessary to store the Events, maximizing the number of Events that can be stored inside the log files.&#160; Unlike the ring_buffer target however, the asynchronous_file_target is queried not through the sys.dm_xe_session_targets DMV, but through the sys.fn_xe_file_target_read_file() DMF.&#160; The sys.fn_xe_file_target_read_file() DMF requires four input parameters; @path which is the path, filename, and extension mask to the log files, @mdpath which is the path, filename, and extension mask to metadata file, @initial_file_name which is the exact path and filename of a file to start reading from and when specified requires the final parameter @initial_offset which is the offset inside that file from which to begin reading the events.<\/p>\n<p>The sys.fn_xe_file_target_read_file() DMF returns a single row for each instance of Event data that is contained inside of the log files being read.&#160; The Event data is materialized into an XML document in the event_data column output by the DMF.when the Target information is queried using the sys.fn_xe_file_target_read_file() DMF, allowing it to be used for Event analysis.&#160; Like the ring_buffer Target, the Event data returned by the sys.fn_xe_file_target_read_file() DMF is not schema bound, but it has exactly the same XML format as an individual &lt;event&gt; node in the ring_buffer Targets output making it very easy to parse the Events contained in either target with very similar XQuery\u2019s.<\/p>\n<h2>Querying\/Parsing the Target Data<\/h2>\n<p>Since the asynchronous_file_target returns the Event data as XML, we have to do the same type of XQuery work to retrieve the Event data from it as we did with the ring_buffer target from yesterday.&#160; After reading yesterday\u2019s post, Adam Machanic (<a href=\"http:\/\/sqlblog.com\/blogs\/adam_machanic\/\" target=\"_blank\">Blog<\/a>|<a href=\"https:\/\/twitter.com\/adammachanic\" target=\"_blank\">Twitter<\/a>) pointed out in a <a href=\"https:\/\/mobile.twitter.com\/AdamMachanic\/statuses\/11497674574405632\" target=\"_blank\">comment on Twitter<\/a> that the slow XML parsing is an optimizer bug that is handled with a derived table in his <a href=\"http:\/\/sqlblog.com\/blogs\/adam_machanic\/archive\/2010\/05\/08\/extended-events-code-generator-v1-001-a-quick-fix.aspx\" target=\"_blank\">Extended Events Code Generator<\/a>.&#160; Adam is absolutely correct, and if you attended my session on Extended Events this year at PASS you\u2019d recall that I didn\u2019t have performance issues in my demo\u2019s for querying the Target data generated by my demo\u2019s.&#160; I used a very different parsing method in my PASS demo\u2019s than I showed yesterday, and I plan to cover that method in a later post in this series already.&#160; However, if you want to see the gist of how to work around the performance issue take a look at the code output by Adam\u2019s code generator.<\/p>\n<p>I am going to reuse yesterday\u2019s demo as a basis for looking at the asynchronous_file_target for simplicity as well as to show the similarity of the XQuery used for querying the Event data.&#160; The basic Event Session captures the error_reported Event and to trigger an error performs a SELECT against a non-existent table.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: green\">-- Create an Event Session to capture Errors Reported\r\n<\/span><span style=\"color: blue\">CREATE EVENT SESSION <\/span>DemoPersistedEvents\r\n<span style=\"color: blue\">ON SERVER\r\nADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>error_reported\r\n<span style=\"color: blue\">ADD TARGET <\/span>package0<span style=\"color: gray\">.<\/span>ring_buffer<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD TARGET <\/span>package0<span style=\"color: gray\">.<\/span>asynchronous_file_target<span style=\"color: gray\">(\r\n     <\/span><span style=\"color: blue\">SET filename<\/span><span style=\"color: gray\">=<\/span><span style=\"color: red\">'D:\\SQLData\\MSSQL10.MSSQLSERVER\\MSSQL\\Log\\DemoPersistedEvents.xel'<\/span><span style=\"color: gray\">)\r\n<\/span><span style=\"color: blue\">WITH <\/span><span style=\"color: gray\">(<\/span>MAX_DISPATCH_LATENCY <span style=\"color: gray\">= <\/span>1 SECONDS<span style=\"color: gray\">)\r\n<\/span><span style=\"color: blue\">GO\r\n<\/span><span style=\"color: green\">-- Alter the Event Session and Start it.\r\n<\/span><span style=\"color: blue\">ALTER EVENT SESSION <\/span>DemoPersistedEvents\r\n<span style=\"color: blue\">ON SERVER\r\nSTATE<\/span><span style=\"color: gray\">=<\/span>START\r\n<span style=\"color: blue\">GO\r\n<\/span><span style=\"color: green\">-- SELECT from a non-existent table to create Event\r\n<\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: gray\">*\r\n<\/span><span style=\"color: blue\">FROM master<\/span><span style=\"color: gray\">.<\/span>schema_doesnt_exist<span style=\"color: gray\">.<\/span>table_doesnt_exist\r\n<span style=\"color: blue\">GO\r\n<\/span><span style=\"color: green\">-- Drop the Event to halt Event collection\r\n<\/span><span style=\"color: blue\">ALTER EVENT SESSION <\/span>DemoPersistedEvents\r\n<span style=\"color: blue\">ON SERVER\r\nDROP EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>error_reported\r\n<span style=\"color: blue\">GO<\/span><\/pre>\n<\/blockquote>\n<p><a href=\"http:\/\/www.11011.net\/software\/vspaste\"><\/a><\/p>\n<p>The first thing we need to know to query our asynchronous_file_target is the filename and metafilename for the files that we want to query from.&#160; If the event session is active and running, we can get this information by querying the Active Session DMV\u2019s.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">SELECT \r\n    <\/span>soc<span style=\"color: gray\">.<\/span>column_name<span style=\"color: gray\">,\r\n    <\/span>soc<span style=\"color: gray\">.<\/span>column_value\r\n<span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_sessions <\/span>s\r\n<span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_session_object_columns <\/span>soc\r\n    <span style=\"color: blue\">ON <\/span>s<span style=\"color: gray\">.<\/span><span style=\"color: blue\">address <\/span><span style=\"color: gray\">= <\/span>soc<span style=\"color: gray\">.<\/span>event_session_address\r\n<span style=\"color: blue\">WHERE <\/span>s<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'DemoPersistedEvents'\r\n  <\/span><span style=\"color: gray\">AND <\/span>soc<span style=\"color: gray\">.<\/span><span style=\"color: magenta\">object_name <\/span><span style=\"color: gray\">= <\/span><span style=\"color: red\">'asynchronous_file_target'<\/span><\/pre>\n<\/blockquote>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/2b0bf0c9\/image.png\"><img decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/2e3dd8b1\/image_thumb.png\" width=\"554\" height=\"120\" \/><\/a> <\/p>\n<p>Notice that the metatdatafile option is NULL, meaning that we were lazy and didn\u2019t explicitly define the metadata file information in our Event Session so now we have to figure it out in order to query the target data from the log files.&#160; One way to find the information would be to open up the path on the server to the log file that was specified:<\/p>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/0d4a660a\/image.png\"><img decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/52eef028\/image_thumb.png\" width=\"644\" height=\"168\" \/><\/a> <\/p>\n<p>Notice that the Extended Events Engine automatically created a metadata file with the same name as the log file, but a different extension, .xem.&#160; Also notice that the file names for both the log file and the metadata file have changed from what was actually defined in the Event Session.&#160; The Engine adds a _0_ and a long integer value that represents the number of milliseconds between January 1, 1600 and the date and time that the file was generated by the Extended Events Engine.&#160; Subsequent files will have a different long integer value that is larger in value allowing you to easily sort the log files from oldest to newest or vice versa.&#160; To query the data contained in the log files, you have two options.&#160; First you can explicitly provide the filenames as shown above, or you can use wildcards in the names and the engine will find the correct matching files and begin reading them.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">DECLARE <\/span>@path <span style=\"color: blue\">nvarchar<\/span><span style=\"color: gray\">(<\/span>260<span style=\"color: gray\">), <\/span>@mdpath <span style=\"color: blue\">nvarchar<\/span><span style=\"color: gray\">(<\/span>260<span style=\"color: gray\">)\r\n\r\n<\/span><span style=\"color: green\">-- Get the log file name and substitute * wildcard in\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span>@path <span style=\"color: gray\">= LEFT(<\/span>column_value<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">LEN<\/span><span style=\"color: gray\">(<\/span>column_value<span style=\"color: gray\">)-<\/span><span style=\"color: magenta\">CHARINDEX<\/span><span style=\"color: gray\">(<\/span><span style=\"color: red\">'.'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: magenta\">REVERSE<\/span><span style=\"color: gray\">(<\/span>column_value<span style=\"color: gray\">))) \r\n        + <\/span><span style=\"color: red\">'*' \r\n        <\/span><span style=\"color: gray\">+ RIGHT(<\/span>column_value<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">CHARINDEX<\/span><span style=\"color: gray\">(<\/span><span style=\"color: red\">'.'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: magenta\">REVERSE<\/span><span style=\"color: gray\">(<\/span>column_value<span style=\"color: gray\">))-<\/span>1<span style=\"color: gray\">)\r\n<\/span><span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_sessions <\/span>s\r\n<span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_session_object_columns <\/span>soc\r\n    <span style=\"color: blue\">ON <\/span>s<span style=\"color: gray\">.<\/span><span style=\"color: blue\">address <\/span><span style=\"color: gray\">= <\/span>soc<span style=\"color: gray\">.<\/span>event_session_address\r\n<span style=\"color: blue\">WHERE <\/span>s<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'DemoPersistedEvents'\r\n  <\/span><span style=\"color: gray\">AND <\/span>soc<span style=\"color: gray\">.<\/span><span style=\"color: magenta\">object_name <\/span><span style=\"color: gray\">= <\/span><span style=\"color: red\">'asynchronous_file_target'\r\n  <\/span><span style=\"color: gray\">AND <\/span>soc<span style=\"color: gray\">.<\/span>column_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'filename'\r\n\r\n<\/span><span style=\"color: green\">-- Get the metadata file name and substitute * wildcard in \r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span>@mdpath <span style=\"color: gray\">= LEFT(<\/span>column_value<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">LEN<\/span><span style=\"color: gray\">(<\/span>column_value<span style=\"color: gray\">)-<\/span><span style=\"color: magenta\">CHARINDEX<\/span><span style=\"color: gray\">(<\/span><span style=\"color: red\">'.'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: magenta\">REVERSE<\/span><span style=\"color: gray\">(<\/span>column_value<span style=\"color: gray\">))) \r\n        + <\/span><span style=\"color: red\">'*' \r\n        <\/span><span style=\"color: gray\">+ RIGHT(<\/span>column_value<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">CHARINDEX<\/span><span style=\"color: gray\">(<\/span><span style=\"color: red\">'.'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: magenta\">REVERSE<\/span><span style=\"color: gray\">(<\/span>column_value<span style=\"color: gray\">))-<\/span>1<span style=\"color: gray\">)\r\n<\/span><span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_sessions <\/span>s\r\n<span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_session_object_columns <\/span>soc\r\n    <span style=\"color: blue\">ON <\/span>s<span style=\"color: gray\">.<\/span><span style=\"color: blue\">address <\/span><span style=\"color: gray\">= <\/span>soc<span style=\"color: gray\">.<\/span>event_session_address\r\n<span style=\"color: blue\">WHERE <\/span>s<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'DemoPersistedEvents'\r\n  <\/span><span style=\"color: gray\">AND <\/span>soc<span style=\"color: gray\">.<\/span><span style=\"color: magenta\">object_name <\/span><span style=\"color: gray\">= <\/span><span style=\"color: red\">'asynchronous_file_target'\r\n  <\/span><span style=\"color: gray\">AND <\/span>soc<span style=\"color: gray\">.<\/span>column_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">' metadatafile'\r\n\r\n<\/span><span style=\"color: green\">-- Set the metadata filename if it is NULL to the log file name with xem extension\r\n<\/span><span style=\"color: blue\">SELECT <\/span>@mdpath <span style=\"color: gray\">= <\/span><span style=\"color: magenta\">ISNULL<\/span><span style=\"color: gray\">(<\/span>@mdpath<span style=\"color: gray\">, \r\n                        LEFT(<\/span>@path<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">LEN<\/span><span style=\"color: gray\">(<\/span>@path<span style=\"color: gray\">)-<\/span><span style=\"color: magenta\">CHARINDEX<\/span><span style=\"color: gray\">(<\/span><span style=\"color: red\">'*'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: magenta\">REVERSE<\/span><span style=\"color: gray\">(<\/span>@path<span style=\"color: gray\">))) \r\n                        + <\/span><span style=\"color: red\">'*xem'<\/span><span style=\"color: gray\">)\r\n\r\n<\/span><span style=\"color: green\">-- Query the Event data from the Target.\r\n<\/span><span style=\"color: blue\">SELECT\r\n    <\/span>module_guid<span style=\"color: gray\">,\r\n    <\/span>package_guid<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">object_name<\/span><span style=\"color: gray\">,\r\n    <\/span>event_data<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">file_name<\/span><span style=\"color: gray\">,\r\n    <\/span>file_offset\r\n<span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span>fn_xe_file_target_read_file<span style=\"color: gray\">(<\/span>@path<span style=\"color: gray\">, <\/span>@mdpath<span style=\"color: gray\">, null, null)\r\n<\/span><\/pre>\n<p>  <a href=\"http:\/\/www.11011.net\/software\/vspaste\"><\/a><\/p><\/blockquote>\n<p>&#160;<\/p>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/5f7c9d44\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/7e531122\/image_thumb.png\" width=\"644\" height=\"44\" \/><\/a> <\/p>\n<p>&#160;<\/p>\n<p>The DMF outputs the module_guid, package_guid, and object_name associated with the Event, the event_data as a XML document, but in string format requiring that it be CAST\/CONVERT\u2019d to XML for parsing, the file_name of the log file that the Event data was read from and the file_offset inside the file for the event.&#160; Using a CAST to XML and performing a CROSS APPLY of the &lt;event&gt; nodes and the same XQuery\u2019s as in yesterday\u2019s post we can query the Event data from the asynchronous_file_target.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: green\">-- Query the Event data from the Target.\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(@name)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>event_name<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(@package)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>package_name<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(@id)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>id<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(@version)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS version<\/span><span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">DATEADD<\/span><span style=\"color: gray\">(<\/span>hh<span style=\"color: gray\">, \r\n            <\/span><span style=\"color: magenta\">DATEDIFF<\/span><span style=\"color: gray\">(<\/span>hh<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">GETUTCDATE<\/span><span style=\"color: gray\">(), <\/span><span style=\"color: magenta\">CURRENT_TIMESTAMP<\/span><span style=\"color: gray\">), \r\n            <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(@timestamp)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'datetime2'<\/span><span style=\"color: gray\">)) <\/span><span style=\"color: blue\">AS <\/span>[timestamp]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(data[@name=&quot;error&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>error<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(data[@name=&quot;severity&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>severity<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(data[@name=&quot;duration&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as state<\/span><span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(data[@name=&quot;user_defined&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(5)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>user_defined<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(data[@name=&quot;message&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(max)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as message\r\nFROM \r\n<\/span><span style=\"color: gray\">(<\/span><span style=\"color: blue\">SELECT\r\n    <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span>event_data <span style=\"color: blue\">AS XML<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>event_data\r\n <span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span>fn_xe_file_target_read_file<span style=\"color: gray\">(<\/span>@path<span style=\"color: gray\">, <\/span>@mdpath<span style=\"color: gray\">, null, null)\r\n) <\/span><span style=\"color: blue\">as <\/span>tab\r\n<span style=\"color: gray\">CROSS APPLY <\/span>event_data<span style=\"color: gray\">.<\/span>nodes<span style=\"color: gray\">(<\/span><span style=\"color: red\">'event'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>q<span style=\"color: gray\">(<\/span>n<span style=\"color: gray\">)<\/span><\/pre>\n<p>  <a href=\"http:\/\/www.11011.net\/software\/vspaste\"><\/a><\/p><\/blockquote>\n<p>Like the ring_buffer Target, the asynchronous_file_target also has an entry in sys.dm_xe_session_targets, but instead of returning the Event data, it returns information about the targets operation.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">select \r\n    <\/span>target_data<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(FileTarget\/@truncated)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>truncated<span style=\"color: gray\">,\r\n    <\/span>target_data<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(FileTarget\/Buffers\/@logged)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>logged<span style=\"color: gray\">,\r\n    <\/span>target_data<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(FileTarget\/Buffers\/@dropped)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>dropped\r\n<span style=\"color: blue\">FROM\r\n<\/span><span style=\"color: gray\">(<\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span>target_data <span style=\"color: blue\">AS XML<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>target_data\r\n<span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_sessions <\/span><span style=\"color: blue\">AS <\/span>s \r\n<span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_session_targets <\/span><span style=\"color: blue\">AS <\/span>t \r\n    <span style=\"color: blue\">ON <\/span>t<span style=\"color: gray\">.<\/span>event_session_address <span style=\"color: gray\">= <\/span>s<span style=\"color: gray\">.<\/span><span style=\"color: blue\">address\r\nWHERE <\/span>s<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'DemoPersistedEvents'\r\n  <\/span><span style=\"color: gray\">AND <\/span>t<span style=\"color: gray\">.<\/span>target_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'asynchronous_file_target'\r\n<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>tab<\/pre>\n<p>  <a href=\"http:\/\/www.11011.net\/software\/vspaste\"><\/a><\/p><\/blockquote>\n<p>The file_name and file_offset information in the the sys.fn_xe_file_target_read_file output can be used to perform differential reads from the asynchronous_file_target.&#160; To demonstrate this we can create an Event Session that will capture a lot of Events in a short period of time. <\/p>\n<p><strong>(Note: I wouldn\u2019t create an unfiltered Event Session on the starting and completed events like this on a production server without first evaluating its potential impact.&#160; While this should be safe, if it causes you a problem, its your server not mine.)<\/strong><\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">IF <\/span><span style=\"color: gray\">EXISTS(<\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: gray\">* <\/span><span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">server_event_sessions <\/span><span style=\"color: blue\">WHERE <\/span>name<span style=\"color: gray\">=<\/span><span style=\"color: red\">'FileTargetDemo'<\/span><span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">DROP EVENT SESSION <\/span>[FileTargetDemo] <span style=\"color: blue\">ON SERVER<\/span><span style=\"color: gray\">;\r\n<\/span><span style=\"color: blue\">CREATE EVENT SESSION <\/span>[FileTargetDemo]\r\n<span style=\"color: blue\">ON SERVER\r\nADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>sql_statement_starting<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>sql_statement_completed<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>sp_statement_starting<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>sp_statement_completed<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>rpc_starting<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>rpc_completed<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>module_start<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>module_end\r\n<span style=\"color: blue\">ADD TARGET <\/span>package0<span style=\"color: gray\">.<\/span>asynchronous_file_target<span style=\"color: gray\">(\r\n     <\/span><span style=\"color: blue\">SET filename<\/span><span style=\"color: gray\">=<\/span><span style=\"color: red\">'D:\\SQLData\\MSSQL10.MSSQLSERVER\\MSSQL\\Log\\FileTargetDemo.xel'<\/span><span style=\"color: gray\">, \r\n         <\/span>metadatafile<span style=\"color: gray\">=<\/span><span style=\"color: red\">'D:\\SQLData\\MSSQL10.MSSQLSERVER\\MSSQL\\Log\\FileTargetDemo.xem'<\/span><span style=\"color: gray\">,\r\n         <\/span>max_file_size <span style=\"color: gray\">= <\/span>5<span style=\"color: gray\">,\r\n         <\/span>max_rollover_files <span style=\"color: gray\">= <\/span>5<span style=\"color: gray\">)\r\n<\/span><span style=\"color: blue\">WITH<\/span><span style=\"color: gray\">(<\/span>MAX_DISPATCH_LATENCY <span style=\"color: gray\">= <\/span>5SECONDS<span style=\"color: gray\">)\r\n<\/span><span style=\"color: blue\">GO\r\n\r\n<\/span><span style=\"color: green\">-- Start the Event Collection\r\n<\/span><span style=\"color: blue\">ALTER EVENT SESSION <\/span>[FileTargetDemo]\r\n<span style=\"color: blue\">ON SERVER\r\nSTATE<\/span><span style=\"color: gray\">=<\/span><span style=\"color: blue\">STOP\r\nGO\r\n\r\n<\/span><span style=\"color: green\">-- Take a pause and allow events to be generated\r\n\r\n\r\n-- Query the target data from the files.\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span><span style=\"color: magenta\">object_name<\/span><span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span>event_data <span style=\"color: blue\">as xml<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>event_data<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">file_name<\/span><span style=\"color: gray\">, \r\n    <\/span>file_offset\r\n<span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span>fn_xe_file_target_read_file<span style=\"color: gray\">(<\/span><span style=\"color: red\">'D:\\SQLData\\MSSQL10.MSSQLSERVER\\MSSQL\\Log\\FileTargetDemo*xel'<\/span><span style=\"color: gray\">, \r\n            <\/span><span style=\"color: red\">'D:\\SQLData\\MSSQL10.MSSQLSERVER\\MSSQL\\Log\\FileTargetDemo*xem'<\/span><span style=\"color: gray\">, \r\n            null,\r\n            null)<\/span><\/pre>\n<p>  <a href=\"http:\/\/www.11011.net\/software\/vspaste\"><\/a><\/p><\/blockquote>\n<p>If you scroll through the output to where the file_offset changes, you can grab the file_name and file_offset for the last event in the first file_offset.<\/p>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/36255546\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/4246cf6d\/image_thumb.png\" width=\"644\" height=\"122\" \/><\/a> <\/p>\n<p>Then requery the target passing that file_name and file_offset into the @initial_file_name and @intitial_offset parameters of the sys.fn_xe_file_target_read_file DMF to have the DMF begin reading from the last entry of the provided offset forward.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: green\">-- Query the target data from the files.\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span><span style=\"color: magenta\">object_name<\/span><span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span>event_data <span style=\"color: blue\">as xml<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>event_data<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">file_name<\/span><span style=\"color: gray\">, \r\n    <\/span>file_offset\r\n<span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span>fn_xe_file_target_read_file<span style=\"color: gray\">(<\/span><span style=\"color: red\">'D:\\SQLData\\MSSQL10.MSSQLSERVER\\MSSQL\\Log\\FileTargetDemo*xel'<\/span><span style=\"color: gray\">, \r\n            <\/span><span style=\"color: red\">'D:\\SQLData\\MSSQL10.MSSQLSERVER\\MSSQL\\Log\\FileTargetDemo*xem'<\/span><span style=\"color: gray\">,             \r\n            <\/span><span style=\"color: red\">'D:\\SQLData\\MSSQL10.MSSQLSERVER\\MSSQL\\Log\\FileTargetDemo_0_129360796797990000.xel'<\/span><span style=\"color: gray\">,\r\n            <\/span>0<span style=\"color: gray\">)<\/span><\/pre>\n<p>  <a href=\"http:\/\/www.11011.net\/software\/vspaste\"><\/a><\/p><\/blockquote>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/728da423\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/77fc14c7\/image_thumb.png\" width=\"644\" height=\"106\" \/><\/a> <\/p>\n<p>If you\u2019ve run the demo\u2019s in this blog post to this point, don\u2019t forget to cleanup the system.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">IF <\/span><span style=\"color: gray\">EXISTS(<\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: gray\">* <\/span><span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">server_event_sessions <\/span><span style=\"color: blue\">WHERE <\/span>name<span style=\"color: gray\">=<\/span><span style=\"color: red\">'FileTargetDemo'<\/span><span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">DROP EVENT SESSION <\/span>[FileTargetDemo] <span style=\"color: blue\">ON SERVER<\/span><span style=\"color: gray\">;\r\n<\/span><span style=\"color: blue\">GO\r\nIF <\/span><span style=\"color: gray\">EXISTS(<\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: gray\">* <\/span><span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">server_event_sessions <\/span><span style=\"color: blue\">WHERE <\/span>name<span style=\"color: gray\">=<\/span><span style=\"color: red\">'DemoPersistedEvents'<\/span><span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">DROP EVENT SESSION <\/span>[DemoPersistedEvents] <span style=\"color: blue\">ON SERVER<\/span><span style=\"color: gray\">;\r\n<\/span><span style=\"color: blue\">GO<\/span><\/pre>\n<p>  <a href=\"http:\/\/www.11011.net\/software\/vspaste\"><\/a><\/p><\/blockquote>\n<h2>Considerations for Usage<\/h2>\n<p>The asynchronous_file_target will probably be the preferred target for most people interested in performing long term analysis of Events collected, or performing short term analysis using an Event Session that is expected to generate a large number of events and event loss due to the FIFO nature of the ring_buffer is not acceptable.&#160; However, there are a couple of considerations associated with this target.&#160; The first is that the log files and metadata file are a set, and have to be maintained together.&#160; If you send someone a log file without the metadata file, they won\u2019t be able to read the information contained in the log file.&#160; The second consideration associated with this target is that the only way to read the information contained inside of the log files, as of the date of this blog post being published, is to copy them to a system that is running SQL Server 2008 or 2008R2 and query the files using the there is no way to retrieve the information contained inside of the log files, without querying the sys.fn_xe_file_target_read_file() DMF using TSQL.&#160; <\/p>\n<h2>What\u2019s next?<\/h2>\n<p>Now that we have looked at the asynchronous_file_target Target, in the next post we\u2019ll look at the bucketizer Targets which can be used to group occurrences of Events based on the Event data being returned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday\u2019s post, Targets Week &#8211; ring_buffer, looked at the ring_buffer Target in Extended Events and how it outputs the raw Event data in an XML document.&#160; Today I\u2019m going to go over the details of the other Target in Extended Events that captures raw Event data, the asynchronous_file_target. What is the asynchronous_file_target? The asynchronous_file_target holds [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,38,45],"tags":[],"class_list":["post-558","post","type-post","status-publish","format-standard","hentry","category-extended-events","category-sql-server-2008","category-xevent-a-day-series"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>An XEvent a Day (6 of 31) - Targets Week - asynchronous_file_target - Jonathan Kehayias<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An XEvent a Day (6 of 31) - Targets Week - asynchronous_file_target - Jonathan Kehayias\" \/>\n<meta property=\"og:description\" content=\"Yesterday\u2019s post, Targets Week &#8211; ring_buffer, looked at the ring_buffer Target in Extended Events and how it outputs the raw Event data in an XML document.&#160; Today I\u2019m going to go over the details of the other Target in Extended Events that captures raw Event data, the asynchronous_file_target. What is the asynchronous_file_target? The asynchronous_file_target holds [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/\" \/>\n<meta property=\"og:site_name\" content=\"Jonathan Kehayias\" \/>\n<meta property=\"article:published_time\" content=\"2010-12-06T22:43:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-13T19:49:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/4bff6370\/image_thumb.png\" \/>\n<meta name=\"author\" content=\"Jonathan Kehayias\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jonathan Kehayias\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/\"},\"author\":{\"name\":\"Jonathan Kehayias\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\"},\"headline\":\"An XEvent a Day (6 of 31) &#8211; Targets Week &#8211; asynchronous_file_target\",\"datePublished\":\"2010-12-06T22:43:00+00:00\",\"dateModified\":\"2017-04-13T19:49:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/\"},\"wordCount\":1889,\"commentCount\":5,\"image\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.SQLskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/windowslivewriter\\\/anxeventaday6of31targetsweekasynchronous\\\/4bff6370\\\/image_thumb.png\",\"articleSection\":[\"Extended Events\",\"SQL Server 2008\",\"XEvent a Day Series\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/\",\"url\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/\",\"name\":\"An XEvent a Day (6 of 31) - Targets Week - asynchronous_file_target - Jonathan Kehayias\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.SQLskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/windowslivewriter\\\/anxeventaday6of31targetsweekasynchronous\\\/4bff6370\\\/image_thumb.png\",\"datePublished\":\"2010-12-06T22:43:00+00:00\",\"dateModified\":\"2017-04-13T19:49:07+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.SQLskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/windowslivewriter\\\/anxeventaday6of31targetsweekasynchronous\\\/4bff6370\\\/image_thumb.png\",\"contentUrl\":\"https:\\\/\\\/www.SQLskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/windowslivewriter\\\/anxeventaday6of31targetsweekasynchronous\\\/4bff6370\\\/image_thumb.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Extended Events\",\"item\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/category\\\/extended-events\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"An XEvent a Day (6 of 31) &#8211; Targets Week &#8211; asynchronous_file_target\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/\",\"name\":\"Jonathan Kehayias - The Rambling DBA\",\"description\":\"The Rambling DBA\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\",\"name\":\"Jonathan Kehayias\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"caption\":\"Jonathan Kehayias\"},\"sameAs\":[\"http:\\\/\\\/3.209.169.194\\\/blogs\\\/jonathan\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An XEvent a Day (6 of 31) - Targets Week - asynchronous_file_target - Jonathan Kehayias","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/","og_locale":"en_US","og_type":"article","og_title":"An XEvent a Day (6 of 31) - Targets Week - asynchronous_file_target - Jonathan Kehayias","og_description":"Yesterday\u2019s post, Targets Week &#8211; ring_buffer, looked at the ring_buffer Target in Extended Events and how it outputs the raw Event data in an XML document.&#160; Today I\u2019m going to go over the details of the other Target in Extended Events that captures raw Event data, the asynchronous_file_target. What is the asynchronous_file_target? The asynchronous_file_target holds [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/","og_site_name":"Jonathan Kehayias","article_published_time":"2010-12-06T22:43:00+00:00","article_modified_time":"2017-04-13T19:49:07+00:00","og_image":[{"url":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/4bff6370\/image_thumb.png","type":"","width":"","height":""}],"author":"Jonathan Kehayias","twitter_misc":{"Written by":"Jonathan Kehayias","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/#article","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/"},"author":{"name":"Jonathan Kehayias","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c"},"headline":"An XEvent a Day (6 of 31) &#8211; Targets Week &#8211; asynchronous_file_target","datePublished":"2010-12-06T22:43:00+00:00","dateModified":"2017-04-13T19:49:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/"},"wordCount":1889,"commentCount":5,"image":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/#primaryimage"},"thumbnailUrl":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/4bff6370\/image_thumb.png","articleSection":["Extended Events","SQL Server 2008","XEvent a Day Series"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/","url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/","name":"An XEvent a Day (6 of 31) - Targets Week - asynchronous_file_target - Jonathan Kehayias","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/#primaryimage"},"thumbnailUrl":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/4bff6370\/image_thumb.png","datePublished":"2010-12-06T22:43:00+00:00","dateModified":"2017-04-13T19:49:07+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/#primaryimage","url":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/4bff6370\/image_thumb.png","contentUrl":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windowslivewriter\/anxeventaday6of31targetsweekasynchronous\/4bff6370\/image_thumb.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-6-of-31-targets-week-asynchronous_file_target\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/"},{"@type":"ListItem","position":2,"name":"Extended Events","item":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/category\/extended-events\/"},{"@type":"ListItem","position":3,"name":"An XEvent a Day (6 of 31) &#8211; Targets Week &#8211; asynchronous_file_target"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/","name":"Jonathan Kehayias - The Rambling DBA","description":"The Rambling DBA","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c","name":"Jonathan Kehayias","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","caption":"Jonathan Kehayias"},"sameAs":["http:\/\/3.209.169.194\/blogs\/jonathan"]}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts\/558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/comments?post=558"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts\/558\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/media?parent=558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/categories?post=558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/tags?post=558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}