I searched online far and wide and didn't see anyone else posting about this so I thought I would. I am trying to audit when the query store does its cleanup and is purged from the query store.

There are two extended event sessions I found that I thought were the events but I have no data being picked up even after the query store has purged stale query data:

 1. query_store_db_cleanup_started
 2. query_store_db_cleanup_finished

Wondering if anyone else has had the same issue and is as curious as I when the query store purged its data?

Below is the code I have for setting up my current audit:

 

       CREATE EVENT SESSION [QueryStore_Cleanup_Audit]
    ON SERVER
        ADD EVENT qds.query_store_db_cleanup__finished
        (ACTION
         (
             package0.last_error,
             package0.process_id,
             sqlos.cpu_id,
             sqlos.system_thread_id,
             sqlos.task_time,
             sqlserver.client_app_name,
             sqlserver.client_connection_id,
             sqlserver.client_hostname,
             sqlserver.client_pid,
             sqlserver.context_info,
             sqlserver.database_id,
             sqlserver.database_name,
             sqlserver.nt_username,
             sqlserver.plan_handle,
             sqlserver.server_instance_name,
             sqlserver.session_id,
             sqlserver.session_nt_username,
             sqlserver.sql_text,
             sqlserver.transaction_id,
             sqlserver.username
         )
         WHERE ([database_id] = (5))
        ),
        ADD EVENT qds.query_store_db_cleanup__started
        (ACTION
         (
             package0.last_error,
             package0.process_id,
             sqlos.cpu_id,
             sqlos.system_thread_id,
             sqlos.task_time,
             sqlserver.client_app_name,
             sqlserver.client_connection_id,
             sqlserver.client_hostname,
             sqlserver.client_pid,
             sqlserver.context_info,
             sqlserver.database_id,
             sqlserver.database_name,
             sqlserver.nt_username,
             sqlserver.plan_handle,
             sqlserver.server_instance_name,
             sqlserver.session_id,
             sqlserver.session_nt_username,
             sqlserver.sql_text,
             sqlserver.transaction_id,
             sqlserver.username
         )
         WHERE ([database_id] = (5))
        )
    WITH
    (
        MAX_MEMORY = 40096KB,
        EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS,
        MAX_DISPATCH_LATENCY = 30 SECONDS,
        MAX_EVENT_SIZE = 0KB,
        MEMORY_PARTITION_MODE = NONE,
        TRACK_CAUSALITY = OFF,
        STARTUP_STATE = ON
    );
    GO
    
    
    
    
    query_store_db_cleanup_started