📋 In This Post
Lab Overview
A removal firm delivers your boxes and hands you a sheet saying forty boxes loaded, forty boxes delivered. The sheet is accurate. Nobody opened a single box, so nobody can tell you the glasses are intact.
Database migration runs on the same sheet. The tool reports rows read, rows written, and a progress bar reaching a hundred percent. None of those says whether a row on the new database means what it meant on the old one. Moving a row and preserving its meaning are separate questions, and only one is being counted.
So this week I migrated MySQL to PostgreSQL with AWS Database Migration Service, kept writing to the source while the migration ran, switched validation on, and seeded the table with values that are perfectly legal in MySQL and have no equivalent in PostgreSQL. Then I asked the target what it actually held.
Cloud Services and Concepts
| Service | Purpose here | What it is |
|---|---|---|
| AWS DMS | The migration itself, on a dms.t3.micro replication instance, running full load plus change data capture with validation on | A managed service that copies a database to another database, optionally of a different engine, while the first one keeps serving |
| Amazon RDS for MySQL | The source, db.t4g.micro, with binary logging turned on so changes can be captured | A managed MySQL instance |
| Amazon RDS for PostgreSQL | The target, db.t4g.micro. A different engine, which is where meaning gets lost | A managed PostgreSQL instance |
| AWS Lambda | Writes the awkward rows, then keeps writing during the load. Inside the VPC, because neither database is public | Short-lived functions; nothing runs between invocations |
| Amazon CloudWatch Logs | The task's own log, which turned out to be half the answer and only half | The log store; DMS writes task progress and errors here |
| HCP Terraform | Remote applies into the sandbox account through OIDC, so no AWS keys are stored anywhere | Hosted Terraform runs, authenticating with short-lived credentials |
What validation actually does, and when
Validation is not on by default. You set
EnableValidation to true, and then, in AWS's words,
"validation begins immediately after a full load is performed for a
table". It reads every row from both databases and compares them, which
costs real query load on both sides.
During validation DMS creates a table on the target called
awsdms_control.awsdms_validation_failures_v1, and writes a
row into it per failure, with a DETAILS column naming the
columns that differ. That table is the evidence, and it is worth
knowing that it may not be there at all: a query against it before
validation has run fails outright, which is a different thing from
finding it empty.
One limitation worth knowing before you plan around it: validation
requires a primary key or unique index. A table without one reports
No primary key rather than an error.
Complete and correct are different questions
DMS publishes a table state and a validation state, and they are not
the same field. Table error is defined by AWS as "the table
wasn't validated because it was in an error state and some data wasn't
migrated". A table in that state never leaves
Pending validation, because there is nothing to compare
against.
Which is the trap. A failed table and a slow validator look identical in the counters: both sit at zero failures, pending. One means "not finished checking". The other means "nothing arrived, and nothing ever will".
Architecture and Workflow
The numbers in the diagram are the order things happen:
- Seed the awkward rows. A Lambda function writes
values that are legal MySQL and have no exact PostgreSQL equivalent:
BIGINT UNSIGNEDat its maximum, aTINYINT(1)holding 2, binary floating point, and aDECIMAL(18,6)whose scale has to survive. - Full load, which is a snapshot. Whatever the source looked like when it began is what gets copied.
- Keep writing during the load. Two thousand rows, written after the snapshot started. These are the cutover question: they have to arrive by change data capture, and the full load counter says nothing about them.
- Validation reads both databases and compares. This is the only step that is about meaning rather than volume.
Prerequisites
- An AWS account, and Terraform 1.10 or later.
- Binary logging on the MySQL source. Change data capture reads the
binary log, so
binlog_format = ROWand a non-zerobinlog retentionare requirements, not tuning. - A primary key on every table you intend to validate.
- Two IAM roles with exact names:
dms-vpc-roleanddms-cloudwatch-logs-role. The console creates these silently the first time you use DMS in an account. Terraform does not, and DMS will not accept substitutes.
Implementation
What was deployed
| Resource | How many | Its job |
|---|---|---|
aws_db_instance | 2 | MySQL source and PostgreSQL target, both db.t4g.micro |
aws_dms_replication_instance | 1 | dms.t3.micro, the machine the migration runs on |
aws_dms_endpoint | 2 | How DMS reaches each database, including the SSL mode for each |
aws_dms_replication_task | 1 | Full load plus CDC, validation enabled, and the type rule |
aws_dms_certificate | 1 | The RDS CA bundle, so the source endpoint can verify the server |
aws_iam_role | 3 | The two exactly-named DMS roles, plus the one the writer runs as |
aws_security_group | 3 | Source, target, and the replication instance |
aws_lambda_function | 1 | Seeds the awkward rows and writes during the load |
| Rules, policies, subnet groups, parameter group, password | 14 | Ingress and egress rules, role attachments, the binlog parameter group, generated credential |
Twenty-eight resources. Three of them cost anything worth counting.
The one thing that is not obvious in the Terraform
The two endpoints do not take the same SSL settings. For the MySQL
source, require is rejected outright; it wants
verify-ca with the RDS certificate bundle imported as a DMS
certificate resource. The PostgreSQL target accepts
require on its own. Same service, same week, two different
answers, and the error message for the wrong one does not suggest the
right one.
Validation and Evidence
I ran the same load twice: once without the type rule that widens the offending column, once with it. Here is the console during the first run.
| Test | Expected | Actual | Status |
|---|---|---|---|
| Both endpoints reach their database | connection test succeeds | both successful, each with its own SSL mode | ✅ |
| Full load completes | progress reaches 100% | 100% in both runs, including the failed one | ✅ |
| Rows present in the target, unwidened | all of them | 0 — Table error | ❌ |
| Rows present in the target, widened | all of them | 6,020 of 6,020 | ✅ |
| Rows written during the load arrive | carried by CDC | 2,000 beyond the full load's 4,020 | ✅ |
| Validation runs and compares | state reaches Validated | Validated, 0 mismatches | ✅ |
| Failure count distinguishes the two runs | non-zero when rows are missing | 0 in both — it cannot | ❌ |
The last row is the finding. A counter reading zero whether the migration worked or never happened is not a check, however prominently it is displayed.
With the rule in place the same console screen reads differently, in exactly one column:
The working run is worth its own sentence. Of 6,020 rows in both databases, the full load carried 4,020. The other 2,000 were written while it ran and arrived separately. Plan a cutover on the full load counter alone and those 2,000 are invisible to you, and they are exactly the rows your customers wrote during the migration window.
| What the task reported | Without the type rule | With it |
|---|---|---|
| Full load progress | 100% | 100% |
| Rows loaded | 0 | 4,020 |
| Rows arriving by CDC | 0 | 2,000 |
| Rows actually in the target | 0 | 6,020 |
| Table state | Table error | Table completed |
| Validation state | Pending validation | Validated |
| Validation failures | 0 | 0 |
The figure contains the most useful thing I found all week, and it is not a number. The DMS task log says:
Command failed to load data with exit error code 0 and exitwhy 1.
Please check target database logs for more information.
That is the whole explanation DMS offers. The actual reason is in the target database's own log, which DMS does not surface anywhere in its console:
ERROR: value "18446744073709551615" is out of range for type bigint
STATEMENT: COPY "shop"."orders" FROM STDIN WITH DELIMITER ',' CSV
MySQL's BIGINT UNSIGNED goes up to
18446744073709551615. PostgreSQL's bigint stops at
9223372036854775807, less than half that. One row held a value above the
ceiling, the bulk COPY of the whole table was rejected
because of it, and the table went to Table error with
nothing loaded. One row out of range cost the entire table.
The fix is a table-mapping transformation rule that changes the column's type on the way across, to a 20 character string, so the value arrives as what it is rather than being forced into a type that cannot hold it:
{
"rule-type": "transformation",
"rule-name": "widen-big-unsigned",
"rule-target": "column",
"object-locator": { "schema-name": "shop", "table-name": "orders",
"column-name": "big_unsigned" },
"rule-action": "change-data-type",
"data-type": { "type": "string", "length": "20" }
}
Security and Cost
Neither database has a public endpoint, and the replication instance reaches them through security group references rather than CIDR ranges. The database password is generated in Terraform and never leaves state; the Lambda reads it from its environment, and the only identity with a route to either database lives in the VPC.
This was also the first week deployed into the sandbox account rather than the management account, which is where every week goes from here on. Service control policies cannot restrict the management account at all, so a deny guardrail only binds the work once the work moves out of it.
What this means for a platform team
Validation costs query load on both databases and is off until you ask for it, so the default configuration of a migration tool is the one that cannot tell you whether the migration worked. Defensible as a default, since the checking is expensive. Not defensible at cutover.
Cost
The stack ran about two and a half hours: two
db.t4g.micro databases, a dms.t3.micro
replication instance, and storage.
The measured figure is not in yet, and this section will carry it rather than an estimate. The usage straddles 26 and 27 November UTC, and Cost Explorer keeps revising a day for hours after it closes; reading it early is how the last two weeks here published numbers that later moved 58% and 84%. It goes in once it stops moving, read from the bill.
Troubleshooting and Lessons
Problem. The task reported full load progress 100% and zero validation failures. The target held zero rows.
Root cause. One seeded value above PostgreSQL's
bigint ceiling made the bulk COPY fail for the
whole table, so the table went to Table error. Validation
never ran, which is why the failure count stayed at zero, and the
progress percentage refers to the load finishing rather than succeeding.
Resolution. A change-data-type
transformation rule widening that column.
Lesson. A zero in a failure counter means one of two opposite things: nothing failed, or nothing was checked. Read the table state before reading the failure count, and treat a count of rows in the target as the only answer that cannot be misread.
Problem. Re-running the migration after fixing the mapping failed with "Start Type : START_REPLICATION, valid only for tasks running for the first time".
Root cause. The start type is not a property of what
you want to happen, it is a property of whether the task has ever run.
AWS is explicit: start-replication is only valid the first
time, and "any other action used for the first time on a given task
… will result in data errors".
Resolution. Pick the start type from the task's
current status: start-replication when it is
ready, reload-target when it has run before and
the whole table needs loading again.
Lesson. Any script that re-runs a migration after a fix is, by definition, never on the first run. Writing the first-run call and testing it once is the easiest way to build something that works exactly once.
Cleanup and Key Takeaways
Everything is destroyed, verified against the API rather than read from the destroy output, and checked while signed in to the sandbox account, because a check pointed at the wrong account reports "gone" for something still running.
Key takeaways
- A progress bar measures effort, not outcome. One hundred percent complete and zero rows in the target are not contradictory readings. They are answers to different questions.
- Zero failures can mean nothing was checked. A table in error never reaches validation, so its failure count stays at zero permanently. The table state is the field that tells you which zero you have.
- The tool's log is not always where the reason is. DMS reported that the load failed and told me to look elsewhere. The target database said which value broke it. Both logs were needed.
- Type ranges are a migration risk, not a detail. One value beyond the target type's ceiling cost the entire table, not the row.
- Rows written during the load need their own answer. Two thousand of mine arrived by change data capture, and nothing in the full load counter would have told me whether they made it.
The whole week comes down to one sentence worth taking to any migration, in any tool: the question is never "did it finish", it is "does the new database say what the old one said", and those are not answered by the same number.
Lab guide and Terraform: week-29-dms-migration-validation
Comments