Alation Sqlserver Query Log SQL
Alation Sqlserver Query Log SQL
Alation Sqlserver Query Log SQL
SQL Server
Query History Configuration
Query Log Ingestion is done using Extended Events
STEPS
ACTION(package0.collect_system_time,package0.event_sequence,sqlos.task_
time,sqlserver.cl ient_app_name,sqlserver.database_id,sqlserver.data-
base_name,sqlserver.nt_username,sqlser ver.server_instance_name,sqlserver.
server_principal_name,sqlserver.session_id,sqlserver.sess ion_nt_user-
name,sqlserver.transaction_id,sqlserver.username)
-- Generic Alation filters, we only make use of certain types of
-- statements
-- Note SELECT is omitted because SELECT without FROM is not useful
-- for our analysis
WHERE ([statement] like ‘%ALTER %’ OR
[statement] like ‘%CREATE %’ OR
[statement] like ‘%DROP %’ OR
[statement] like ‘%TRUNCATE %’ OR
[statement] like ‘%MERGE %’ OR
[statement] like ‘%FROM %’ OR
[statement] like ‘%USE %’
))
ADD TARGET package0.event_file(
SET filename=N’C:\Users\All Users\Documents\alation_query_log.xel’,
-- CONFIGURE THIS OPTIONALLY CONFIGURE THIS, max file size in
-- MB before rolling over
-- Note Alation will read one file at a time so this is the size of
-- file that may be read into memory while it is being fetched.
max_file_size=(100), -- in MB
max_rollover_files=(100)) -- OPTIONALLY CONFIGURE THIS
WITH (MAX_MEMORY=50 MB,
-- OPTIONALLY CONFIGURE THIS, the total event buffer size
EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,
-- If buffer is full events will be dropped instead of blocking
-- the server
MAX_DISPATCH_LATENCY=30 SECONDS,
-- OPTIONALLY CONFIGURE THIS, max time before writing events to
-- storage
MAX_EVENT_SIZE=0 KB,
-- Any events that are too large to fit in the buffer will be
-- dropped
MEMORY_PARTITION_MODE=NONE,
TRACK_CAUSALITY=OFF,
STARTUP_STATE=ON
)
GO
-- Query to start the session (change START > STOP to stop it)
ALTER EVENT SESSION alation_query_log ON SERVER
STATE = START
go
-- If you need to delete and recreate the session this is the syntax
-- to drop it.
DROP EVENT SESSION [alation_query_log] ON SERVER
GO
-- Check if the session is dropping events and see other data about
-- the session
SELECT * FROM sys.dm_xe_sessions;
SECTION B