ApsaraDB RDS for SQL Server records instance events as error logs. Use these logs to diagnose issues, free up disk space by cleaning up accumulated log files, and monitor primary/secondary switchover events.
Prerequisites
Before you begin, ensure that you have:
An ApsaraDB RDS for SQL Server instance
Access to the ApsaraDB RDS console
View error logs
The console shows error logs from the last month only. For logs older than one month, use SQL statements.
View error logs in the console
Go to the Instances page. In the top navigation bar, select the region where your instance resides, then click the instance ID.
In the left-side navigation pane, click Logs.
On the Error Logs tab, select a time range to filter results.
The Error Logs tab shows events from the past month, including custom events and specific system events.
To view error logs older than one month, use SQL statements as described in the next section.
View error logs by using SQL statements
SQL Server 2016 or earlier
Call the sp_rds_read_error_logs stored procedure.
-- Return all error logs
EXEC sp_rds_read_error_logs;
-- Return error logs from log file N that contain a specific keyword
EXEC sp_rds_read_error_logs <n>, 1, 'error';SQL Server 2017 or later
Call the sp_readerrorlog stored procedure.
EXEC sp_readerrorlog;For the full parameter reference, see the Microsoft documentation.
Clean up error logs
Cleaning up error logs removes log files from the instance to free disk space. Error logs already uploaded to an Object Storage Service (OSS) bucket remain accessible in the console after cleanup.
SQL Server 2008 R2 instances do not support this operation.
Go to the Instances page. In the top navigation bar, select the region where your instance resides, then click the instance ID.
In the left-side navigation pane, click Logs.
On the Error Logs tab, click Clean Disk Space Occupied by Error Logs.
Click OK.
After cleanup, check disk usage on the Monitoring and Alerts page. For details, see View storage usage.
To automate cleanup using the API, call ModifyDBInstanceConfig.
View primary/secondary switchover logs
This feature is only available for primary RDS instances running SQL Server 2008 R2 with local disks.
Go to the Instances page. In the top navigation bar, select the region where your instance resides, then click the instance ID.
In the left-side navigation pane, click Service Availability.
In the Primary/Secondary Switching Logs section, select a time range to view the switchover logs generated during that period.

What's next
To understand when automatic primary/secondary switchovers occur and how to trigger one manually, see Switch workloads over between primary and secondary ApsaraDB RDS for SQL Server instances.
To manage transaction logs, see Shrink the transaction logs of an ApsaraDB RDS for SQL Server instance and the PurgeDBInstanceLog API operation.
To download log backup files, see Back up an ApsaraDB RDS for SQL Server instance and Download data backup files and log backup files.