SQL Server Audit / Extended Events – Role‑based (sysadmin) filtering limitations

Uday Paleti 5 Reputation points
2026-04-24T17:19:09.7+00:00

Hello Microsoft Team,

We are implementing security monitoring for sysadmin account usage on an on‑premises SQL Server instance and would like to know what EX events or Audit to achieve our goal?

We tried Audit and XE events but those are capturing all logins (Sysadmin,Non Sysadmin,Developer accounts etc.) so we do not want noise on Prod server. We want capture who is login with sysadmin rights other than DBA.

Please help me possible solution. Thanks.

Our requirement

We want to:

  • Capture login activity related to sysadmin accounts
  • Identify approved vs unapproved sysadmin usage
  • Exclude specific trusted DBA/service accounts
  • No performance impact on Prod servers.**

Below event not creating and getting error
**CREATE EVENT SESSION Audit_Sysadmin_Logins_test

ON SERVER

ADD EVENT sqlserver.login

(

ACTION (

    sqlserver.client_app_name,

	sqlserver.username,  

    sqlserver.client_hostname,

    sqlserver.server_principal_name,

    sqlserver.session_id

)

WHERE

(

    -- Only successful logins

    [result] = 0

    -- Must be sysadmin

    AND IS_SRVROLEMEMBER('sysadmin', [server_principal_name]) = 1

    -- Exclude DBA/service accounts

    AND [server_principal_name] NOT IN (

        'DOMAIN\dba_user1',

        'DOMAIN\dba_user2'

       

    )

)

)

ADD TARGET package0.event_file

(

SET 

filename = N'R:\Extended_Events\Audit_Sysadmin_Logins.xel',

    max_file_size = 50,

    max_rollover_files = 5

);

GO

SQL Server Database Engine

Answer recommended by moderator
Uday Paleti 5 Reputation points
2026-05-07T17:25:22.5933333+00:00

Thanks, @Anonymous for the follow-up.
Due to time constraints, we created XE events for specific accounts on each server. However, I tried your suggestion (mentioned in Part 1) by modifying the script, and it works fine on the test servers. I will monitor these events for a few weeks, and if they provide the required output, we will implement them on the production servers as well. Thanks again for your suggestions.

CREATE EVENT SESSION Audit_Sysadmin_Logins_test

ON SERVER

ADD EVENT sqlserver.login

(

ACTION

(

    sqlserver.client_app_name,

    sqlserver.username,

    sqlserver.client_hostname,

    sqlserver.server_principal_name,

    sqlserver.session_id

)

WHERE

(

    -- Exclude DBA / service accounts

    

     [server_principal_name] <> 'DOMAIN\dba_user1'

    AND [server_principal_name] <> 'dba_user2'

	AND [server_principal_name] <> 'DOMAIN\dba_use3'

	AND [server_principal_name] <> 'dba_user4'

)

)

ADD TARGET package0.event_file

(

SET

    filename = N'R:\Extended_Events\Audit_Sysadmin_Logins.xel',

    max_file_size = 50,

    max_rollover_files = 5

);

GO

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Oldest
  1. Erland Sommarskog 137.6K Reputation points MVP Volunteer Moderator
    2026-04-24T21:22:05.2166667+00:00

    I'm afraid that there is no straightforward way to do what you want to do. I think the best you can do is to set up an event session where you explicitly list the members of sysadmin (with the exception of your two DBA users). If you add new persons to sysadmin, you will to modify the events session accordingly.

    I should point out that there is quite a flaw here: A malicious user may have found a way to elevate to sysadmin on the fly when the user wants to perform something evil. It goes without saying that this is something you want to capture. Although, exactly to do that, hm, I am not sure.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.