Customers are modernizing their mission-critical legacy on-premises IBM Db2 for z/OS databases to Amazon Relational Database Service (Amazon RDS) for PostgreSQL or Amazon Aurora PostgreSQL-Compatible Edition for its scalability, performance, agility, and availability.
You can use the AWS Schema Conversion Tool (AWS SCT) to simplify the schema conversion from Db2 for z/OS to Amazon RDS for PostgreSQL or Amazon Aurora PostgreSQL-Compatible Edition. For details about converting schema objects with the AWS SCT for Db2 z/OS as a source, refer to AWS SCT now supports IBM DB2 for z/OS as a source. After converting the schema objects using the AWS SCT, you can use AWS Database Migration Service (AWS DMS) to migrate data. As the schema migration is a semi-automatic process, it may still need manual conversion sometimes when the objects are not converted fully or when a mismatch of key object features occurs.
In this post, we walk you through how to validate database schema objects migrated from Db2 for z/OS to Amazon RDS for PostgreSQL or Amazon Aurora PostgreSQL-Compatible Edition. A similar validation between Db2 for z/OS to Amazon RDS for MySQL or Amazon Aurora MySQL-Compatible Edition will be covered in another post.
Objects to validate
As best practice you should perform schema validation after you successfully convert your database schema objects from Db2 for z/OS and deploy the converted schema objects in PostgreSQL using the AWS SCT. Post-migration schema validation determines the success factor of the overall migration.
In the following sections, we go through the validation scenarios for each of the following database schema object types in detail to ensure that the number of objects for each object type remains consistent between source and target databases. These validation scenarios do not cover or explore the conversion accuracy of your migration, they validate the migrated database objects directly.
Schemas
Tables
Views
Primary keys
Foreign keys
Indexes
Materialized query tables
User-defined data types
Triggers
Sequences
Procedures
Functions
Schemas
Schemas represent a collection of database objects that serve a related functionality in an application or microservice. You can validate the schemas at the source and target databases using the following SQL queries:
Db2 for z/OS Query
PostgreSQL Query
When you convert your Db2 for z/OS schema, the AWS SCT adds an additional schema (aws_db2zos_ext) to your target database. These schemas implement SQL system functions of the Db2 for z/OS database that are required when writing the converted schema to your Aurora PostgreSQL database. These additional schemas are called the AWS SCT extension pack.
We exclude schemas related to system or catalog tables (SYS%) in Db2 for z/OS and in PostgreSQL (pg_catalog,information_schema, public).
Verify if the number of schemas in the source and target database matches. If any differences are found, look at the AWS SCT logs to identify reasons for failure or create it manually.
Tables
The AWS SCT converts source Db2 for z/OS tables to the equivalent target (PostgreSQL) tables. If required, we can use custom mapping rules to include or exclude specific tables from migration. The following scripts return the counts and detail-level information for all the tables:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Verify the results from the source and target databases. If you see any differences, identify the reason from the AWS SCT or manual logs and rerun the failed statement after fixing the problem.
Views
You can validate the views count converted by the AWS SCT with the following queries on the source and target databases:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Verify the count and details between the source and target using these queries. If any differences are found, identify the cause and fix the differences.
Primary keys
Primary keys allow you to have unique values for columns, which prevents information from being duplicated. This key helps improve the search based on the key values and avoid table scans.
The following queries help you extract the counts and details of primary keys in the source and target databases:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Verify the count and details of the primary keys between the source and target using these queries. If any differences are found, identify the cause through the deployment logs and fix the differences.
Foreign keys
Foreign keys help you maintain referential integrity between tables. These keys should be turned off on the target before performing data migration using AWS DMS full load migration. For more information, see Using a PostgreSQL database as a target for AWS Database Migration Service.
With the following queries, you get the counts and detail-level information about the foreign keys in both the source and target databases. You validate the foreign keys after completing the full load data migration using AWS DMS.
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Indexes
Indexes are the database objects created based on one or more columns of a table. Indexes are used to improve the query performance and ensure uniqueness of data when defined as unique indexes.
Unique indexes
With unique keys, you can maintain the uniqueness of data in the column. With the following queries, you get the counts and detail-level information about the unique keys in both the source and target databases:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Non-unique indexes
Indexes play a key role in improving query performance. Because tuning methodologies differ from database to database, the number of indexes and their types vary between Db2 for z/OS and PostgreSQL databases based on different use cases, so index counts also may differ. The index count may also differ due to the limitation of partitioned tables in PostgreSQL.
Use the following queries:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Verify the count and detail of indexes between the source and target database, and any differences should either be attributed to a known reason or investigated and fixed based on the deployment logs.
Materialized query tables
Materialized query tables from Db2 for z/OS are migrated as materialized views in PostgreSQL. They’re similar to regular views, except that the materialized query tables persist the results in a table-like form. This improves query performance because the data is readily available to be returned. You can use the following queries to compare the objects between source and target:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Verify the count and detail of materialized query tables and materialized views between the source and target database, and any differences should be investigated and fixed based on the deployment logs.
User-defined data types
The AWS SCT migrates custom data types from Db2 for z/OS to PostgreSQL as types. You can use the following queries to compare the objects between source and target:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Verify the count and detail of user-defined types between the source and target databases, and any differences should be investigated and fixed based on the deployment logs.
Triggers
Triggers can help you audit databases, implement a business rule, or implement referential integrity. They can also impact performance based on usage in appropriate areas. The following queries give you the count and details of triggers for both the source and target databases:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
In PostgreSQL, triggers are implemented by defining a trigger function before the trigger itself is created. The trigger function must be declared as a function taking no arguments and returning type trigger. The trigger count between Db2 for z/OS and PostgreSQL could vary because of the way they are implemented in PostgreSQL. Verify the count and detail of triggers between the source and target databases, and any differences should either be attributed to a known reason or investigated and fixed based on the deployment logs.
Sequences
Sequences help you create and increment integer values for columns based on given ranges and order. Unlike identity columns, sequences aren’t associated with specific tables. Applications refer to a sequence object to retrieve its next value. The relationship between sequences and tables is controlled by the application. User applications can reference a sequence object and coordinate the values across multiple rows and tables.
The following queries help you get the counts and detail-level information of sequences available in the source and target databases:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Verify the count and details of sequences between source and target, but it’s also important that you set the sequence to the correct values after migration. Setting the sequence is important because after sequences are migrated from the source to target database, they start with the minvalue of the sequence and can cause duplicate key errors during insert and update statements.
Procedures
Db2 for z/OS standard stored procedures encapsulate business logic and run related DDL or DML operations in a single unit of work. In PostgreSQL, we use functions over stored procedures, owing to the limitations of procedures. In those scenarios the source Db2 procedures count also gets added to the function count. In both the source and target databases, the following queries provide counts and detail-level information about the procedures:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Functions
In Db2 for z/OS, SQL functions implement specific business or functional logic on input parameters and return certain types of predefined output. In PostgreSQL, because functions are the preferred choice to implement business and functional logic, their count is usually higher than Db2 for z/OS. In both the source and target databases, the following queries provide counts and detail-level information about the functions:
Db2 for z/OS Query
PostgreSQL Query
For detail-level information, use the following queries:
Db2 for z/OS Query
PostgreSQL Query
Useful PostgreSQL catalog tables
The following table summarizes some helpful Db2 for z/OS and their corresponding PostgreSQL system and catalog tables and views. These tables and views contain metadata with respect to various objects present in the database and are used for database object validation.
Db2 for z/OS
PostgreSQL
Use Case
sysibm.systables/ sysibm.syscolumns
pg_tables
/information_schema.tables
Look for various table properties
sysibm.systables/ sysibm.syscolumns
Pg_views/information_schema.views
Look for different properties of views
sysibm.sysindexes/ sysibm.syskeys
pg_indexes/pg_index
Gather details about indexes
sysibm.sysroutines
pg_proc
Gather details about procedures, functions, and trigger functions
sysibm.systriggers
information_schema.triggers
Gather details about triggers
sysibm.syssequences
pg_sequence/information_schema.sequences
Gather details about sequence, and identity or serial columns
sysibm.systables
pg_matviews
Find more details about materialized views
sysibm.sysdatatypes
pg_type
Gather more information about custom data types
Handling objects not supported in PostgreSQL
You must manually perform migration of Db2 for z/OS objects not supported by PostgreSQL. These will need to be implemented differently than in DB2 for z/OS to emulate the same function as source. So manual validation would be required to be performed on such objects.
Conclusion
In this post, we discussed validation of database objects with metadata queries for Db2 for z/OS and Aurora PostgreSQL-Compatible Edition or RDS for PostgreSQL databases. Database object validation is an essential step that provides an in-depth view into migration accuracy and confirms whether all database objects are migrated appropriately. The database validation phase confirms the integrity of the target database and ensures a smoother transition for the integration of the dependent application processes.
Database migration should always be followed by unit testing, functional testing, and regression testing for all the objects irrespective of automatic or manual migration as this assures that all migrated objects confirm to standards and are working as intended. This saves a lot of reworks when you conduct integration testing with your applications.
Let us know if you have any comments or questions. We value your feedback!
About the Authors
Sai Parthasaradhi is a Database Migration Specialist with AWS Professional Services. He works closely with customers to help them migrate and modernize their databases on AWS.
Vikas Gupta is a Lead Database Migration Consultant with AWS Professional Services. He loves to automate manual processes and enhance the user experience. He helps customers migrate and modernize workloads in the AWS Cloud, with a special focus on modern application architectures and development best practices.
Pavithra Balasubramanian is a Database Consultant with Amazon Web Services in India. She is passionate about helping customers in their cloud adoption journey with a focus on legacy database migrations to the AWS Cloud.
Read MoreAWS Database Blog