Splunk Search

Find user that ran a specific dbquery

jcrane
Explorer

I need to find which user ran a specific dbquery such as 'select * from table1'. Can someone tell me how to search splunk for this?

Thanks,
j

MythiliIyer
New Member

This works for me to find queries on any database in the instance. I'm sysadmin on the instance (check your priviledges):

SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.*
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
WHERE dest.dbid = DB_ID('msdb')
ORDER BY deqs.last_execution_time DESC

This is the same answer that Aaron Bertrand provided but it wasn't placed in an answer.

0 Karma

Ayn
Legend

Splunk keeps all issued searches in its _audit index, so you can look there. Something like this:

index=_audit action=search info=granted search="*select * from table1*"
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...