Migrate virtual generated columns from Oracle to PostgreSQL
Created by Veeranjaneyulu Grandhi (AWS), Rajesh Madiwale (AWS), and Ramesh Pathuri (AWS)
Environment: Production | Source: Oracle Database | Target: Amazon RDS for PostgreSQL or Aurora PostgreSQL-Compatible |
R Type: Re-architect | Workload: Oracle | Technologies: Migration; Databases |
AWS services: Amazon Aurora; Amazon RDS; AWS DMS |
Summary
In version 11 and earlier, PostgreSQL doesn’t provide a feature that is directly equivalent to an Oracle virtual column. Handling virtual generated columns while migrating from Oracle Database to PostgreSQL version 11 or earlier is difficult for two reasons:
Virtual columns aren’t visible during migration.
PostgreSQL doesn't support the
generate
expression before version 12.
However, there are workarounds to emulate similar functionality. When you use AWS Database Migration Service (AWS DMS) to migrate data from Oracle Database to PostgreSQL version 11 and earlier, you can use trigger functions to populate the values in virtual generated columns. This pattern provides examples of Oracle Database and PostgreSQL code that you can use for this purpose. On AWS, you can use Amazon Relational Database Service (Amazon RDS) for PostgreSQL or Amazon Aurora PostgreSQL-Compatible Edition for your PostgreSQL database.
Starting with PostgreSQL version 12, generated columns are supported. Generated columns can either be calculated from other column values on the fly, or calculated and stored. PostgreSQL generated columns
Prerequisites and limitations
Prerequisites
An active AWS account
A source Oracle database
Target PostgreSQL databases (on Amazon RDS for PostgreSQL or Aurora PostgreSQL-Compatible)
PL/pgSQL
coding expertise
Limitations
Applies only to PostgreSQL versions before version 12.
Applies to Oracle Database version 11g or later.
Virtual columns are not supported in data migration tools.
Applies only to columns defined in the same table.
If a virtual generated column refers to a deterministic user-defined function, it cannot be used as a partitioning key column.
The output of the expression must be a scalar value. It cannot return an Oracle supplied datatype, a user-defined type,
LOB
, orLONG RAW
.Indexes that are defined against virtual columns are equivalent to function-based indexes in PostgreSQL.
Table statistics must be gathered.
Tools
pgAdmin 4
is an open source management tool for PostgreSQL. This tool provides a graphical interface that simplifies the creation, maintenance, and use of database objects. Oracle SQL Developer
is a free, integrated development environment for working with SQL in Oracle databases in both traditional and cloud deployments.
Epics
Task | Description | Skills required |
---|---|---|
Create a source Oracle Database table. | In Oracle Database, create a table with virtual generated columns by using the following statement.
In this source table, the data in the | DBA, App developer |
Create a target PostgreSQL table on AWS. | Create a PostgreSQL table on AWS by using the following statement.
In this table, the | DBA, App developer |
Task | Description | Skills required |
---|---|---|
Create a PostgreSQL trigger. | In PostgreSQL, create a trigger.
| DBA, App developer |
Create a PostgreSQL trigger function. | In PostgreSQL, create a function for the trigger. This function populates a virtual column that is inserted or updated by the application or AWS DMS, and validates the data.
| DBA, App developer |
Task | Description | Skills required |
---|---|---|
Create a replication instance. | To create a replication instance, follow the instructions in the AWS DMS documentation. The replication instance should be in the same virtual private cloud (VPC) as your source and target databases. | DBA, App developer |
Create source and target endpoints. | To create the endpoints, follow the instructions in the AWS DMS documentation. | DBA, App developer |
Test the endpoint connections. | You can test the endpoint connections by specifying the VPC and replication instance and choosing Run test. | DBA, App developer |
Create and start a full load task. | For instructions, see Creating a Task and Full-load task settings in the AWS DMS documentation. | DBA, App developer |
Validate the data for the virtual column. | Compare the data in the virtual column in the source and target databases. You can validate the data manually or write a script for this step. | DBA, App developer |
Related resources
Getting started with AWS Database Migration Service (AWS DMS documentation)
Using an Oracle database as a source for AWS DMS (AWS DMS documentation)
Using a PostgreSQL database as a target for AWS DMS (AWS DMS documentation)
Generated columns in PostgreSQL
(PostgreSQL documentation) Trigger functions
(PostgreSQL documentation) Virtual columns
in Oracle Database (Oracle documentation)