We have a large database with around 5000 objects (tables, views, sql functions, stored procedures etc.). A large portion of those objects are not in use anymore - but no-one exactly knows which ones. So we keep maintaining those old objects without knowing if someone still uses them.
We wanted to use Extended Events to trace the objects actually in use. Essentially we use the following query to collect an event whenever a database object is accessed. the events are stored in *.xel files.
CREATE EVENT SESSION {mySession} ON SERVER
ADD EVENT sqlserver.lock_acquired (
SET collect_database_name = (0)
,collect_resource_description = (1)
ACTION(sqlserver.client_hostname, sqlserver.client_app_name, collect_system_time, database_id)
WHERE (
[package0].[equal_boolean]([sqlserver].[is_system], (0)) -- user SPID
AND [package0].[equal_uint64]([resource_type], (5)) -- OBJECT
AND [package0].[equal_uint64]([database_id], {dbId}) -- user database
AND [package0].[greater_than_equal_int64]([object_id], ({minimalUserObjectId})) -- user object
AND ([mode] = (1)-- SCH - S
OR [mode] = (6)-- IS
OR [mode] = (8)-- IX
OR [mode] = (3)-- S
OR [mode] = (5)-- X
)
)
)
ADD TARGET [package0].event_file
(
SET filename='{xelFile}',
max_file_size=25,
max_rollover_files=5000
)
WITH (
MAX_MEMORY = 25 MB
,EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS
,MAX_DISPATCH_LATENCY = {MaxDispatchLatency} SECONDS
,MEMORY_PARTITION_MODE = PER_NODE
,TRACK_CAUSALITY = OFF
,STARTUP_STATE = OFF
);
We then wrote a separate program which periodically reads those *.xel files, aggretates the values and stores them in a *.xlsx file.
This prinicpally works. However, on the production database, there is an enormous amount of data collected (the *.xel files will grow to about 300 GB in size - per day!). Also, SQL server seems to use up a lot of resources for collecting the events - frequently, users cannot connect to the database or cannot run very simple queries because they get a timeout.
Is there any other - less resource intensive - way to collect usage data of db objects?