Amazon RDS SQL Server: Get Instance Size Using TSQL

You can obviously retrieve an Amazon RDS SQL Server’s instance type (size) from the AWS portal, but I wanted to get it using TSQL:

IF OBJECT_ID('tempdb..#AmazonErrorLog') IS NOT NULL
    DROP TABLE #AmazonErrorLog;
 
CREATE TABLE #AmazonErrorLog
(
    LogDate DATETIME,
    ProcessInfo NVARCHAR(20),
    [Text] NVARCHAR(1000)
);
 
DECLARE @pattern nvarchar(30) = N'System Model:';
 
INSERT INTO #AmazonErrorLog
EXEC rdsadmin.dbo.rds_read_error_log;
 
IF @@ROWCOUNT > 0
BEGIN
    SELECT InstanceSize = CAST(REPLACE(SUBSTRING(Text, LEN(@pattern) + 1 + PATINDEX (N'%' + @pattern + N'%', Text), 100), '''', '') AS varchar(100))
    FROM #AmazonErrorLog
    WHERE PATINDEX (N'%' + @pattern + N'%', Text) > 0 
END
 
DROP TABLE #AmazonErrorLog;

3 thoughts on “Amazon RDS SQL Server: Get Instance Size Using TSQL”

  1. I was curious so I tried this, however I had to switch the REPLACE and CAST positions to get it to work.
    Also, AWS may have changed what they’re providing for metadata strings. On an example SQL 2016 Std RDS instance, I only received “HVM domU” as the System Model. Maybe this is different for other SQL versions and/or instance sizes. The example above is a db.r4.large from the console.

  2. The full string is:
    “System Manufacturer: ‘Xen’, System Model: ‘HVM domU’.”

    I couldn’t find any other lines in the errorlog that mentioned the instance size 🙁

Comments are closed.