Quick revision
The short answer
I would convert the schema and data types carefully, with particular attention to NUMBER, DATE, Oracle's treatment of empty strings as null and sequences, and test the application's queries against PostgreSQL early. The data moves with an initial bulk load followed by change data capture from Oracle to keep PostgreSQL in sync, verified with row counts, checksums per table or partition and comparisons of key queries. At cutover I would switch reads first if possible, stop writes briefly, let CDC catch up, switch writes, and keep a reverse sync or rollback plan for a period afterwards.
What to remember
In this answer, we designed a migration of 2 TB from Oracle to PostgreSQL with only minutes of write downtime. We converted types carefully, including NUMBER, DATE, empty strings and sequences, and tested the application's queries early. We bulk loaded from a known SCN and kept PostgreSQL in sync with CDC, verified with counts, checksums per partition and key query comparisons, switched reads first, then stopped writes briefly to let CDC catch up before switching writes, and kept a reverse sync as a way back.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would convert the schema and data types carefully, with particular attention to NUMBER, DATE, Oracle's treatment of empty strings as null and sequences, and test the application's queries against PostgreSQL early. The data moves with an initial bulk load followed by change data capture from Oracle to keep PostgreSQL in sync, verified with row counts, checksums per table or partition and comparisons of key queries. At cutover I would switch reads first if possible, stop writes briefly, let CDC catch up, switch writes, and keep a reverse sync or rollback plan for a period afterwards.
Why this question is asked
Moving 2 TB between two different database engines while the system keeps running is a common modernisation project, usually driven by licence cost. The data volume is not the hard part; a bulk load of 2 TB takes hours, not weeks. The hard parts are the subtle differences between Oracle and PostgreSQL, keeping the two in sync while the application keeps writing, and proving the copy is correct before switching. Interviewers ask this to see whether a candidate can design all three. In this answer, we will convert the schema, test the application, load and sync the data, verify it, plan a short cutover, keep a way back, and answer how to test that the application behaves the same.
1Converting the Schema and Types Carefully
Tools such as ora2pg can generate a first PostgreSQL schema from Oracle, but every mapping deserves a review, because several Oracle types and behaviours have no exact equal. Oracle's NUMBER is one type for all numbers; in PostgreSQL we choose integer, bigint or numeric(p, s) per column, based on the actual values, because using numeric everywhere is correct but slower and maps to BigDecimal in Java. Oracle's DATE holds a time down to the second, so it maps to timestamp(0), not to PostgreSQL's date, which would silently lose the time.
| Oracle | PostgreSQL | Watch out for |
|---|---|---|
| NUMBER(10) | bigint or integer | Range of real values; Java type changes |
NUMBER(12,2) | numeric(12,2) | Keep exact decimals for money |
| DATE | timestamp(0) | Oracle DATE has a time part |
VARCHAR2(100 BYTE) | varchar(100) | Bytes in Oracle, characters in PostgreSQL |
| '' (empty string) | NULL or '' | Oracle stores '' as NULL |
| Sequence + trigger | identity or sequence | Reset start values after load |
| CLOB / BLOB | text / bytea | Driver and JPA mapping changes |
The empty string is the classic surprise. Oracle treats '' as NULL, so a query WHERE middle_name IS NULL finds rows where the application saved an empty string. In PostgreSQL those are different values. We decide one rule, usually converting empty strings to NULL during the load to keep behaviour the same, and check application code that relies on it. Sequences must be set after the load to a value above the highest migrated id, or the first insert on PostgreSQL fails with a duplicate key.
2Testing the Application Against PostgreSQL Early
Long before moving data, we run the application on PostgreSQL. With Spring Boot and JPA much of the SQL is generated by Hibernate, which adapts to the PostgreSQL dialect. The risk sits in native queries and database code: ROWNUM instead of LIMIT, NVL instead of COALESCE, the old (+) outer join syntax, SYSDATE, CONNECT BY hierarchies, MERGE statements and PL/SQL procedures. We search for all of them and rewrite them, and we move logic out of stored procedures where that is simpler than translating it.
Identifier case also changes. Oracle folds unquoted names to upper case and PostgreSQL to lower case, so native queries with quoted upper-case names break. Keeping all names unquoted and lower case in the new schema avoids most of this.
3Bulk Load Plus Change Data Capture
A few minutes of write downtime rules out the simple approach of stopping the system and copying everything. Instead, we copy the data while the system runs and then keep the copy current. Change data capture, CDC, reads Oracle's redo log, the log of every committed change, and replays those changes on PostgreSQL. Tools that do this include Debezium's Oracle connector, AWS DMS and Oracle GoldenGate.
6 messages in order. Play them, or step through them one at a time.
The SCN, Oracle's change number, is the point where the bulk copy ends and change capture begins.
The important detail is the start point. The bulk load reads each table as of a single system change number, SCN, and CDC replays every change after that same SCN. If the two points do not match, changes made in between are either lost or applied twice, which is a classic source of missing rows. We load the largest tables in parallel by partition or key range, which typically brings 2 TB across in a day, and then watch the CDC lag fall to seconds.
4Verifying the Copy
Before cutover we need evidence that PostgreSQL holds the same data. Row counts per table are the first check, compared at a moment when CDC has caught up. Counts do not catch wrong values, so we also compute checksums: for each table or partition, both databases produce a hash of the rows ordered by primary key, using the same text formatting for numbers, dates and nulls. A difference narrows the problem to one partition, which we then compare row by row.
Finally, we compare the results of key business queries, such as daily balances, open orders per customer or yesterday's totals, run on both databases. These catch semantic problems that checksums can hide, such as a time zone shift in timestamps that we applied consistently but wrongly to every row.
5Cutting Over With Minutes of Write Downtime
If the application allows it, we switch reads first. Read-only features, such as reports or search, start querying PostgreSQL while writes still go to Oracle; CDC keeps PostgreSQL seconds behind. This tests PostgreSQL under real load with low risk, since switching reads back is easy.
Then the write switch. We stop writes, for example by putting the application into a maintenance mode that rejects write requests or by scaling the writing components to zero. We wait until CDC has applied the last change, which takes seconds when lag is low, run quick final counts on the most important tables, set the sequences, change the application's data source to PostgreSQL, and allow writes again. Rehearsed a few times in a staging environment, this takes a few minutes.
- Reads already on PostgreSQLoptional, if staleness allowed
- Stop writesmaintenance mode for write paths
- Wait for CDC lag to reach zerousually seconds
- Final counts and key checks pass?YesyesNoset sequences, switch writes
- Start reverse sync to Oraclerollback path for a few weeks
5 steps in order. Play them, or step through them one at a time.
6Keeping a Way Back
For a period after cutover, often a few weeks, we keep Oracle current with a reverse sync: CDC from PostgreSQL, for example Debezium's PostgreSQL connector, applies every new change to Oracle. If a serious problem appears, such as a query that is unacceptably slow at month-end, we can switch the application back to Oracle without losing the writes made since cutover.
The reverse path has to be tested like the forward one, including type conversions in the other direction. When the rollback period ends and business cycles like month-end have passed on PostgreSQL, we stop the reverse sync and decommission Oracle.
7Follow-up questions
How would you test that the application behaves the same on PostgreSQL?
I would run the full integration test suite against a real PostgreSQL, using Testcontainers so each test run gets the same version as production, and add tests for the known differences: empty strings, DATE with time, numeric precision, sorting and collation of text, and time zones. Then I would replay a sample of production read traffic against both databases and compare responses, and run performance tests on a production-sized copy, checking query plans for the heaviest queries, because the optimisers differ and an index Oracle used may need to be created differently.
Why not stop the system for a few hours and copy everything at once?
Because the requirement allows only minutes of write downtime, and a 2 TB copy plus verification would take hours. It also leaves no time to fix anything found during the copy. Bulk load plus CDC moves the long work before the cutover, so the downtime only covers the final catch-up.
What does Spring Boot need to change at cutover?
The JDBC URL, credentials and driver, the Hibernate dialect, which Hibernate 6 and later usually detect automatically, and any native queries. If both data sources must exist for a while, for example reads on PostgreSQL and writes on Oracle, we configure two DataSource beans and route repositories explicitly.
8Conclusion
In this answer, we designed a migration of 2 TB from Oracle to PostgreSQL with only minutes of write downtime. We converted types carefully, including NUMBER, DATE, empty strings and sequences, and tested the application's queries early. We bulk loaded from a known SCN and kept PostgreSQL in sync with CDC, verified with counts, checksums per partition and key query comparisons, switched reads first, then stopped writes briefly to let CDC catch up before switching writes, and kept a reverse sync as a way back.
Open with
I would split it into conversion, sync, verification and cutover. For conversion, I would generate a first schema with a tool like ora2pg and then review the tricky mappings by hand: NUMBER becomes integer, bigint or numeric per column, Oracle DATE becomes timestamp because it has a time part, empty strings are null in Oracle so I decide how to load them, and sequences must be reset after loading.
Then, if they want more
I would run the application against PostgreSQL early, with Testcontainers, and rewrite native SQL like ROWNUM, NVL or CONNECT BY. For the data, a stop-and-copy would take hours, so I would bulk load from a known SCN and then use CDC from that same SCN, for example Debezium or DMS, to keep PostgreSQL seconds behind Oracle.
To verify, I compare row counts, checksums per table or partition computed the same way on both sides, and results of key business queries.
For cutover, I switch reads first if they can tolerate seconds of lag, then put the writes into maintenance mode, wait for CDC to reach zero lag, do final checks, set sequences and switch the data source. That takes minutes if rehearsed.
Finally I run a reverse sync from PostgreSQL to Oracle for a few weeks, so we can roll back without losing new writes, and only then retire Oracle.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design a migration of 2 TB of customer data from Oracle to PostgreSQL for a Spring Boot...": https://scrivio-interview-library.netlify.app/architecture/modernization/22dd46ef2a/