A recovery can be aimed at a wall-clock timestamp, at a transaction-log position, or at a named marker created earlier. How do you choose between them, and why is a timestamp target less precise than it appears?
answer
- end-of-log / timestamp / log position / xid / named marker
- commit-time clock: skew, timezone, coarse in practice
- marker before a risky migration = no forensics later
- inclusive vs exclusive - stop BEFORE the bad txn
- pause at target, inspect, then promote
basics
~20 sUse a log position when you can identify the exact transaction, a named marker when you planned ahead of a risky change, and a timestamp only to narrow a search. Timestamps rely on commit-time clocks, have coarse practical resolution, and cannot separate transactions committing in the same instant.
solid answer
~60 sThe targets differ in precision and in when you must decide. - **Log position** (log sequence number, or file plus offset) is exact, monotonic and clock-independent. It is the best target whenever you can read the log and find the offending transaction's commit record. Its cost is forensic work during an incident. - **Named marker / restore point** is created *before* a risky change, so recovery later needs no forensics at all. It is the professional habit around migrations and bulk operations, and costs nothing to create. - **Transaction identifier** targets stop relative to a specific transaction, useful when you know exactly which one caused the damage. - **Timestamp** is the most human-friendly and the least precise. It is matched against commit timestamps recorded in the log, which come from the server clock at commit time - subject to skew, NTP adjustments and timezone confusion - and practical resolution means many transactions can share the same instant. Two details matter regardless of target: whether the target itself is **included or excluded**, and what recovery does **on reaching** the target - pausing to let you inspect before promoting is almost always the right choice.
go deeper
Know that recovery can be aimed at a time or at a position in the transaction log, and that it always stops at a transaction boundary.
Explain why a log position is more precise than a timestamp and that the target can be inclusive or exclusive.
Give the selection rule per situation, the clock and density reasons timestamps mislead, and the operational settings that decide correctness - exclusive target and pause-at-target.
Push the practice upstream: mandatory restore markers before risky changes, documented recovery-target playbooks, and awareness that recovery rewinds the database but not queues, caches or downstream consumers.
## The available target kinds Engines differ in naming, but the family of recovery targets is consistent: 1. **End of available log.** Replay everything you have. This is the disaster-recovery case: media loss, not logical damage. It maximises recovered data and is not useful when the problem is a bad statement. 2. **Timestamp.** Stop at the last transaction that committed at or before a given time. 3. **Log position.** Stop at a specific location in the transaction-log stream. 4. **Transaction identifier.** Stop relative to a specific transaction's commit. 5. **Named restore point / marker.** Stop at a label that someone recorded in the log stream in advance. ## Why timestamps mislead A timestamp target is compared against the **commit timestamp** written into the log by the server at commit time. That creates several sources of imprecision: - **Clock source.** It is the database server's clock, not the application's or the incident channel's. Skew of even a second, an NTP step, or a mismatch between local time and UTC in how you specify the target can move the boundary by more transactions than you expect. - **Resolution versus density.** A busy OLTP system may commit thousands of transactions per second. Whatever the stored precision, the practical effect is that specifying a time picks a boundary among a crowd of transactions you cannot distinguish, so unrelated work gets included or excluded arbitrarily. - **Commit time is not statement time.** A long transaction that started at 14:10 and committed at 14:33 is included by a 14:33 target and excluded by a 14:32 one, even though most of its work happened long before. Reasoning about 'when the damage started' by statement time therefore does not translate cleanly. - **Ordering.** Recovery stops on **commit order**, which is the log order. Commit timestamps are broadly consistent with that order but should not be treated as a fine-grained sort key. Because of this, the practical method is: use the approximate time to locate the region of the log, inspect the log to identify the offending transaction, then convert to a log-position or transaction-identifier target. ## Why named markers are the best answer Everything above describes forensic work performed under pressure. A restore point created deliberately before a schema migration, a bulk data fix or a risky release removes all of it: the target is a label with unambiguous placement in the log stream. It costs one statement, and it is the single highest-value habit around planned risky changes. The obvious limitation is that it only helps for changes you knew were risky; accidents still require forensics. ## Two settings that decide correctness - **Inclusive versus exclusive.** Most engines let you say whether the transaction matching the target is itself applied or not. When recovering from a damaging transaction you want it **excluded** - stop *before* it. Getting this backwards replays exactly the statement you were trying to escape, and the mistake is easy to make because the default is often inclusive. - **Action on reaching the target.** Typical choices are pause, promote or shut down. **Pause** is the right default during an incident: recovery halts, the database can be inspected read-only, and if you overshot or undershot you can adjust and re-run without having produced a new branch of history. Promoting immediately makes the outcome final; it also forks the history, after which changing your mind can mean restoring from scratch. ## Additional constraints - Recovery always stops on a **transaction boundary**. Uncommitted work at the target is rolled back; you cannot land mid-transaction. - The target must fall inside the recoverable window: at or after the consistency point of the base backup being used, and at or before the end of the contiguous archived log chain. A target earlier than the backup means you need an older base backup. - Some effects are outside the logged stream - engine-excluded operations, files stored outside the database, external systems already notified. Recovery moves the database back; it does not move the outside world back, so reconciliation with queues, caches and downstream consumers is part of the plan. ## Choosing, in one line each Planned risky change: create a marker first and use it. Accidental damage you can pinpoint in the log: use the log position, excluded. Damage you can only bound in time: use a timestamp to find the region, then convert. Media loss with no logical damage: replay to the end of the log.
- You set a timestamp target and recovery clearly overshot, replaying the damaging transaction. What went wrong and what do you do next?Most likely the target was inclusive rather than exclusive, or the timestamp resolved to a boundary after the offending commit because of clock skew, timezone handling, or several transactions sharing that instant. Restore again with an exclusive target, ideally converted to the exact log position preceding that transaction's commit record, and pause at the target so you can verify before promoting.
- Why is pausing at the recovery target usually better than promoting immediately?Pausing lets you open the database read-only and confirm you landed on the right side of the boundary before anything becomes irreversible. Promotion forks the history into a new branch, and undoing that generally means restoring the base backup and replaying again from scratch, which costs the full recovery time a second time.
saying these in an interview costs you the question
- Assuming a timestamp target is exact to the sub-second on a busy system
- Confusing statement time with commit time for long-running transactions
- Leaving the target inclusive when the goal is to stop before the damaging transaction
- Promoting immediately at the target instead of pausing to verify
- Never creating restore markers before planned risky migrations