aws rds监控慢sql
In the first part of the article, Explore SQL Server Integration Services (SSIS) on AWS RDS SQL Server, we understood that AWS RDS SQL Server supports SSIS functionality starting from May 19th, 2020.
在本文的第一部分, 探索AWS RDS SQL Server上SQL Server集成服务(SSIS) ,我们了解到AWS RDS SQL Server从2020年5月19 日开始支持SSIS功能。
In this article, we will create, deploy, and schedule SSIS packages using SQL Server Agent jobs. You should configure your environment with prerequisites and steps mentioned in the first article specified above.
在本文中,我们将使用SQL Server代理作业创建,部署和安排SSIS包。 您应该使用上面指定的第一篇文章中提到的先决条件和步骤来配置环境。
We use Visual Studio 2019 SQL Server data tools to create an integration service project. Once we installed visual studio 2019 using Download SQL Server Data Tools (SSDT) for Visual Studio, we need to enable the integration service extension.
我们使用Visual Studio 2019 SQL Server数据工具来创建集成服务项目。 一旦我们使用以下方法安装了Visual Studio 2019 下载适用于Visual StudioSQL Server数据工具(SSDT) ,我们需要启用集成服务扩展。
You should install it in the Amazon EC2 Windows instance. I have the following EC2 instance, and it is a member of the [SqlshackDemo] domain. It is the same domain that we used in the RDS instance.
您应该将其安装在Amazon EC2 Windows实例中。 我有以下EC2实例,它是[SqlshackDemo]域的成员。 它与我们在RDS实例中使用的域相同。
Open any project in Visual Studio and go to Extensions > Manage Extension from the menu bar. It opens the following market place to download extensions. Search for the SQL Server Integration Service Projects and download it.
在Visual Studio中打开任何项目,然后从菜单栏中转到“ 扩展”>“管理扩展 ”。 它为下载扩展程序打开了以下市场。 搜索“ SQL Server集成服务项目”并下载。
Launch the setup and select the language of the installer. By default, it chooses system language. You can change it if required.
启动安装程序,然后选择安装程序的语言。 默认情况下,它选择系统语言。 您可以根据需要进行更改。
Click Ok, and it starts the integration service project installation in the Visual Studio.
单击“确定”,它开始在Visual Studio中安装Integration Service项目。
We have already installed Visual Studio 2019, so it integrates the integration service package with it. In case you have multiple versions, you can choose the required version.
我们已经安装了Visual Studio 2019,因此它与集成服务包集成在一起。 如果您有多个版本,则可以选择所需的版本。
As we can see below, SQL Server Integration Services Projects version 3.7 in the Visual Studio 2019 on Amazon EC2 instance.
如下所示,在Amazon EC2实例上的Visual Studio 2019中,SQL Server Integration Services项目版本3.7。
Launch Visual Studio in the EC2 instance, create a new project and select the category – Integration Service Project.
在EC2实例中启动Visual Studio,创建一个新项目,然后选择类别– Integration Service Project。
For configuration, specify the project name and location. I give the project name – SSISforRDS.
要进行配置,请指定项目名称和位置。 我给项目名称– SSISforRDS 。
It opens the following SSIS project. You can see the SSIS toolbox in the left and SSIS packages along with its parts like control flow in the solution explorer ( right-side).
它将打开以下SSIS项目。 您可以在左侧看到SSIS工具箱,并在解决方案资源管理器(右侧)中看到SSIS包及其控件流等部分。
For this article, my primary intension is to guide you for creating an SSIS project that uses AWS RDS SQL Server integration service. We will create a basic SSIS package here.
对于本文,我的主要意图是指导您创建使用AWS RDS SQL Server集成服务的SSIS项目。 我们将在这里创建一个基本的SSIS包。
My RDS SQL instance holds [AdventureWorksDW2014] database. You can download this sample database from Microsoft docs. You can follow the article Recover Data in AWS RDS SQL Server to restore it on the RDS instance using the S3 bucket.
我的RDS SQL实例拥有[AdventureWorksDW2014]数据库。 您可以从Microsoft docs下载此示例数据库。 您可以按照文章在AWS RDS SQL Server中恢复数据来使用S3存储桶在RDS实例上将其还原。
Create the following stored procedure to select the records from a SQL view.
Create the following stored procedure to select the records from a SQL view.创建以下存储过程以从SQL视图中选择记录。
创建以下存储过程以从SQL视图中选择记录。USE [AdventureWorksDW2014];
GO
CREATE PROCEDURE [TempSP]
AS
BEGIN
SELECT *
FROM [dbo].[vDMPrep];
END;
Now, drag an Execute SQL Task from the SSIS toolbox.
现在,从SSIS工具箱中拖动一个Execute SQL Task 。
Double-click on the execute SQL task to open its configuration editor.
双击execute SQL任务以打开其配置编辑器。
In the authentication, always use Windows authentication. We cannot use SQL authentication for SSIS in the RDS environment.
在身份验证中,请始终使用Windows身份验证。 我们不能在RDS环境中对SSIS使用SQL身份验证。
Click Ok and Specify the SQL statement to execute the stored procedure, we created earlier.
单击确定,然后指定SQL语句以执行我们之前创建的存储过程。
USE [AdventureWorksDW2014];
GO
EXEC [TempSp];
GO
Click Ok. Now, right-click on the SSIS solution and go to its properties. Here, you can see the project creation date, the EC2 instance name, the Windows authenticated user, and the project name.
单击确定。 现在,右键单击SSIS解决方案,然后转到其属性。 在这里,您可以看到项目创建日期,EC2实例名称,Windows身份验证用户和项目名称。
In security, it sets the default protection level as EncryptSensitiveWithUserKey. Change this Protection level to DonotSaveSensitive.
在安全性方面,它将默认保护级别设置为EncryptSensitiveWithUserKey 。 将此保护级别更改为DonotSaveSensitive 。
You get a warning message if you change the package protection level. Click Ok to accept the warning.
如果更改包装保护级别,则会收到警告消息。 单击“确定”接受警告。
We also need to set the same protection level for the SSIS package. Right-click on the control flow area and go to properties. Change the protection level to DonotSaveSensitive, as shown in the below image.
我们还需要为SSIS包设置相同的保护级别。 右键单击控制流区域,然后转到属性。 如下图所示,将保护级别更改为“ DonotSaveSensitive” 。
Save the package and click on Build-> Build Solution.
保存该软件包,然后单击Build-> Build Solution 。
It builds the package for you, and you get the status in the output tab.
它会为您构建软件包,然后在输出选项卡中获取状态。
Browse the SSIS project directory in the EC2 instance. In the Bin-> Development folder, you can find a project file with .ispac Extension similar to the below file.
浏览EC2实例中的SSIS项目目录。 在Bin-> Development文件夹中,您可以找到带有.ispac扩展名的项目文件,类似于下面的文件。
Login to AWS web console and upload this project.ispac file in the S3 bucket that is already integrated with AWS RDS SQL Server.
登录到AWS Web控制台并将此project.ispac文件上传到已与AWS RDS SQL Server集成的S3存储桶中。
To download this file from the S3 bucket to the RDS directory ( D:\S3), we use the RDS stored procedure msdb.dbo.rds_download_from_s3 with the following arguments.
要将文件从S3存储桶下载到RDS目录(D:\ S3),我们将RDS存储过程msdb.dbo.rds_download_from_s3与以下参数一起使用。
You should run this procedure in SSMS connected using Windows authenticated AWS RDS SQL Server.
您应该在使用Windows身份验证的AWS RDS SQL Server连接的SSMS中运行此过程。
EXEC msdb.dbo.rds_download_from_s3
@s3_arn_of_file = 'arn:aws:s3:::sqlshackdemo/SSISforRDS.ispac',
@rds_file_path = 'D:\S3\SSISforRDS.ispac',
@overwrite_file = 1;
It starts a task to execute the stored procedure. Note-down the task id and pass it in the msdb.dbo.rds_fn_task_status to check the status.
它启动一个任务来执行存储过程。 记下任务ID,并将其传递到msdb.dbo.rds_fn_task_status中以检查状态。
SELECT * FROM msdb.dbo.rds_fn_task_status(NULL,26)
It shows success status that means RDS downloaded the ISPAC file in the RDS instance directory.
它显示成功状态,这表示RDS已在RDS实例目录中下载了ISPAC文件。
Before we move further, right-click on the SSISDB catalog and create a folder. In this case, we are connected with the RDS admin user.
在继续之前,请右键单击SSISDB目录并创建一个文件夹。 在这种情况下,我们与RDS管理员用户连接。
You get the following error message. We get this error because the ADMIN user does not have permission to create folders in the SSIS catalog.
您收到以下错误信息。 我们收到此错误,因为ADMIN用户没有在SSIS目录中创建文件夹的权限。
Let’s try the same operation with Windows authenticated users. We create a folder [Sample SSIS project] in the SSISDB catalog.
让我们对Windows身份验证的用户尝试相同的操作。 我们在SSISDB目录中创建一个文件夹[SSIS示例项目] 。
It created the folder, as shown below. We use this folder to deploy the project created earlier.
它创建了文件夹,如下所示。 我们使用此文件夹部署之前创建的项目。
We use the stored procedure msdb.dbo.rds_msdb_task to deploy an SSIS project.
我们使用存储过程msdb.dbo.rds_msdb_task来部署SSIS项目。
EXEC msdb.dbo.rds_msbi_task
@task_type = 'SSIS_DEPLOY_PROJECT',
@file_path = 'd:\S3\SSISforRDS.ispac',
@folder_name = 'Sample SSIS project',
@project_name = 'SSISforRDS';
In the above query, we use the following arguments.
在上面的查询中,我们使用以下参数。
We have deployed a package successfully as it shows the SUCCESS status in the msdb.dbo.rds_fn_task_status.
我们已经成功部署了一个软件包,因为它在msdb.dbo.rds_fn_task_status中显示SUCCESS状态。
SELECT * FROM msdb.dbo.rds_fn_task_status(NULL,29)
Now, refresh the SSMS connection, and you see the deploy SSIS package and project in the integration service project.
现在,刷新SSMS连接,您会在Integration Service项目中看到部署SSIS包和项目。
We can either manually execute the package from the SSISDB catalog or execute it using the SQL job. Right-click on the package and select Execute, as shown below.
我们可以从SSISDB目录中手动执行程序包,也可以使用SQL作业执行程序包。 右键单击该软件包,然后选择Execute ,如下所示。
It opens the following execute package window. You can verify the RDS instance connection and package properties.
它打开以下执行包窗口。 您可以验证RDS实例连接和包属性。
Click Ok, and it starts an operation ID for the package execution.
单击确定,它会为包执行启动一个操作ID。
Click Ok, and it opens the package execution report. Oh! The package failed in execution. It is unable to open the connection to the RDS instance. It is surprising, right! We already connected to RDS using Windows authentication and it works fine, but in the package, it fails to acquire a connection.
单击确定,它将打开程序包执行报告。 哦! 程序包执行失败。 它无法打开与RDS实例的连接。 令人惊讶,对! 我们已经使用Windows身份验证连接到RDS,并且可以正常工作,但是在软件包中,它无法获取连接。
To resolve this error, right-click on the package and select Configure.
要解决此错误,请右键单击该程序包,然后选择Configure 。
In the SSIS package for AWS RDS SQL Server, we need to specify the server name in the following format:
在适用于AWS RDS SQL Server的SSIS软件包中,我们需要以以下格式指定服务器名称:
We have the following connection string in the package that uses the RDS endpoint.
在使用RDS端点的程序包中,我们具有以下连接字符串。
Current Connection String:
当前连接字符串 :
Data Source=ssasinrds.cumznzii9fba.us-east-1.rds.amazonaws.com;Initial Catalog=AdventureWorksDW2014;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;
数据源= ssasinrds.cumznzii9fba.us-east-1.rds.amazonaws.com;初始目录= AdventureWorksDW2014;提供程序= SQLNCLI11.1;集成安全性= SSPI;自动翻译= False;
Replace this connection string that uses the server name in the format specified above.
替换此连接字符串,该字符串使用上述指定格式的服务器名称。
New Connection String
新的连接字符串
New: Data Source=ssasinrds.sqlshackdemo.com;Initial Catalog=AdventureWorksDW2014;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;
新增功能:数据源= ssasinrds.sqlshackdemo.com;初始目录= AdventureWorksDW2014;提供程序= SQLNCLI11.1;集成安全性= SSPI;自动翻译= False;
Click Ok and again open the configuration wizard. Now, replace the server name in the new format.
单击确定,然后再次打开配置向导。 现在,以新格式替换服务器名称。
Once both the changes complete, execute the SSIS package. You can validate the connection string using the new server format.
两项更改完成后,执行SSIS包。 您可以使用新的服务器格式来验证连接字符串。
We can see the package executes successfully after making the change for the RDS instance connection in the new format.
我们可以看到在以新格式对RDS实例连接进行更改之后,包成功执行。
Usually, we set up a SQL Server Agent job to execute the package at a scheduled time. We can set up a SQL agent job for package execution in the AWS RDS SQL Server as well.
通常,我们设置SQL Server代理作业以在计划的时间执行程序包。 我们也可以在AWS RDS SQL Server中设置SQL代理作业以执行包。
It requires setting up a credential and proxy account for job execution.
它需要设置凭证和代理帐户以执行作业。
It uses the CREATE CREDENTIAL command. Specify the Windows user (Identity argument) and password (Secret argument) in the query below.
它使用CREATE CREDENTIAL命令。 在下面的查询中指定Windows用户(Identity参数)和密码(Secret参数)。
USE [master]
GO
CREATE CREDENTIAL [SSIS_Credential_SQL] WITH IDENTITY = N'sqlshackdemo\rajendra.gupta', SECRET = N'India@123'
GO
In this step, we create a proxy with the credential created in the above step. We also need to give permissions to run the integration service package using the msdb.dbo.rds_sqlagent_proxy procedure.
在此步骤中,我们将使用在上一步中创建的凭据创建代理。 我们还需要授予使用msdb.dbo.rds_sqlagent_proxy过程运行集成服务程序包的权限。
USE [msdb];
GO
EXEC msdb.dbo.sp_add_proxy
@proxy_name = N'SSIS_Proxy',
@credential_name = N'SSIS_Credential_SQL',
@description = N'';
EXEC msdb.dbo.sp_grant_login_to_proxy
@proxy_name = N'SSIS_Proxy',
@login_name = N'sqlshackdemo\rajendra.gupta';
EXEC msdb.dbo.rds_sqlagent_proxy
@task_type = 'GRANT_SUBSYSTEM_ACCESS',
@proxy_name = 'SSIS_Proxy',
@proxy_subsystem = 'SSIS';
GO
Expand SQL Server Agent, jobs, and create a new job. In this specify a job name, and you can specify a description as well.
展开SQL Server代理,作业,然后创建一个新作业。 在此指定作业名称,还可以指定描述。
Click on the Steps and add a new job step using the following inputs.
单击步骤,然后使用以下输入添加新的作业步骤。
Click on the eclipse in the package and select the package that we wish to execute.
单击包中的Eclipse,然后选择我们要执行的包。
You can see the job step configuration, as shown below.
您可以看到作业步骤配置,如下所示。
You can create a job schedule as per your requirement.
您可以根据需要创建工作计划。
We can see the SQL agent job to run the package in the AWS RDS SQL Server.
我们可以看到SQL代理作业,以在AWS RDS SQL Server中运行程序包。
Right-click on the job to execute it or wait for its autorun in the scheduled time. We can see below job that holds the integration service package executed successfully
右键单击该作业以执行它,或等待它在计划的时间内自动运行。 我们可以看到以下包含成功执行集成服务包的作业
In the two series article, we explored the configuration of integration services for the AWS RDS SQL Server. We deployed an SSIS project, executed it manually, and using the SQL Server agent job as well. It is a useful enhancement to RDS SQL services, and I would recommend you to explore it.
在这两个系列文章中,我们探索了适用于AWS RDS SQL Server的集成服务的配置。 我们部署了一个SSIS项目,手动执行了该项目,并且还使用了SQL Server代理作业。 它是对RDS SQL服务的有用增强,我建议您对其进行探索。
翻译自: https://www.sqlshack.com/working-with-ssis-packages-on-aws-rds-sql-server/
aws rds监控慢sql