In brief
Migrating from Oracle to PostgreSQL is mostly a rewrite of code inside the database, not a data move. Tools convert tables and data well; most of the work and risk sits in PL/SQL packages, triggers, Oracle-specific SQL and behavioral differences, such as Oracle treating an empty string as NULL while PostgreSQL does not. A safe plan has five stages: inventory, schema and code conversion, data migration with change replication, comparison testing, and cutover with a fallback plan.
Stage 1: inventory and complexity assessment
Before there is a schedule, you need to know what is in the database. A checklist:
- number of schemas, tables, views, sequences and the data volume;
- number and size of PL/SQL packages, procedures, functions and triggers;
- use of Oracle-specific features: `CONNECT BY`, `ROWNUM`, `MERGE`, `DBMS_*`, autonomous transactions, object types, database links;
- the applications that connect to the database, and whether their SQL lives in code, configuration files or an ORM;
- batch jobs, reports, exports and systems that read tables directly.
Conversion tools produce such a report automatically: ora2pg has a migration assessment mode, and AWS DMS Schema Conversion and the AWS Schema Conversion Tool assess complexity and flag objects that need manual fixes. Treat the report as a starting point, because it knows neither the business logic nor which procedures are dead code.
Stage 2: schema and code conversion
The PostgreSQL documentation has a dedicated chapter on porting from PL/SQL to PL/pgSQL. The key differences:
| Area | Oracle | PostgreSQL |
|---|---|---|
| Packages | `PACKAGE` with procedures and variables | no packages; functions are grouped in schemas, session state is kept e.g. in temporary tables |
| Numeric and text types | `NUMBER`, `VARCHAR2` | `numeric` (or `integer`, `bigint`), `varchar` or `text` |
| Dates | `DATE` also stores the time of day | `date` is the date only; the usual equivalent is `timestamp` |
| Empty string | `''` treated as NULL | `''` is a regular string, distinct from NULL |
| `FOR ... REVERSE` loop | counts from the second bound down to the first | counts from the first bound down to the second, so bounds must be swapped |
| Exceptions | e.g. `DUP_VAL_ON_INDEX` | e.g. `unique_violation`, different `RAISE` syntax |
| Autonomous transactions | `PRAGMA AUTONOMOUS_TRANSACTION` | not available; needs a workaround such as writing over a separate connection |
The empty string difference is the most treacherous. Oracle's documentation states plainly that the database treats a character value with a length of zero as null. Code that checks `column IS NULL` stops catching empty strings after migration, and reports start counting differently. You need to decide whether to convert such data to NULL during migration or fix the conditions in code, and capture that decision in tests.
Map `NUMBER` without precision deliberately: keys to `bigint`, amounts to `numeric` with a defined scale. Mapping everything to `numeric` works, but it slows down joins and indexes.
Stage 3: data migration and change replication
For a large database a one-off export in a maintenance window is often not enough. The typical pattern:
- Full load into the new database while the old one keeps running.
- Ongoing change replication (CDC) from Oracle to PostgreSQL until cutover day. AWS DMS supports both modes: one-time migration and replicating ongoing changes to keep source and target in sync.
- A short cutover window: stop writes to the old database, apply the last changes, reconcile the data, switch the application over.
How changes are read from the log is covered in the article on Change Data Capture, and general principles of migrating without downtime in the article on migrating customer data.
Sequences need a separate step: after the data is loaded, set their current values above the highest key in each table, or the first insert after cutover will fail with a uniqueness error.
Stage 4: comparison testing
The migration is done when the results match, not when the code compiles. A test set:
- data reconciliation: row counts and control totals of numeric columns for every table, plus record sample comparisons;
- procedure tests: the same inputs in Oracle and PostgreSQL with compared outputs, paying special attention to rounding, time zones, sorting of text with national characters and empty strings;
- application regression: the full automated test suite on the new database, as described in the article on regression testing;
- performance tests: the PostgreSQL planner chooses different plans than Oracle, and hints from Oracle code do nothing. Queries from key processes need to be checked with an execution plan, as described in the article on SQL query performance.
Data reconciliation testing in a large migration is described in the project on data migration testing for a merger of two banks.
Stage 5: cutover and fallback plan
Before cutover you need a ready answer to the question of what happens if something goes wrong an hour into running on PostgreSQL. Options:
- reverse replication from PostgreSQL back to Oracle for the first days, so a fallback does not lose new transactions;
- incremental cutover: read-only reports and modules first, then modules that write;
- clear rollback criteria: for example a balance reconciliation failure or a key transaction's response time above an agreed threshold.
The risks that most often stretch a project: underestimated PL/SQL code, hidden dependencies (reports reading tables directly, database links), no automated application tests, and third-party tool licenses that only support Oracle. Planning a full move to the cloud, in which changing the database is one step, is covered in the article on cloud migration strategies.
Questions and answers
How long does an Oracle to PostgreSQL migration take?
It depends mainly on the amount of code in the database, not the data volume. A database with plain tables and simple SQL in the application is a matter of weeks. A system with thousands of PL/SQL procedures and dozens of integrations is a project of many months. A reliable estimate only comes from a complexity assessment report and a trial rewrite of a few representative packages.
Will tools convert all PL/SQL code automatically?
No. ora2pg, AWS DMS Schema Conversion and the AWS Schema Conversion Tool handle tables, indexes, views and simpler code well, but complex packages, autonomous transactions, object types and dynamic SQL usually need manual work. The tool's report shows how many such places there are, and that is where an estimate should start.
Can PostgreSQL handle the load of an Oracle system?
Often yes, but you have to prove it with a test rather than assume it. PostgreSQL has a different query planner, connection handling and partitioning mechanisms. Queries tuned for years on Oracle may need new indexes or a rewrite. Before cutover, run a load test on a copy of production data and compare the times of key transactions.
What about empty strings and NULL after migration?
Oracle treats an empty string as NULL; PostgreSQL does not. Choose one rule: convert empty strings to NULL during data migration, or fix the conditions in code and in the application. Document the choice in the migration plan and verify it with tests, or the difference only shows up in reports.