GitLab.com Database Deletion
A tired engineer wiped the wrong database server, then the team found their backups had been silently failing.
- Severity
- Status page turned red
- Difficulty
- beginner
- Companies
- GitLab
- Tech
- PostgreSQL, Replication, Backups, Azure
- Root cause
- operator mistake, latent bug
The story
Quick (1 min)
On 31 January 2017, GitLab.com went down for many hours and lost about six hours of user data, including projects, comments and new accounts.
During a long night fighting database problems, an engineer meant to delete data on the backup database server to resync it. They ran the command on the main server by mistake. They stopped it within a second or two, but about 300 GB was already gone.
The team then turned to their backups and found the main nightly backup had been failing silently for some time because of a version mismatch, and the failure emails were being rejected. They recovered from a snapshot an engineer happened to take six hours earlier.
The lesson: a backup you haven't restored from is only a hope. Test your restores.
Keep reading to the end to earn XP.Read. XP earned.
Engineer (2 min)
Setup. GitLab.com ran one PostgreSQL primary (db1) and one hot-standby secondary (db2), used only for failover.
Load and lag. From about 19:00 UTC, database load spiked, which GitLab suspected was spam. Part of it was a background job hard-deleting an employee's account that had been wrongly flagged for abuse. By about 23:00, replication lag grew until the WAL segments the secondary needed were gone from the primary. GitLab wasn't using WAL archiving, so the secondary had to be rebuilt by wiping its data directory and running pg_basebackup.
The debugging spiral. pg_basebackup hung silently. Engineers raised max_wal_senders from 3 to 32. Postgres then wouldn't restart ("too many semaphores") because max_connections was set to 8000, so that was lowered to 2000. pg_basebackup still appeared to hang. In fact it was waiting silently for the primary, which was normal but not documented in GitLab's runbooks or the official docs.
The mistake (~23:30). Thinking leftover files were the problem, an engineer wiped the data directory again, but on the primary, not the secondary. About 300 GB was removed before they stopped it.
The backups:
- Nightly
pg_dumpto S3: the bucket was empty. The job ran on an app server with no Postgres data directory, so the packaging defaulted topg_dump9.2 against a 9.6 database, which errored. Failure emails were rejected because of DMARC. - Azure disk snapshots: not enabled for database servers.
- LVM snapshots (made to copy production to staging): one about 24 hours old, and one taken by hand about 6 hours earlier. That one saved them.
- Replication: both copies were now gone.
Recovery. Copying from slow, cheap staging disks (about 60 Mbps) took about 18 hours. The database was restored to its state at 17:20 UTC on 31 January.
Interview takeaway: test restores, alert on backup failure through a channel that actually reaches people, and make it obvious which host you're on.
Keep reading to the end to earn XP.Read. XP earned.
Deep dive (2 min)
Timeline (UTC, from GitLab's postmortem)
- ±17:20, 31 Jan: an engineer takes a manual LVM snapshot of production to load into staging for pgpool-II testing. This becomes the restore point.
- ±19:00: database load spikes, suspected spam. Users struggle to post comments. Part of the load is a background job removing a GitLab employee wrongly flagged for abuse.
- ±23:00: the secondary falls too far behind and needed WAL segments are gone. The secondary's data directory is wiped for a resync, then
pg_basebackupappears to hang. Configuration changes follow (max_wal_senders3→32,max_connections8000→2000). - ±23:30: an engineer wipes the PostgreSQL data directory on the primary, believing it is the secondary. About 300 GB is removed before they stop it.
- Minutes later: the backup search begins, and help is requested on Slack. "Unfortunately the process of both finding and using backups failed completely."
- Through 1 Feb: data is copied from the staging host. It takes about 18 hours because of throttled network disks.
- 1 Feb, 17:00: the database is restored without webhooks. ~18:00: webhooks are restored from a separate copy, and sequences are incremented by 100,000 to avoid reusing IDs.
Data lost
Database changes between 17:20 and 00:00 UTC on 31 January. GitLab's best estimate: about 5,000 projects, 5,000 comments and 700 new user accounts. Git repositories and wikis were stored separately and not affected. Self-managed GitLab and GitHost customers were not affected.
The four procedures, and why none worked as intended
pg_dumpevery 24h to S3. Silently broken. The Omnibus package picks the Postgres version from$PGDIR/PG_VERSION. On an app server with no data directory it defaulted to 9.2, which can't dump 9.6. Cron error emails were rejected because DMARC wasn't enabled for them.- LVM snapshots every 24h for staging. They worked, but weren't designed for disaster recovery.
- Azure disk snapshots. Enabled for NFS servers, not database servers, "as we assumed that our other backup procedures were sufficient enough."
- Replication. Meant for failover, not disaster recovery, and both hosts were wiped.
Radical transparency
GitLab tracked progress in a public Google Doc and live-streamed the recovery on YouTube, peaking around 5,000 viewers. The engineer had added their own name to the doc. GitLab said it would redact names in future.
"Losing production data is unacceptable." (GitLab CEO, in the postmortem)
Keep reading to the end to earn XP.Read. XP earned.
Failure replay
Step by step, what broke and what it hit next. Showing the key steps. Switch to Engineer or Deep dive for every step.
- 17:20Engineerhealthy
Before testing in staging, an engineer takes a manual LVM snapshot of production. Nobody knows yet that it matters.
Affects: Staging snapshot
- 19:00Primary DB (db1)degraded
Load spikes from suspected spam and a background job hard-deleting a wrongly flagged account.
Affects: Secondary DB (db2)
- 23:00Secondary DB (db2)down
Replication falls too far behind. Without WAL archiving, the secondary must be wiped and rebuilt.
- 23:00–23:30Secondary DB (db2)failing
pg_basebackup seems to hang. Config tweaks and restarts follow, and it still looks stuck.
- 23:30Primary DB (db1)down
Meaning to clear the secondary, an engineer wipes the data directory on the primary. About 300 GB is gone in seconds.
Affects: Users
- 23:30+Nightly pg_dumpdown
The S3 backup bucket is empty. A Postgres version mismatch had been breaking dumps, and the failure emails were rejected.
- Feb 1Staging snapshotrecovering
The manual snapshot from 6 hours earlier is copied back over slow disks. It takes about 18 hours.
Affects: Primary DB (db1)
- Feb 1, 18:00Usersrecovering
GitLab.com returns, restored to 17:20 UTC on 31 Jan. About six hours of database changes are lost for good.
Impact
- Who was affected
- GitLab.com users; an estimated 5,000 projects, 5,000 comments and 700 new user accounts lost. Git repositories and wikis were unaffected.
- How long
- Many hours of downtime; full restoration completed around 18:00 UTC on 1 February 2017.
- Cost
- not disclosed
Lessons
- Regularly test restores; GitLab's main backup had been failing silently.
- Backup failure alerts must reach a human through a channel that works.
- Make destructive commands hard to run on the wrong host (clear prompts, hostname checks, separate credentials).
- Replication is not a backup; deletes replicate too.
- Tired engineers late at night make mistakes; hand off and use runbooks, especially for destructive steps.
Quiz
What was the immediate cause of the data loss?
The answer is An engineer ran a data-wiping command on the primary instead of the secondary. About 300 GB was removed from the primary before the engineer stopped the command.
Check answer
An engineer ran a data-wiping command on the primary instead of the secondary. About 300 GB was removed from the primary before the engineer stopped the command.
Why was the S3 backup bucket empty?
The answer is pg_dump 9.2 was running against a PostgreSQL 9.6 database and failed, and failure emails were rejected. The backup ran on an app server where the packaging defaulted to version 9.2. The errors were emailed but rejected because of DMARC.
Check answer
pg_dump 9.2 was running against a PostgreSQL 9.6 database and failed, and failure emails were rejected. The backup ran on an app server where the packaging defaulted to version 9.2. The errors were emailed but rejected because of DMARC.
What saved GitLab from losing about 24 hours of data?
The answer is An LVM snapshot an engineer took manually about 6 hours earlier for staging. The manual snapshot taken at about 17:20 UTC limited the loss to about six hours of database changes.
Check answer
An LVM snapshot an engineer took manually about 6 hours earlier for staging. The manual snapshot taken at about 17:20 UTC limited the loss to about six hours of database changes.
Why did restoring take about 18 hours?
The answer is The snapshot was on cheap, throttled staging disks (about 60 Mbps). The staging environment used Azure classic storage without Premium Storage, so the drives were the bottleneck.
Check answer
The snapshot was on cheap, throttled staging disks (about 60 Mbps). The staging environment used Azure classic storage without Premium Storage, so the drives were the bottleneck.
Interview prep
Try answering out loud before you open the model answer.
- system design
Design a backup and recovery strategy for a production PostgreSQL database that would have survived GitLab's 2017 incident.
Show model answer
Set recovery point (RPO) and recovery time (RTO) objectives first. Use continuous WAL archiving to object storage plus regular base backups, which enables point-in-time recovery to just before a bad command. Keep backups in a separate account with deletion protection. Most importantly, run automated restore tests: restore to a scratch instance on a schedule, run sanity queries, and alert if it fails. Monitor backup age ("newest successful backup is older than X") rather than relying on failure emails. Make sure restores are fast enough to meet the RTO; GitLab's 18-hour copy came from slow staging disks.
A strong answer hits:
- Define RPO and RTO
- WAL archiving and point-in-time recovery
- Automated, scheduled restore tests
- Alert on backup freshness, not just failure emails
- Restore speed matters as much as having a backup
How did your answer compare? - behavioural
Tell me about a time you made, or nearly made, a destructive mistake in production. What safeguards did you add afterwards?
Show model answer
Answer honestly and blamelessly: explain the context (fatigue, confusion, pressure), what you did to limit the damage, and the systemic fixes. Link it to GitLab: the engineer stopped the command within seconds, but the real failures were missing guardrails and untested backups. Good safeguards include coloured prompts or hostname banners for production, confirmation steps naming the host, peer review for destructive operations, and handing off when tired.
A strong answer hits:
- Own the mistake, focus on systemic causes
- Describe how you limited the damage
- Concrete guardrails (prompts, confirmations, peer review)
- Fatigue and handoff awareness
How did your answer compare? - debugging
A tool you're relying on during an incident hangs with no output. How do you avoid making things worse while investigating?
Show model answer
Pause before trying random fixes. GitLab's pg_basebackup was waiting silently for the primary, which was normal, but each "fix" added risk, and a re-wipe on the wrong host destroyed the data. Check the docs and runbooks, ask someone who knows the tool, use read-only diagnostics (strace, logs, network checks), and avoid destructive retries. Announce each action in the incident channel so others can catch mistakes, and double-check which host you're on.
A strong answer hits:
- Prefer read-only diagnosis over destructive retries
- Ask experts, check runbooks
- Narrate actions so others can catch errors
- Verify the target host before destructive commands
How did your answer compare?
Go deeper
- Official postmortemPostmortem of database outage of January 31GitLab, link checked 2026-11-24