Oracle To Azure Database For PostgreSQL Migration Cookbook
Oracle To Azure Database For PostgreSQL Migration Cookbook
Prepared by
Microsoft has provided generic high-level guidance in this document with the understanding that
MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, WITH RESPECT TO THE
INFORMATION CONTAINED HEREIN.
This document is provided “as-is”. Information and views expressed in this document, including URL and
other Internet Web site references, may change without notice.
Some examples depicted herein are provided for illustration only and are fictitious. No real association or
connection is intended or should be inferred.
This document does not provide you with any legal rights to any intellectual property in any Microsoft
product. You may copy and use this document for your internal, reference purposes.
Note: The detail provided in this document has been harvested as part of a customer engagement
sponsored through the Data SQL Ninja Engineering.
4 Migration Recommendations......................................................................................................... 10
5 References ............................................................................................................................................. 11
Replacing an Oracle database backend with an Azure Database for PostgreSQL backend is a simple exercise
that can be executed using the following steps:
Discover: Customers discover all the databases they own, instances hosting them, source database type
and version, other database metadata, etc.
Assess: In this phase, the goal is to identify which Azure database target a customer can migrate their
database to and how much work is involved.
1. Target and SKU recommendation – Identifies which Azure database target and SKU is right
for a database.
2. Readiness assessment – Compares the features used on the source vs the target and give
an overview of work involved in migrating a database to Azure.
Convert: Convert the schema from the source database type to target database type. This phase is valid
only for heterogenous migrations.
Migrate: Migrating a database involves migrating schema, data and objects usually in that order. There are
2 types of database migration methods:
1. Offline migrations – In this method, customers plan a downtime for the database, mark it
read-only, perform the migration and switch over their applications to the new database.
Validate: After the migration is complete, it is important to ensure that target database has the same
schema, data and objects as source database. Also, it is important to validate if applications using the
database behaves the same way on both source and target databases.
After provisioning the VM and Azure Database for PostgreSQL, two configurations are needed for enabling
connectivity between them: “Allow Azure Services” and “Enforce SSL Connection”, depicted as follow:
Download the copy of the inventory script from DataMigrationTeam GitHub repository by visiting this url.
Download the related scripts from the ora2pg website or alternatively, if you are using ora2pg v20, you
can download a sample configuration file from our GitHub Repo. This cookbook is prepared targeting
ora2pg v20.
Guide to install ora2pg using script on Windows and Linux is available on Data Migration Team GitHub
repository. Please refer to reference section for download url. Please note that the script used to install
ora2pg on Windows and Linux is installs the latest version of ora2pg, however, this cookbook is prepared
targeting ora2pg v20.
Estimating the cost of a migration process from Oracle to PostgreSQL is not easy. To obtain a good
assessment of this migration cost, Ora2Pg will inspect all database objects, all functions and stored
procedures to detect if there's still some objects and PL/SQL code that cannot be automatically converted
by Ora2Pg.
Ora2Pg has a content analysis mode that inspect the Oracle database to generate a text report on what the
Oracle database contains and what cannot be exported.
To activate the "analysis and report" mode, use the export de type SHOW_REPORT like in the following
command:
ora2pg -t SHOW_REPORT
To estimate the migration cost in man-days, Ora2Pg allow you to use a configuration directive called
ESTIMATE_COST that you can also enabled at command line:
The default migration unit represent around five minutes for a PostgreSQL expert. If this is your first
migration you can get it higher with the configuration directive COST_UNIT_VALUE or the --cost_unit_value
command line option:
The last line of the report shows the total estimated migration code in man-days following the number of
migration units estimated for each object. This migration unit represent around five minutes for a
PostgreSQL expert. If this is your first migration you can get it higher with the configuration directive
COST_UNIT_VALUE or the --cost_unit_value command line option. Find below some variations of
assessment a) tables assessment; b) columns assessment c) schema assessment using default cost_unit (5
min) d) schema assessment using 10 min as cost unit. Run the following command to generate the report
and estimates. Update the path to your configuration file path as needed.
ora2pg -c /etc/ora2pg/ora2pg.conf
Migration levels:
Technical levels:
4 = manual: no stored functions but with triggers or views with code rewriting
The assessment consists in a letter A or B to specify whether the migration needs manual rewriting or not,
and a number from 1 to 5 to indicate the technical difficulty level. You have an additional option --
human_days_limit to specify the number of human-days limit where the migration level should be set to C
to indicate that it need a huge amount of work and a full project management with migration support.
Default is 10 human-days. You can use the configuration directive HUMAN_DAYS_LIMIT to change this
default value permanently.
The process of understanding which elements need manual intervention consists in compiling the files
generated by ora2pg against the PostgreSQL database, checking the log and making the necessary changes
until all the schema structure is compatible with PostgreSQL syntax.
During the compilation of files, check the logs and correct the necessary syntaxes that ora2pg was unable
to convert out of the box.
You can either edit the default configuration file /etc/ora2pg/ora2pg.conf (the one you have created during
the installation phase) or you can create your own file (Refer to section 3.1). The default
file /etc/ora2pg/ora2pg.conf will be used by ora2pg unless you specify a different one. When updating the
configuration file, please keep in mind Oracle have many modules installed which may not be useful, so to
make sure that these unwanted modules are not extracted from your oracle instance, please find this section
in the configuration file and update as required.
# system users:
# Other list of users set to this directive will be added to this list.
1. Find the following four Oracle related parameters and change them accordingly:
ORACLE_HOME /u01/app/oracle/product/12.1/dbhome_1
ORACLE_DSN dbi:Oracle:host=localhost;sid=xe;port=1521
ORACLE_USER system
ORACLE_PWD oracle
DISABLE_SEQUENCE 1
DISABLE_TRIGGERS USER
TRUNCATE_TABLE 1
DROP_FKEY 1
At this point, all that is required is to execute the psql import commands, pointing to the files containing
the modified code in order to compile the database objects against the PostgreSQL database and import
the data.
In this step, some level of parallelism on importing the data can be implemented. Use the following
command to import DDL to PostgreSQL.
You can also use ora2pg to migrate your data from source Oracle to destination PostgreSQL using following
command
As of May 2019, if you want to perform an online migration, consider using Attunity Replicate for Microsoft
Migrations or Striim.
For “delta/incremental” migration using ora2pg, the technique consists in applying for each table a query
that applies a filter (cut) by date or time, etc., and after that finalizing the migration applying a second query
which will migrate the rest of the data (leftover). Refer to section 3.5.
In the source data table, migrate all the historical data first. An example of that is:
You can query the changes made since the initial migration by running a command similar to the following:
In this case it is recommended that the validation is enhanced by checking data parity on both sides, source
and target.
For online migrations, with Azure Data Migration Services you can migrate your oracle databases hosted
on-premises or on a virtual machine to Azure Database for PostgreSQL. It enables resilient migrations of
Oracle databases at scale and with high reliability. Provision an instance of Database Migration Service from
the Azure portal or via Azure PowerShell and create a migration project to perform the migration.
Ideally, if source and target databases have a networking path, ora2pg can should be used for data
validation. Using the type of action called TEST allows to check that all objects from Oracle database have
been created under PostgreSQL. The command run as following:
BEGIN
DBMS_STATS.GATHER_SCHEMA_STATS
DBMS_STATS.GATHER_DATABASE_STATS
DBMS_STATS.GATHER_DICTIONARY_STATS
END;
https://ora2pg.darold.net/documentation.html
https://datamigration.microsoft.com/
https://www.postgresql.org/
https://www.striim.com/
https://www.attunity.com/
http://blog.dalibo.com/2016/08/19/Autonoumous_transactions_support_in_PostgreSQL.html
https://docs.microsoft.com/en-us/azure/dms/tutorial-oracle-azure-postgresql-online
https://github.com/microsoft/DataMigrationTeam