Query store audit
-
07-02-2021 - |
Question
We frequently use query store force plan feature.
We would like to audit when and who forced each plan.
Is extended events session is needed auditing this event,
or there are dmvs or catalog views with this specific information?
Solution
You could create some auditing on the execution of the sys.sp_query_store_force_plan
procedure.
Create the server audit
USE master ;
GO
-- Create the server audit.
CREATE SERVER AUDIT ServerAudit
TO FILE ( FILEPATH =
'D:\AuditFiles\' ) ;
GO
-- Enable the server audit.
ALTER SERVER AUDIT ServerAudit
WITH (STATE = ON) ;
Create the database audit specification
CREATE DATABASE AUDIT SPECIFICATION Audit_Plan_force
FOR SERVER AUDIT ServerAudit
ADD (EXECUTE
ON sys.sp_query_store_force_plan BY public)
WITH (STATE = ON) ;
GO
Force a plan in a user database
Query the audit file
SELECT event_time,Action_id,succeeded,server_principal_name,database_name,object_name,Statement
FROM fn_get_audit_file('D:\AuditFiles\*',default,default);
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange