← all lessons

vip-certification-prep · 2026-08-26 · data-integritydatabasedisaster-recoverypostmetawordpress

Post-restore data integrity checks

The idea

After a partial restore, the import succeeding does not mean the data is correct. Validate three things before calling it done: orphaned rows (e.g. wp_postmeta rows whose post_id no longer exists), broken serialized values (a truncated PHP-serialized string renders wrong or fatals), and stale caches (the object cache may still serve pre-restore values, so flush it). Re-importing the full backup "to be safe" is the wrong instinct — it undoes the targeted restore and discards newer data.

How it shows up

-- orphaned postmeta
SELECT pm.meta_id FROM wp_postmeta pm
LEFT JOIN wp_posts p ON p.ID = pm.post_id
WHERE p.ID IS NULL;
wp cache flush   # clear stale cached values after the restore

Read more

Exercises

  1. Find orphans — Run the orphaned-postmeta query above on a test DB. Done when: you get a (possibly empty) list of meta rows with no parent post.
  2. Spot a broken serialize — Truncate a serialized meta value by hand, then load the post and observe the failure. Done when: you can recognise the symptom of a corrupted serialized string.

My notes