Updated on 2024-10-24 GMT+08:00

Viewing and Downloading Audit Logs

The SQL audit function is enabled by default for Microsoft SQL Server DB instances and cannot be disabled. Major change operations on services, databases, and tables are recorded in audit log files for future query and download.

RDS for SQL Server Audit enables you to audit server-level and database-level groups of events and individual events. RDS for SQL Server audits consist of zero or more audit action items. Table 1 shows the server-level audit action groups and provides the equivalent RDS for SQL Server Event Class where applicable. For more information, see SQL Server Audit Action Groups and Actions.

  • The maximum size of an audit log file is 50 MB. Up to 50 audit log files can be displayed.
  • RDS for SQL Server 2008 Web and Standard Editions do not support the SQL audit function.
  • No audit is performed for job creation and modifications on parameters, server attribute parameters, SQL agent attribute parameters, and database extended attribute parameters.
  • The succeeded parameter displayed in the audit log indicates whether the event is triggered successfully. Its value cannot be null. For all events except login events, only the success or failure of the permission check (not the operation) is reported.
  • For details about the audit of table-level and column-level architecture changes, see the audit result of the SQL Server engine.
  • To read audit logs, you can obtain the audit log file name from the console and then run the following statement:

    select * from msdb.dbo.rds_fn_get_audit_file('D:\ServerAudit\audit\RDSAudit_test.sqlaudit', default, default)

    If you have already downloaded the audit log file to a local directory, log in to your local SQL Server database and then run the following statement (the local account must have the CONTROL SERVER permission):

    select * from sys.fn_get_audit_file('\\path\RDSAudit_test.sqlaudit', default, default)

Table 1 Audit action groups

Action Group Name

Description

APPLICATION_ROLE_CHANGE_PASSWORD_GROUP

This event is raised whenever a password is changed for an application role.

DATABASE_CHANGE_GROUP

This event is raised when a database is created, altered, or dropped.

DATABASE_OBJECT_CHANGE_GROUP

This event is raised when a CREATE, ALTER, or DROP statement is executed on database objects, such as schemas.

DATABASE_OBJECT_OWNERSHIP_CHANGE_GROUP

This event is raised when a change of owner for objects within database scope.

DATABASE_OBJECT_PERMISSION_CHANGE_GROUP

This event is raised when a GRANT, REVOKE, or DENY has been issued for database objects, such as assemblies and schemas.

DATABASE_OWNERSHIP_CHANGE_GROUP

This event is raised when you use the ALTER AUTHORIZATION statement to change the owner of a database.

DATABASE_PERMISSION_CHANGE_GROUP

This event is raised whenever a GRANT, REVOKE, or DENY is issued for a statement permission by any user in SQL Server for database-only events such as granting permissions on a database.

DATABASE_PRINCIPAL_CHANGE_GROUP

This event is raised when principals, such as users, are created, altered, or dropped from a database.

DATABASE_ROLE_MEMBER_CHANGE_GROUP

This event is raised whenever a login is added to or removed from a database role.

FAILED_LOGIN_GROUP

Indicates that a principal tried to log on to a SQL Server database and failed. Events in this class are raised by new connections or by connections that are reused from a connection pool.

LOGIN_CHANGE_PASSWORD_GROUP

This event is raised whenever a login password is changed by way of ALTER LOGIN statement or sp_password stored procedure.

SCHEMA_OBJECT_CHANGE_GROUP

This event is raised when a CREATE, ALTER, or DROP operation is performed on a schema.

SCHEMA_OBJECT_OWNERSHIP_CHANGE_GROUP

This event is raised when the permissions to change the owner of schema object (such as a table, procedure, or function) is checked.

SCHEMA_OBJECT_PERMISSION_CHANGE_GROUP

This event is raised whenever a grant, deny, revoke is performed against a schema object.

SERVER_OBJECT_CHANGE_GROUP

This event is raised for CREATE, ALTER, or DROP operations on server objects.

SERVER_OBJECT_OWNERSHIP_CHANGE_GROUP

This event is raised when the owner is changed for objects in server scope.

SERVER_OBJECT_PERMISSION_CHANGE_GROUP

This event is raised whenever a GRANT, REVOKE, or DENY is issued for a server object permission by any principal in SQL Server.

SERVER_PERMISSION_CHANGE_GROUP

This event is raised when a GRANT, REVOKE, or DENY is issued for permissions in the server scope.

SERVER_PRINCIPAL_CHANGE_GROUP

This event is raised when server principals are created, altered, or dropped.

SERVER_ROLE_MEMBER_CHANGE_GROUP

This event is raised whenever a login is added or removed from a fixed server role.

SERVER_STATE_CHANGE_GROUP

This event is raised when the SQL Server service state is modified.

USER_CHANGE_PASSWORD_GROUP

This event is raised whenever the password of a contained database user is changed by using the ALTER USER statement (SQL Server 2008 is not involved).

Querying Audit Logs

  1. Log in to the management console.
  2. Click in the upper left corner and select a region.
  3. Click in the upper left corner of the page and choose Databases > Relational Database Service.
  4. On the Instances page, click the target instance name.
  5. In the navigation pane on the left, choose Logs. On the System Logs page, click Downloads.
  6. On the Downloads page, record the names of audit logs.

    Figure 1 RDS for SQL Server audit logs

    The audit log name starts with RDSAudit. The system automatically adds the GUID and timestamp to the file name as a suffix.

  7. Connect to the DB instance through the Microsoft SQL Server client. For details, see Connecting to a DB Instance Through a Public Network.
  8. After the DB instance is connected, run the following command to view details about SQL audit logs:

    select * from msdb.dbo.rds_fn_get_audit_file(file_pattern, initial_file_name, audit_record_offset)

    Table 2 Parameter description

    Parameter

    Description

    file_pattern

    Specifies the directory or path and file name for the audit file set to be read.

    initial_file_name

    Specifies the path and name of a specific file in the audit file set to start reading audit records from.

    audit_record_offset

    Specifies a known location with the file specified for the initial_file_name.

    Example:

    select * from msdb.dbo.rds_fn_get_audit_file('D:\ServerAudit\audit\*.sqlaudit', default, default)

    Figure 2 Audit log details

Downloading SQL Audit Logs

  1. Log in to the management console.
  2. Click in the upper left corner and select a region.
  3. Click in the upper left corner of the page and choose Databases > Relational Database Service.
  4. On the Instances page, click the target instance name.
  5. In the navigation pane on the left, choose Logs. On the System Logs page, click Downloads.
  6. Locate a log to be downloaded and click Download in the Operation column.

    1. The system automatically loads the downloading preparation tasks. The loading duration is determined by the log file size and network environment.
      • When the log is being prepared for download, the log status is Preparing.
      • When the log is ready for download, the log status is Preparation completed.
      • If the preparation for download fails, the log status is Abnormal.
    2. In the displayed dialog box, click OK to download the log whose status is Preparation completed. If you click Cancel, the system does not download the log.

      The download link is valid for 5 minutes. After the download link expires, a message is displayed indicating that the download link has expired. You can close the window and repeat the procedure 6 to try to download a log again.