aws rds监控慢sql
In this article, we will review how to migrate database from on-premise SQL Server instance to AWS RDS SQL Server instance using AWS Database migration service. There are different ways to migrate the database to the AWS RDS instance:
在本文中,我们将回顾如何使用AWS Database迁移服务将数据库从本地SQL Server实例迁移到AWS RDS SQL Server实例。 有多种方法可以将数据库迁移到AWS RDS实例:
- AWS Database Migration Service (DMS) AWS数据库迁移服务(DMS)
- Native backups 本机备份
- BCP utility BCP实用程序
- Import and Export wizard 导入和导出向导
AWS数据库迁移服务 (AWS Database Migration Service)
With AWS Database migration service, you can migrate your on-premise SQL Server database to AWS RDS instance with minimal downtime.
借助AWS Database Migration Service,您可以在最少的停机时间内将本地SQL Server数据库迁移到AWS RDS实例。
Source as on-premise: AWS Database migration service supports 2005, 2008, 2008R2, 2012, 2014, and 2016 versions. Web and express editions are not supported.
来源为本地 :AWS数据库迁移服务支持2005、2008、2008R2、2012、2014和2016版本。 不支持Web和Express版本。
Source as RDS instance: AWS Database migration service supports 2008R2, 2012, 2014, and 2016 versions. Enterprise and standard versions are supported.
作为RDS实例来源: AWS数据库迁移服务支持2008R2、2012、2014和2016版本。 支持企业版和标准版。
Step by step to set up database migration service between on-premise instance and AWS RDS SQL Server instance.
逐步设置本地实例和AWS RDS SQL Server实例之间的数据库迁移服务。
创建复制实例 (Creating replication instance)
To use data migration service, we need to create a replication instance which will be used to run migration tasks.
要使用数据迁移服务,我们需要创建一个复制实例,该实例将用于运行迁移任务。
Login to AWS management console, Click on Services and type database migration service. Click on Database migration service.
登录到AWS管理控制台,单击“ 服务”,然后键入数据库迁移服务。 单击数据库迁移服务 。
In the database migration service home page, click on Replication Instances.
在数据库迁移服务主页中,单击“ 复制实例” 。
Click on Create replication instance.
单击创建复制实例 。
On Create replication instance page, enter the name and description of the replication instance. Select the instance class.
在“ 创建复制实例”页面上,输入复制实例的名称和描述。 选择实例类。
Enable multi-AZ if you need high availability and fault-tolerant replicating environment. Enable Publicly accessible if you want to access the replication instance from outside of your VPC network.
如果需要高可用性和容错复制环境,请启用多可用区。 如果要从VPC网络外部访问复制实例,请启用“可公开访问” 。
Configure other options like maintenance and security as per your need and click on Create at the bottom of the page.
根据需要配置其他选项,例如维护和安全性,然后单击页面底部的创建 。
Once the replication instance is created we need to create source(on-premise SQL Server) and destination endpoints(AWS RDS SQL Server).
创建复制实例后,我们需要创建源(本地SQL Server)和目标端点(AWS RDS SQL Server)。
创建端点 (Creating endpoints)
An endpoint has connection information of source and target database systems. AWS DMS uses the information in these endpoints to connect to the source database and migrate data from source to target.
端点具有源数据库系统和目标数据库系统的连接信息。 AWS DMS使用这些终端节点中的信息连接到源数据库,并将数据从源迁移到目标。
Navigate to Database migration service console, Click on Endpoints and click on Create Endpoint.
导航到数据库迁移服务控制台,单击“ 端点” ,然后单击“ 创建端点” 。
On Create endpoint page, select the endpoint type as source endpoint and enter the endpoint identifier.
在“ 创建端点”页面上,选择端点类型作为源端点,然后输入端点标识符。
Now select the source engine as SQL Server and enter the connection details like server name, port number, username, password, and the database name.
现在,选择源引擎作为SQL Server,然后输入连接详细信息,例如服务器名称,端口号,用户名,密码和数据库名称。
Choose SSL mode if you want to encrypt the connection for the endpoint.
如果要加密端点的连接,请选择SSL模式。
Click on Create endpoint at the bottom of the page.
单击页面底部的创建端点 。
Alternatively, you can test the endpoint connection by selecting the VPC and replicating instance. Once you click on Run test endpoint is created with details provided above and an attempt is made to connect to source endpoint. Upon successful connection, the status is reported as successful.
或者,您可以通过选择VPC和复制实例来测试端点连接。 单击运行测试端点后,将创建上面提供的详细信息,并尝试连接到源端点。 连接成功后,状态报告为成功。
After creating source endpoint, we need to create target endpoint.
创建源端点后,我们需要创建目标端点。
Navigate to Database migration service console, Click on Endpoints and click on Create Endpoint. On Create endpoint page, select the endpoint type as target endpoint and enable Select RDS DB Instance option. Select the AWS RDS SQL Server instance to which you want to migrate the on-premise database.
导航到数据库迁移服务控制台,单击“ 端点” ,然后单击“ 创建端点” 。 在“ 创建端点”页面上,选择端点类型作为目标端点,然后启用“ 选择RDS数据库实例”选项。 选择要将本地数据库迁移到的AWS RDS SQL Server实例。
RDS instance connection details are auto-populated. enter the password and database name and test your target endpoint connection which will automatically create an endpoint.
RDS实例连接详细信息将自动填充。 输入密码和数据库名称并测试您的目标端点连接,这将自动创建一个端点。
创建迁移任务 (Creating Migration Tasks)
Migration task will perform all your migration work. To create a migration task, we need to create a replication instance, source, and target endpoints first.
迁移任务将执行您的所有迁移工作。 要创建迁移任务,我们需要首先创建复制实例,源端点和目标端点。
Navigate to DMS Page and click on database migration tasks and click on Create task.
导航到DMS页面,然后单击数据库迁移任务,然后单击创建任务 。
On Create database migration task page enter the task identifier. Select the replication instance, source and target endpoints you created earlier. Select the migration type as per your need and disable “Start task on create”. Below are the different migration types available to migrate the on-premise database to AWS RDS SQL Server instance.
在“ 创建数据库迁移任务”页面上,输入任务标识符。 选择您之前创建的复制实例,源和目标端点。 根据需要选择迁移类型,然后禁用“ 创建时启动任务” 。 以下是可用于将本地数据库迁移到AWS RDS SQL Server实例的不同迁移类型。
- Migrate existing data 迁移现有数据
- Migrate existing data and replicate ongoing changes 迁移现有数据并复制正在进行的更改
- Replicate data changes only 仅复制数据更改
Migrate existing data – If you select migrate existing data, the task will perform one-time migration from source to target endpoint.
迁移现有数据 –如果选择迁移现有数据,则该任务将执行一次从源端点到目标端点的迁移。
Migrate existing data and replicate ongoing changes – this option will load initial data from source to target endpoint and migrate the incremental data changes. To use this option the distribution must be set up on source SQL Server database instance and the database must be in full recovery model.
迁移现有数据并复制正在进行的更改 –此选项将从源将初始数据加载到目标端点并迁移增量数据更改。 若要使用此选项,必须在源SQL Server数据库实例上设置分发,并且数据库必须处于完全恢复模型。
AWS DMS uses transactional replication in the backend to migrate ongoing changes on tables with a primary key. For tables which do not have a primary key, Change Data Capture is used to migrate ongoing changes to target (AWS RDS SQL Server).
AWS DMS在后端使用事务复制来迁移具有主键的表上正在进行的更改。 对于没有主键的表,“更改数据捕获”用于将正在进行的更改迁移到目标(AWS RDS SQL Server)。
Replicate data changes only – This option will not migrate initial data but replicate incremental changes.
仅复制数据更改 –此选项不会迁移初始数据,而是复制增量更改。
In table mapping section, you can specify the selection and transformations rules. Select Guided UI option and click on Add new selection rule.
在表映射部分,您可以指定选择和转换规则。 选择“ 引导式UI”选项,然后单击“ 添加新选择规则”。
Here we can specify which schema can be part of the migration and which one to be ignored during migration.
在这里,我们可以指定哪种模式可以作为迁移的一部分,以及哪种模式在迁移期间将被忽略。
In this case, I want to migrate the existing data and on-going changes of SalesTaxRate table only. So, I created a rule by specifying schema, table name and Include action.
在这种情况下,我只想迁移现有数据和SalesTaxRate表的持续更改。 因此,我通过指定架构,表名称和Include操作创建了一条规则。
You can also filter data that is being replicated from a source endpoint to target endpoint(AWS RDS SQL server) by creating a column filter.
您还可以通过创建列过滤器来过滤从源端点复制到目标端点(AWS RDS SQL服务器)的数据。
Click on Add column filter. Enter the column name, condition, and value. This filter will replicate only rows which match the condition i.e. where name is equal to “Canadian GST”.
单击添加列过滤器 。 输入列名称,条件和值。 此过滤器将仅复制符合条件的行,即名称等于“ Canadian GST”的行。
You can also specify transformation rules if you want to rename destination table or change the table schema. To create transformation rule, under transformation rules, Click on Add new transformation rule. Select the target and schema and specify the action.
如果要重命名目标表或更改表架构,也可以指定转换规则。 要创建转换规则,请在转换规则下单击添加新转换规则 。 选择目标和架构,然后指定操作。
Specify the advanced setting as per your need or set them to default values and click on Create task.
根据需要指定高级设置,或将其设置为默认值,然后单击“ 创建任务” 。
Once the migration task is created you can run an assessment test to identify if the migration task has any unsupported data types. AWS DMS scan your source endpoint for the datatypes and compares with pre-defined datatypes supported by AWS DMS. To create an assessment report, Navigate to Database migration tasks and select the task for which you want to run the assessment test. Click on Actions drop-down and select Assess.
创建迁移任务后,您可以运行评估测试以识别迁移任务是否具有任何不受支持的数据类型。 AWS DMS会在源端点上扫描数据类型,然后与AWS DMS支持的预定义数据类型进行比较。 要创建评估报告,请导航至数据库迁移任务,然后选择要为其运行评估测试的任务。 单击操作下拉菜单,然后选择评估 。
Once the assessment is complete, click on the migration task to see the assessment result.
评估完成后,单击迁移任务以查看评估结果。
Navigate to the AWS DMS console click on Database migration task, select the task and click Actions drop down and select the Restart/Resume to start the task. The status of the task will be changed to Starting.
导航到AWS DMS控制台,单击Database migration task ,选择任务,然后单击Actions下拉菜单,然后选择Restart / Resume以启动任务。 任务的状态将更改为正在启动。
Once the initial load is complete the status will be changed to “Load complete, replication ongoing”.
初始加载完成后,状态将更改为“加载完成,复制正在进行”。
Login to AWS RDS SQL Server instance using SQL Server management studio. Navigate to tables and you can see the table on target is created with “DBO” schema as mentioned in the transformation rules.
使用SQL Server管理工作室登录到AWS RDS SQL Server实例。 导航到表,您可以看到目标表是使用转换规则中提到的“ DBO”模式创建的。
Query the table to see if the data is loaded as per the filter mentioned in the migration task.
查询表以查看是否按照迁移任务中提到的过滤器加载了数据。
You can see only rows with values “Canadian GST” are migrated to target instance.
您只能看到将值“ Canadian GST”的行迁移到目标实例。
To see the statistics of migration task, click on migration task and scroll down to Table Statistics section which shows few stats like the number of inserted rows, the initially loaded rows and total rows in the table.
要查看迁移任务的统计信息,请单击迁移任务,然后向下滚动至“表统计信息”部分,其中显示了一些统计信息,例如插入的行数,表中最初加载的行和总行数。
迁移观察 (Observations from migration)
- Identity property of the column is not copied to the target database 列的标识属性未复制到目标数据库
- Foreign keys are not created on the target database. We must create them manually 未在目标数据库上创建外键。 我们必须手动创建它们
- Constraints are not created on the target database. We must create them manually 不会在目标数据库上创建约束。 我们必须手动创建它们
- Indexes are not copied to the target database 索引未复制到目标数据库
- Stored procedures, views, functions, and triggers must be manually created on the target database 必须在目标数据库上手动创建存储过程,视图,函数和触发器
- Tables with primary key – NVARCHAR(MAX) and VARCHAR(MAX) columns are replicated to the target database 具有主键的表– NVARCHAR(MAX)和VARCHAR(MAX)列被复制到目标数据库
- Tables without a primary key – NVARCHAR(MAX) and VARCHAR(MAX) columns are not replicated to the target database 没有主键的表-NVARCHAR(MAX)和VARCHAR(MAX)列不会复制到目标数据库
- Tables without a primary key- rows exceeding the size of 8000 bytes are not replicated 没有主键行超过8000字节大小的表不会被复制
翻译自: https://www.sqlshack.com/aws-rds-sql-server-migration-using-aws-database-migration-service/
aws rds监控慢sql