Notes · Operations

Breaking Oracle: beyond 4,294,967,295 rows

In 2014 we moved 8.9 billion matches out of eHarmony's customer-facing Oracle database and into their own cluster. The pattern was simple. Running it like a mission is what made it work.

A mechanical row counter labeled ROWS CREATED, stopped at 4,294,967,295 with a MAX tag and the note 2 to the 32nd minus 1

Vitaliy Mogilevskiy · November 24, 2026 · 8 min read · First published on dbatoolz.com, 2016

4294967295 rows created

Tuesday, November 4, 2014, 10:55 a.m. After an hour and fifty minutes, the load finally comes back:

4294967295 rows created.

That's 232 − 1, the ceiling of a 32-bit row counter: the number Oracle's engineers figured nobody would ever reach. We'd passed it long before. The table held more than twice that, and it was growing by over 10 million rows a day.

The table was eHarmony's matches, 8.9 billion of them, living in the same Oracle database as the rest of the customer-facing site. That week we moved them into their own database cluster, so the matching services could scale on their own and we could get on with the big-data problem.

None of it was groundbreaking. Twitter had moved its tweets out of MySQL into Cassandra in 2010; Netflix moved its movie queue from SimpleDB to Cassandra in 2013 the same way. What was different was the platform. This was an Oracle shop, and instead of buying big-iron replication we built our own migration service and a technique we could repeat.

The plan: batch the past, stream the present

Split the data in two. A batch job handles everything up to a point in time; a stream handles everything after it. Both apply the same transformation rules, so they land in the same shape and can be merged. It's close to a Lambda architecture, except the end product isn't a query. It's an entire data set that conforms to the new model.

Migration plan: dual-write plus backfillAt T0 a dual-write service mirrors writes from the legacy database into a dual-write schema. At T1 a snapshot of the legacy database is extracted and a backfill job transforms, deduplicates and indexes it into a backfill schema. The two schemas merge, with dual-write winning every overlap, into the new cluster, and dual-write keeps the two databases in sync afterwards. Legacy DBlive traffic1 Dual-writeservice · T02 Snapshotas of T1Dual-writeschemaBackfillschema3 Backfilldedupe · index4 Mergedual-write wins5 Newclusterafter the merge, dual-write keeps both in syncT0 · STREAM THE PRESENTT1 · BATCH THE PAST
The migration in five steps. Amber is the live stream, sage is the historical batch.
  1. T0: turn on dual-write. An event-driven migration service mirrors every write from the legacy database into an empty staging schema on the new cluster, applying the same rules as the backfill. An update to a row the staging schema hasn't seen yet becomes an insert.
  2. T1: snapshot. Take a consistent as-of snapshot of the legacy database, mount it on a standalone node and extract it to shared storage.
  3. Backfill. Load the T1 data into the new cluster, transforming, deduplicating, partitioning and indexing on the way in. It lands in its own schema, separate from dual-write.
  4. Merge. When the backfill finishes, pause dual-write briefly and merge. Dual-write wins every overlap, because it holds the latest version of each row.
  5. Resume dual-write and keep the two databases in sync.

The transformation happened on load, not on extract. The new cluster had far more CPU than the standalone staging node, so it was faster, and keeping the extract an exact mirror of the legacy data meant we had something to check against when validation raised questions.

The cutover wasn't a flag day. Once the databases were in sync, we deployed the new microservices on the new store and sent a small cohort of users to them, watching for failures and latency. If anything broke, we routed back to the old service, fixed it and tried again, while dual-write kept both stores current. Everyone moved only when we trusted it.

The rest of this note is the tooling and instrumentation that got us through steps 2 to 5.

A run-doc, timed to the minute

The whole migration lived in a run-doc: numbered steps, each a copy/paste command that calls an independent shell script, each with a duration from rehearsal. Every script checks its own result and emails it on exit. You can chain them into a master script or run them one at a time.

                         OCT-02-2014

Id STEP                                                          Min
-- ------------------------------------------------------------ ----
 1 Set up staging schema                                           5
 2 Enable dual-write to the new cluster (T0 starts here)          60
 3 Clone legacy database to a staging database                    60
 4 Extract latest matches and match data                         360
 5 Create target schema                                           12
 6 Create STAGE tables                                             2
 7 Set up index rebuild package                                    2
 8 Load MA from STAGE                                             41
 9 Load staging table used to check for dups [MDC]                17
10 Build MA+MDC indexes so we can check for dups                  32
11 Build a list of dups joining MA and MDC                        64
12 Remove duplicate matches from MA                                5
13 Load MUA from MA                                               45
14 Rebuild MUA indexes                                            75
15 Re-enable constraints                                           5
16 Import schema stats                                             1
17 Disable dual-write                                             45

   ------------------------- merge -------------------------

18 Disable access to STAGE                                         5
19 Count rows in STAGE                                            35
20 Validate STAGE matches exist for USER1+USER2                   19
21 Set up and populate staging table of matches to purge           2
22 Purge dual-write collisions from table 1                        9
23 Purge dual-write collisions from table 2                       48
24 Sync TABLE_1 with STAGE                                         2
25 Sync TABLE_2 with STAGE                                        17
26 Extract TABLE_3_ALL directly from legacy                       12
27 Sync TABLE_3 with legacy                                        1
28 Grant / create synonyms                                         1
-- ------------------------------------------------------------ ----
                                                          TOTAL: 982
The run-doc schedule, rebuilt from the original with internal names generalized. Steps 8 to 16 are the backfill.

A run-doc takes judgment calls out of the cutover window, so you can focus on the step in front of you even when you're half asleep. The last thing you want at that hour is to be doubting yourself while you work out what comes next.

And it was rehearsed. We kept each rehearsal's timings in the run-doc's comments, so during the real run every step had a number to beat. This is the test rollout and dress rehearsal from Busy is not a deliverable: every step identified and timed, then run end to end until reality stops disagreeing with the plan.

Instrument or fly blind

The night before, we ran steps 1 and 2 of the plan. To get a consistent snapshot, we put the source database in backup mode, took a SAN snapshot of its volumes, presented it to the staging node and recovered it to a consistent state. Data Pump then extracted it to shared NFS storage with 16 parallel workers.

It finished in 8 hours, 8 minutes and 11 seconds: 13 hours faster than the previous rehearsal, when our shared storage had struggled.

Any step that runs longer than a few minutes also gets a snapshot of what the database is waiting on, from monitoring we built in-house. If the system is starved for a resource, we find out early:

MIN_SAMPLE_TIME            MAX_SAMPLE_TIME            DURATION_TIME
-------------------------- -------------------------- --------------------------
04-NOV-14 12.10.39.291 AM  04-NOV-14 12.14.24.786 AM  +000000000 00:03:45.495

 TSECS EVENT                               SQL_ID           SQL_HASH
------ ----------------------------------- ------------- -----------
  1978 Datapump dump file I/O              8khaw3u81bgv6   777633826
  1434 ON CPU                              8khaw3u81bgv6   777633826
   204 direct path read                    8khaw3u81bgv6   777633826
   101 db file sequential read                                     0
    41 ON CPU                                                      0
     1 db file scattered read                                      0

6 rows selected.
Wait-event profile of the Data Pump extract, sampled a few minutes in.

Without it, the first sign of trouble would have been the previous rehearsal's elapsed time passing with no end in sight.

The duplicates that ate 2 TB of TEMP

The new model stores every match twice, once under each user, so you can look it up by either ID. That turns 8.9 billion matches into 17.8 billion rows. It also exposed a problem. In rare cases, two separate matches had been made for the same pair of people, and flipping the IDs turned them into duplicate keys:

How flipping user IDs exposes duplicate matchesThe source stores one row per match: match 1 for users 1 and 2, and match 2 for users 2 and 1, the same pair made twice. The target stores each match under both users, so the pair (1,2) appears for both match 1 and match 2, and so does (2,1). ROW_NUMBER partitioned by user1 and user2 gives the second row in each pair the number 2, marking it as the duplicate. SOURCE · ONE ROW PER MATCHmatchuser1user2112221match 2: same pair of people,made a second time by mistakestore underboth usersTARGET · ONE ROW PER USERuser1user2matchrn1211122221112122(1,2)(2,1)rn = ROW_NUMBER() OVER (PARTITION BY user1, user2 ORDER BY match)rn > 1 is the duplicate: delete it
Flipping user IDs makes a second match for the same pair collide. ROW_NUMBER() marks the extra row.

In the first rehearsal this was easy: a GROUP BY found the duplicates. By the second rehearsal the data had passed some critical mass, and the same query plan generated twice as much sort, all of it on disk. We ran out of TEMP. Three runs, each over 40 minutes, each failing on space. I gave TEMP 2 TB. It ate that too, and I threw in the towel.

Oracle's analytic functions did what GROUP BY couldn't. ROW_NUMBER() OVER (PARTITION BY … ORDER BY …) numbers the rows within each partition, so every duplicate comes out with a row number above 1 and a plain WHERE clause finds it:

-- Sketch with generic names: keep the first match for each pair of users
DELETE FROM matches_by_user
 WHERE ROWID IN (
       SELECT rid
         FROM (SELECT ROWID AS rid,
                      ROW_NUMBER() OVER (PARTITION BY user1_id, user2_id
                                         ORDER BY match_id) AS rn
                 FROM matches_by_user)
        WHERE rn > 1);

Across all 17.8 billion rows, the filter took 50 minutes (Elapsed: 00:50:02.89).

Workers you can stop

Indexing ran through a package we wrote for it. You give it a table name, a number of concurrent workers and the database node to run on. It spawns that many workers, and each one pulls table partitions from a queue table built on the fly.

The workers can be stopped and started at any time, and they pick up where they left off. In testing, that let us tune the rebuild while watching what it did to the cluster and the storage. It's the same restartable, multi-worker shape I'd first learned from Oracle's own patching tools, and I've rebuilt it ever since; the latest version is open source as hammerdown.

"Are we there yet?" is easy to answer. The queue table shows what's done and what's pending, and the workers log each partition with autonomous transactions, so the log survives even if a worker dies:

TARGET_NAME            P   COUNT(*)
---------------------- - ----------
MATCH_ALL              N        202
MATCH_ALL              Y        310
MATCH_DUP_CHECK        N        191
MATCH_DUP_CHECK        Y        321

TARGET_NAME            START_DATE                    END_DATE
---------------------- ----------------------------- -----------------------------
MATCH_ALL              04-NOV-14 12.21.21.764927 PM  04-NOV-14 12.21.39.847200 PM
MATCH_ALL              04-NOV-14 12.21.16.770432 PM  04-NOV-14 12.21.39.830473 PM
MATCH_ALL              04-NOV-14 12.21.21.809984 PM  04-NOV-14 12.21.39.734733 PM
MATCH_ALL              04-NOV-14 12.21.19.379682 PM  04-NOV-14 12.21.39.570969 PM
MATCH_ALL              04-NOV-14 12.21.14.959532 PM  04-NOV-14 12.21.38.810784 PM
MATCH_ALL              04-NOV-14 12.21.13.962890 PM  04-NOV-14 12.21.38.458792 PM
MATCH_ALL              04-NOV-14 12.21.14.179121 PM  04-NOV-14 12.21.37.865755 PM
MATCH_ALL              04-NOV-14 12.21.11.849899 PM  04-NOV-14 12.21.36.775834 PM
MATCH_ALL              04-NOV-14 12.21.09.936565 PM  04-NOV-14 12.21.35.589880 PM
MATCH_ALL              04-NOV-14 12.21.08.388380 PM  04-NOV-14 12.21.33.683780 PM

10 rows selected.
The queue mid-run, partitions processed (Y) and pending (N), and the last ten partitions to finish, 18 to 26 seconds each.

When it's done, the log says so, and a summary gives the total time per table:

LOG_LINE
--------------------------------------------------------------------------------
15484: unload -> no unusable partitions found - exiting on: 2014-nov-04 12:21:39
start_batches -> START on 2014-nov-04 12:04:06

TARGET_NAME        STRD                          ENDD                          MINUTES
------------------ ----------------------------- ----------------------------- -------
MATCH_ALL          04-NOV-14 12.04.10.336136 PM  04-NOV-14 12.21.39.847200 PM       17
MATCH_DUP_CHECK    04-NOV-14 12.04.15.484836 PM  04-NOV-14 12.21.03.465170 PM       16
The worker log and per-table summary: 1,024 partitions indexed in 17 minutes.

Import the stats, don't gather them

The Oracle optimizer doesn't know what it's doing until you give it table and index statistics. Gathering them on this data could take a full day, which has no place in a cutover window.

So we gathered them ahead of time, exported them, and imported them during the run with DBMS_STATS.IMPORT_SCHEMA_STATS. That takes seconds. One trap: system-generated hash partition names (SYS_P%) differ from build to build, so we wrote a small procedure to rename the partitions to match the names in the exported stats.

The merge

With the backfill done (data clean, partitioned and indexed), we paused dual-write and counted:

SetMatches
Backfill, historical8,867,335,138
Dual-write, online23,046,176

First, purge every historical match that also exists in the online set, since the online copy is newer. We looked them up by match_id with a nested-loop join (USE_NL), which had been the fastest plan in testing. The storage array alerted at over 30,000 IOPS, with service times under a millisecond:

------- 3PAR IO Alert!: Wed Nov  5 13:20:23 PST 2014 -------

    - ISSUE: found 1 IO consumers over threshold of 20000 IOPs

------- here are the hosts -------
13:20:23 11/05/2014 r/w   I/O per second       KBytes per sec        Svt ms   IOSz KB
           Hostname         Cur   Avg   Max     Cur    Avg    Max   Cur  Avg  Cur  Avg Qlen
         matchdb-01    t  31844 31844 31844  281182 281182 281182  0.39 0.39  8.8  8.8   12
Storage alert during the purge, hostname generalized.

Then a direct-path insert (INSERT /*+ APPEND PARALLEL */) with 32 parallel slaves, letting Oracle handle the index maintenance: it marks the affected index partitions unusable during the load and reconciles them once the load completes. Inserting the 23,046,176 rows, indexes included, took a minute and a half (01:30.13).

The last step was flipping the synonyms that the online and batch APIs connect through, and handing the system over. Mission accomplished.

What still holds

The tools have changed since 2014. Today you'd probably reach for a change-data-capture product before writing your own migration service. The way you run the work hasn't:

Most of all, it was run as one mission: a timed plan, rehearsals, and one person driving the backfill. That's the operating discipline behind Busy is not a deliverable, and it's how I still run large migrations.

This is a remastered version of “Breaking Oracle: Beyond 429496729 Rows,” first published on dbatoolz.com on January 15, 2016 (archived copy). The text is tightened, the title's missing digit is restored and the figures are rebuilt. The old address now redirects here.

Planning a migration you can't afford to get wrong?

I plan and run large database migrations as one mission: a timed run-doc, full-volume rehearsals, instrumentation on every long-running step, and someone driving the cutover window who has done it before.