AWS Database Blog

Migrate your Sybase ASE database to Amazon RDS for SQL Server in near-real time

Customers running their business-critical workloads on SAP Adaptive Server Enterprise (Sybase ASE) databases can modernize them by migrating to Amazon Relational Database Service (Amazon RDS) for SQL Server and be able to keep Transact-SQL (T-SQL) as their preferred database programming language and Tabular Data Stream (TDS) as their communication protocol, which accelerates the migration and helps reduce costs. Amazon RDS for SQL Server makes it simple to set up and operate SQL Server deployments in the cloud by managing time-consuming database administration tasks, including provisioning, backups, software patching, monitoring, and hardware scaling.

In the post Migrate your SAP ASE (Sybase ASE) database to Amazon RDS for SQL Server, I presented a solution to migrate your Sybase ASE database schema and data to Amazon RDS for SQL Server using SQL Server Migration Assistant (SSMA) for Sybase, which is a free tool from Microsoft.

As of this writing, SSMA for Sybase supports one-time migration of the data and doesn’t support continuous replication.

Customers with business-critical applications and stringent Recovery Time Objective (RTO) requirements can’t afford long outages often required by the SSMA tool for large databases. Our customers have asked how to migrate their large databases in near-real time.

In this post, we examine a use case in which you migrate your Sybase ASE database schema using SSMA for Sybase and data to Amazon RDS for SQL Server using AWS Database Migration Service (AWS DMS) in near-real time.

Solution overview

The SSMA and AWS DMS-based migration solution has the following major components:

The following diagram illustrates the solution architecture.

For our use case, our Sybase ASE database is running on Amazon EC2, and we continuously replicate data from Sybase ASE to Amazon RDS for SQL Server using AWS DMS. The following diagram illustrates our architecture.

This solution has the following characteristics:

  • Sybase ASE is installed and configured to run on an Amazon EC2 server, which we refer to as the source database
  • An AWS DMS replication instance is created, which we refer to as the replication instance
  • Amazon RDS for SQL Server is our target database

To perform the full load and set up continuous replication from Sybase ASE to Amazon RDS for SQL Server, you must complete the following high-level steps:

  1. Check Replication Agent configuration
  2. Optionally, disable the RepAgent thread
  3. Establish a Log Transfer Manager (LTM) truncation point
  4. Enable replication
  5. Create a replication instance
  6. Create a source endpoint
  7. Create a target endpoint
  8. Create a database migration task
  9. Start the migration task

Prerequisites

To test this scenario, you must have the following prerequisites:

Check Replication Agent configuration

Find out if your database is configured to use Replication Agent by running the following command:

exec sp_config_rep_agent

If your database isn’t configured to use Replication Agent, you can skip to the Establish an LTM truncation point step.

(Optional) Disable the RepAgent thread

Disabling the RepAgent thread allows the Mirror Replication Agent to reserve the logscan context in the primary database. Complete the following steps:

  1. Connect to the Sybase ASE server, open a new query window, and run the following command to stop the RepAgent thread:
    use pubs2
    exec sp_stop_rep_agent pubs2
  2. To disable the RepAgent thread in the source database, run the following command:
    sp_config_rep_agent pubs2, 'disable', 'preserve secondary truncpt'

Establish an LTM truncation point

To establish an LTM truncation point, connect to the Sybase ASE server, open a new query window, and run the following command:

dbcc settrunc('ltm', 'valid')

Enable replication

To enable replication, complete the following steps:

  1. To display the replication status for all the tables in the source database, run the following command:
    sp_setreptable
  2. To enable replication on all the tables in the source database, run the output of the following command:
    select 'sp_setreptable ' + name + ', ''true''' + ';'
         from sysobjects o where type = 'U' order by name;

    For example:

    sp_setreptable au_pix, 'true';
    sp_setreptable authors, 'true';
    sp_setreptable blurbs, 'true';
    sp_setreptable discounts, 'true';
    sp_setreptable publishers, 'true';
    sp_setreptable roysched, 'true';
    sp_setreptable sales, 'true';
    sp_setreptable salesdetail, 'true';
    sp_setreptable stores, 'true';
    sp_setreptable titleauthor, 'true';
    sp_setreptable titles, 'true';
  3. To validate replication is enabled, run the following command:
    sp_setreptable

Create a replication instance

To set up continuous replication, create an AWS DMS replication instance following these steps:

  1. On the AWS DMS console, choose Replication instances in the navigation pane.
  2. Choose Create replication instance.
  3. Enter a name and description.
  4. Choose an instance class.
  5. For Engine version, we recommend choosing the latest AWS DMS engine version.
  6. The default setting for Allocated storage is 50 GB; you can change it as needed.
  7. For VPC, choose your VPC.
  8. For Multi AZ, choose between a production workload (Multi-AZ) and dev or test workload (Single-AZ) setup based on your requirement.
  9. Review the settings for Advanced security and network configuration, Maintenance, and Tags.
  10. Choose Create.

Create a source endpoint

Next, you need to create the source endpoint and test the connection using the replication instance you created in the previous step.

  1. On the AWS DMS console, choose Endpoints in the navigation pane.
  2. Choose Create endpoint.
  3. For Endpoint type, choose Source endpoint.
  4. For Endpoint identifier, enter a name for your endpoint.
  5. For Source engine, choose SAP Sybase ASE.
  6. For Access to endpoint database options, select Provide access information manually.
  7. For Server name, enter the source database server name.
  8. Enter the port, user name, password, and database name for the source database server.
  9. Choose Create endpoint.

  10. After you create the endpoint, select it and on the Actions menu, choose Test Connection to make sure it’s successful.

Create a target endpoint

Next, you create the target endpoint and test the connection using the replication instance you created in the previous step.

  1. On the AWS DMS console, choose Endpoints in the navigation pane.
  2. Choose Create endpoint.
  3. For Endpoint type, select Target endpoint.
  4. Select RDS DB instance and choose the RDS for SQL Server instance.
  5. For Endpoint identifier, enter a name for your endpoint.
  6. For Target engine, choose Microsoft SQL Server.
  7. For Access to endpoint database, select Provide access information manually or AWS Secrets Manager depending on your preference.
  8. For Server name, enter the target database server name.
  9. Enter the port, user name, password, and database name for the target database server.
  10. Choose Create endpoint.

  11. After you create the endpoint, select it, and on the Actions menu, choose Test Connection to make sure it’s successful.

Create a database migration task

To create the database migration task using the replication instance and source and target endpoints, complete the following steps:

  1. On the AWS DMS console, choose Database migration tasks in the navigation pane.
  2. Choose Create task.
  3. For Task identifier, enter a unique name.
  4. Choose your replication instance, source database endpoint, and target database endpoint.
  5. For Migration type, choose Migrate existing data and replicate ongoing changes.

  6. For Target table preparation mode, select Do nothing.
  7. For Stop task after full load completes, select Don’t stop.
  8. For Include LOB columns in replication, select Limited LOB mode.
    Find out the maximum LOB size (KB) using the Best practices section later in this post.

  9. Skip the Enable validation option because it’s not supported (as of this writing) for the Sybase endpoint.
  10. Select Enable CloudWatch logs to gain insights during the migration process from Amazon CloudWatch.
  11. Review the Advanced task settings options and enter values as needed.
  12. In the Table mappings section, under Selection rule, choose Add new selection rule.
  13. Enter % for Schema name and Table name to include all the schemas and tables from the source database.
  14. For Start migration task, select Manually later.
  15. Choose Create task.

Start the migration task

Before you start the migration task, make sure you have disabled the foreign key constraints and triggers at the target database migrated using SSMA for Sybase.

For a database with a large number of triggers, you can run the output of the following commands from SQL Server Management Studio (SSMS):

use pubs2
go
select 'DISABLE TRIGGER ' + name + ' ON ' + object_name(parent_id) + ';' from sys.triggers

For a database with a large number of foreign keys, you can run the output of the following commands from SSMS:

use pubs2
go
SELECT 'ALTER TABLE ' + sc.name + '.' + o.name +
' NOCHECK CONSTRAINT ' + fk.name
FROM sys.foreign_keys AS fk
INNER JOIN sys.objects AS o ON fk.parent_object_id = o.object_id
inner join sys.schemas sc ON sc.schema_id = o.schema_id

To start the migration task, complete the following steps:

  1. On the AWS DMS console, choose Database migration tasks in the navigation pane.
  2. Select the task you created.
  3. On the Actions menu, choose Restart/Resume.

Validate the migration

To validate the schema migration, follow the instructions in Testing Migrated Database Objects (SybaseToSQL).

  1. On the AWS DMS console, choose Database migration tasks in the navigation pane.
  2. Choose the database migration task.
  3. On the Table statistics tab, review the Full load rows, Inserts, Updates, and Deletes columns.
  4. To view the CloudWatch logs, choose View logs.
  5. On the CloudWatch Logs console, you can download the logs in CSV format from the Actions menu.

Perform the cutover

To complete the cutover, follow these steps:

  1. Find and download the latest Microsoft ODBC and Microsoft JDBC drivers to use in the application.
  2. Find an approved outage window for the application and stop the application.
  3. Verify the target database is in sync with the source database.
  4. On the AWS DMS console, choose Database migration tasks in the navigation pane.
  5. Select the migration task and on the Actions menu, choose Stop.
  6. Enable the triggers at the target database.For a database with a large number of triggers, you can run the output of the following commands from SSMS:
    use pubs2
    go
    select 'ENABLE TRIGGER ' + name + ' ON ' + object_name(parent_id) + ';' from sys.triggers
  7. Enable the foreign keys at the target database.
    For a database with a large number of foreign keys, you can run the output of the following commands from SSMS:

    use pubs2
    go
    SELECT 'ALTER TABLE ' + sc.name + '.' + o.name +
    ' WITH CHECK CHECK CONSTRAINT ' + fk.name
    FROM sys.foreign_keys AS fk
    INNER JOIN sys.objects AS o ON fk.parent_object_id = o.object_id
    inner join sys.schemas sc ON sc.schema_id = o.schema_id
  8. Deploy application changes related to this migration.
  9. Start the application.

Best practices

The following best practices are recommended:

  • Create the AWS DMS replication instance in the same AWS Region and Availability Zone as Amazon RDS for SQL Server to have minimum network latency between them.
  • Right-size the AWS DMS replication instance in terms of CPU, memory, and storage based on your database size and data types in the database.
  • Consider changing the default values via the AWS DMS Database migration tasks page when creating the task to optimize the full load.
  • Identify the tables with LOB data to improve the speed of an AWS DMS task using the following code:
    select 	o.name as table_name, 
    		c.name as column_name,
    		t.name as data_type 
    		
    from sysobjects o
    inner join syscolumns c 
    on o.id=c.id 
    inner join systypes t
    on t.type = c.type
    where o.type='U' 
    and c.type in (34,35,174);
  • Identify the maximum LOB size by running the output of the following code:
    select 	'select max(datalength(',c.name, ')) from dbo.', o.name,';'
    from   	sysobjects o,
                syscolumns c
    where  o.type = 'U' and    
    o.id = c.id
    and    c.type in (34,35,174);
  • Identify large tables using the following code:
    select top 10 convert(varchar(30),o.name) AS table_name,
      row_count(db_id(), o.id) AS row_count,
      data_pages(db_id(), o.id, 0) AS pages,
      data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs
    from 	sysobjects o
    where type = 'U'
    order by kbs DESC, table_name ASC;
  • Choose the right Amazon RDS for SQL Server collation by identifying the character set of the source Sybase ASE database using the following code:
    exec sp_default_charset

Clean up

To remove all the components created by this solution and avoid future charges, complete the following steps:

  1. Sign in to the AWS Management Console
  2. Choose the Region where your EC2 instance, RDS for SQL Server instance, and AWS DMS replication instance reside
  3. On the Amazon RDS console, choose Databases
  4. Select the RDS for SQL Server instance and on the Actions menu, choose Delete
  5. On the Amazon EC2 console, choose Instances
  6. Select the EC2 instances used as source data and SSMA host
  7. On the Instance state menu, choose Terminate instance
  8. On the AWS DMS console, choose Database migration tasks
  9. Select the migration task and on the Actions menu, choose Stop
  10. Wait for the task to stop, then choose Delete
  11. On the AWS DMS console, choose Endpoints
  12. Select the source and target endpoints and on the Actions menu, choose Delete
  13. On the AWS DMS console, choose Replication instances
  14. Select the replication instance and on the Actions menu, choose Delete

Limitations

This solution has the following limitations:

Summary

In this post, we demonstrated how to create an AWS DMS replication instance, endpoints, and database migration tasks followed by data migration (continuous replication) from Sybase ASE to Amazon RDS for SQL Server using AWS DMS. Try out Amazon RDS for SQL Server and migrate your Sybase ASE database workload to AWS in near-real time.

If you have any comments or feedback, leave them in the comments section.


About the author

Rajib Sadhu is Senior Database Specialist Solutions Architect with over 15 years of experience in Microsoft SQL Server and other database technologies. He helps customers architect and migrate their database solutions to AWS. Prior to joining AWS, he supported production and mission-critical database implementation across the financial and travel and hospitality industry segments.