Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A developer ran an UPDATE without a WHERE clause on the production customers table at 14:05. Writes continue. Walk through recovering with point-in-time recovery while limiting impact.

First we stop the damage from growing, by pausing whatever writes to the customers table or putting that feature in read-only mode. Then we restore a base backup to a new instance and replay WAL to just before 14:05 with recovery_target_time, never touching production. From that copy we extract the correct customers rows and repair production with a careful UPDATE joined by key, taking care not to undo legitimate changes made after 14:05, and afterwards we change how production changes are made.

Why this question is asked

An UPDATE without a WHERE clause is the classic production mistake, and it happens to careful people. What separates a calm recovery from a second incident is the plan: restoring the whole database over production would throw away every legitimate change since 14:05, across every table. Interviewers ask this scenario to see whether we can use point-in-time recovery precisely, protect the data that is still correct, and fix the process afterwards. In this answer, we will contain the damage, run point-in-time recovery to a separate instance, repair only the damaged rows, deal with changes made after the mistake, and then look at how to keep it from happening again.

1Contain the Damage First

At 14:05 the statement ran something like UPDATE customers SET email = 'test@example.com' and committed. Every customer row now has the wrong value in that column, and because writes continue, the application is now sending messages to the wrong address, or customers are editing profiles on top of broken data. The first job is to stop things getting worse, not to start restoring.

So we look at who reads and writes the damaged column. If an email job is sending messages, we pause it. If the customer profile feature can be put in read-only mode with a feature flag, we do that. We avoid stopping the whole service if we can, because orders and payments in other tables are still correct and still flowing. We also record the exact time of the statement from the database log or pg_stat_statements, the session that ran it, and which columns it changed, because the repair depends on these details.

2Restore to a New Instance With Point-in-Time Recovery

Point-in-time recovery means restoring a physical base backup and replaying archived WAL, the write-ahead log of every change, up to a chosen moment. We do it on a new server, never on production, because production also holds every correct change since 14:05 in every other table.

We pick the latest base backup taken before 14:05 and set the recovery target just before the bad statement. If the log shows the UPDATE committed at 14:05:12, we target 14:05:00, or better, the transaction just before it with recovery_target_xid if we can find it. With recovery_target_action = 'pause', PostgreSQL stops at the target and lets us check the data before we promote it, and if we chose the wrong time we can restart with a different target.

Java
# On the new instance, after restoring the base backup files (pgBackRest example)
pgbackrest --stanza=main --delta \
--type=time --target="2026-11-05 14:05:00+00" \
--target-action=pause restore
# The equivalent PostgreSQL settings it writes
# restore_command = 'pgbackrest --stanza=main archive-get %f "%p"'
# recovery_target_time = '2026-11-05 14:05:00+00'
# recovery_target_action = 'pause'
-- once paused, check the data before going further
SELECT count(DISTINCT email) FROM customers; -- 98211 (before the mistake: many distinct values)
Step throughRepairing with a restored copy
ProductionRestored copyEngineer
pause writer job, set feature read-only
restore base backup, replay WAL to 14:05:00
paused at target, data looks correct
export id and email of customers
load into repair table customers_fix
UPDATE from customers_fix, skip rows changed after 14:05
rows updated: 98204, as expected
re-enable feature and job

8 messages in order. Play them, or step through them one at a time.

3Repair Production Row by Row

With the restored copy open, we export only what the bad statement damaged: the primary key and the original value of the changed column. We load that into a repair table on production, then run one UPDATE that joins by key. We run it inside a transaction, check the row count against what we expect, and only then commit.

SQL
-- On the restored copy
\copy (SELECT id, email FROM customers) TO 'customers_fix.csv' CSV
-- On production
CREATE TABLE customers_fix (id bigint PRIMARY KEY, email text NOT NULL);
\copy customers_fix FROM 'customers_fix.csv' CSV
BEGIN;
UPDATE customers c
SET email = f.email
FROM customers_fix f
WHERE c.id = f.id
AND c.email = 'test@example.com' -- only rows still holding the bad value
AND f.email <> 'test@example.com'; -- and only where the copy has a real value
-- UPDATE 98204
COMMIT;

Notice the two extra conditions in the WHERE clause. They make the repair narrow: we only touch rows whose email still holds the bad value, so a customer who typed a new email after 14:05 keeps it. Notice also that we test the damaged column itself rather than the row's updated_at. A customer who edited only their name after 14:05 has a recent updated_at but still carries the bad email, and still needs it repaired; and if a trigger maintains updated_at, the bad UPDATE itself bumped it on every row.

4Handling Changes Made After 14:05

Between 14:05 and the moment we paused writes, real customers may have changed their email, and new customers may have signed up. A blind copy from the restored instance would overwrite those legitimate changes with older values. So we split the rows into three groups. Rows whose email still holds the bad value get the restored value, even if other columns changed later. Rows whose email a person changed after 14:05 keep their current value, because it is newer than anything in the backup. Rows created after 14:05 do not exist in the restored copy and are left alone.

Timestamps help, but an audit table or the application's change log is better, because it says who changed what and when. Where the evidence is unclear, a short list of uncertain rows for the support team to review is safer than guessing.

Deciding each customer row
Row situationEvidenceAction
Email still holds the bad valueemail = bad value, no later email change in auditrestore value from copy
Email changed by customer after 14:05audit entry for email after 14:05keep current value
Created after 14:05id not in restored copyleave alone
Unclearconflicting evidencelist for manual review

5Preventing It Next Time

After the repair, the post-incident review should be about the process, not the person. Production data changes should go through reviewed scripts run by a tool, not typed into a live session. Those scripts run inside a transaction and check the affected row count before committing, for example by aborting if more than the expected 1 row changes. Direct write access to production databases should be rare and temporary, granted through just-in-time access with auditing. Some teams also add guards in their SQL client, such as safe-update modes that refuse an UPDATE without a key in the WHERE clause.

SQL
BEGIN;
UPDATE customers SET email = 'new@example.com' WHERE id = 4711;
-- UPDATE 1 <- if this had said UPDATE 98211, we would ROLLBACK here
COMMIT;

6Follow-up questions

How would you know the RTO for this database before an incident?

By measuring it in regular restore drills. We restore the latest base backup to a fresh instance, replay WAL to a chosen time, run checks and record how long each step took: provisioning, copying files, replaying WAL and validating. Those measured times are our real RTO, and they tell us whether we need more frequent base backups or faster storage.

Why not restore production itself to 14:05?

Because that would undo every legitimate change made in every table after 14:05, such as new orders and payments, to fix one column of one table. Restoring to a separate instance lets us repair just the damage.

What if the backup chain is broken?

Then we look for other sources: a delayed replica if one exists, logical dumps, the application's audit log or event stream, or an analytics copy. This is why restore drills matter: they find a broken chain before we need it.

7Conclusion

In this answer, we recovered from an UPDATE without a WHERE clause. We contained the damage by pausing writers, restored a base backup to a new instance and replayed WAL to just before 14:05, then repaired production with a narrow UPDATE joined by key that only touched emails still holding the bad value. We separated untouched rows, rows legitimately changed later and new rows, and finished with process changes: reviewed scripts, transactions with row count checks, and less direct write access.

What to say in the interviewAbout 80 seconds aloud

Open with

First I would contain it. I would find what writes or reads that column, pause any job that is sending messages or acting on the bad data, and put the affected feature in read-only mode, without stopping the rest of the service, because other tables are still correct.

Then, if they want more

I would note the exact commit time and the columns changed from the logs. Then I would restore the latest base backup before 14:05 to a new instance, never over production, and replay WAL to just before the statement with recovery_target_time and recovery_target_action set to pause, so I can check the data at that point.

From that copy I export the primary keys and original values, load them into a repair table on production, and run one UPDATE joined by key inside a transaction, only for rows whose email still holds the bad value, and check the row count before committing.

Legitimate changes after 14:05 keep their current values, and I would use the audit log rather than just timestamps when it is available. Afterwards I would push for reviewed change scripts, transactions with row count checks, and fewer people with direct write access.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. 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 "A developer ran an UPDATE without a WHERE clause on the production customers table at...": https://scrivio-interview-library.netlify.app/databases/database-operations/418b0235b2/