GitLab's 2017 Database Incident: When Every Backup Method Failed at Once

By Published 6 min read

Short answer: On 31 January 2017 a GitLab engineer, trying to rebuild a lagging PostgreSQL replica, accidentally deleted data on the primary database instead. GitLab then found that its backup methods had been failing silently or were never designed for recovery, so it restored from a six-hour-old staging snapshot and lost about six hours of database records. The lesson: a backup you have not restored is not a backup, so automate restore tests and give one person ownership of data durability.

Every engineer has a version of this story: a command typed in the wrong terminal window. What made GitLab's incident famous was not the mistake but what came after it. The company had several backup and replication mechanisms, and when it needed them, none of them worked the way everyone assumed. GitLab also did something unusual: it debugged in public and then published a detailed postmortem. That document remains one of the best free lessons on backups available.

What happened in the GitLab database incident?

According to GitLab's postmortem:

  1. A spike in database load, likely from spam plus a background job removing an account that had been wrongly flagged for abuse, caused the secondary PostgreSQL database to fall behind the primary.
  2. The primary had already removed the write-ahead log (WAL) segments the secondary needed, so the secondary had to be rebuilt by hand. Attempts to do this hung, and settings were changed while troubleshooting.
  3. Late in the evening, an engineer decided to wipe the secondary's data directory and start again. The command was run on the primary.
  4. It was stopped within seconds, but roughly 300 GB of data was already gone.

The team then went looking for the most recent good copy of the database.

Why did every backup method fail?

MechanismWhat GitLab assumedWhat was actually true
Daily pg_dump to S3Regular logical backupsThe job used pg_dump 9.2 against a PostgreSQL 9.6 database, so every run failed. The failure emails were rejected because DMARC was not configured. The S3 bucket was empty.
Azure disk snapshotsDisk-level backupsNot enabled for the database servers.
LVM snapshotsUsable copiesThey existed, but were made for copying data to staging, not for disaster recovery. One manual snapshot was about six hours old.
ReplicationA live second copyThe secondary had just been wiped for rebuilding. Replication is not a backup anyway: it copies deletions too.
WAL archiving / point-in-time recoveryNot in useNo way to replay to the minute before the deletion.

The pg_dump failure is the one to remember. The cron job ran on a server without a database data directory, so the packaging defaulted to the older 9.2 tools. Nothing about the setup looked wrong from the outside. The job ran every day. It just produced nothing, and the alert that would have said so went nowhere.

What was lost and how long did recovery take?

GitLab restored from the six-hour-old LVM snapshot made for staging. Because the staging disks were slow, copying the data took around 18 hours. Database records created in roughly a six-hour window were lost; GitLab estimated around 5,000 projects, 5,000 comments and 700 new user accounts. Git repositories and wikis were stored separately and were not affected. Projects created in the lost window were recreated in basic form from the repositories, without their issues and other database data. Database ID sequences were pushed forward by 100,000 so that new records would not reuse old IDs.

GitLab streamed the recovery live and documented progress in a public document. That openness earned it a lot of goodwill, but goodwill is not the plan to rely on.

The root cause was ownership, not the command

GitLab's own "five whys" analysis lands in the right place. The trigger was a load spike and a mistaken command. The reason recovery took so long and lost data was that backups failed silently, the alternative copies were never designed for recovery, and nobody owned or regularly tested the backup procedures. Its list of improvements reflects that: monitored backups, automated restore testing, hourly snapshots, point-in-time recovery, better runbooks, and a named owner for data durability.

Notice what is not on the list as the main fix: "stop engineers running dangerous commands". Humans will make mistakes under pressure late at night. The system should make the mistake recoverable.

How common is this in Indian startups and SMEs?

It is a very common pattern. The typical setup is a single managed or self-hosted database, a nightly dump script someone wrote two years ago, and a vague belief that "the cloud provider takes backups". Typical gaps:

  • The dump script fails after a database upgrade and nobody notices.
  • Backups are stored in the same account, region or even the same server as the database, so a compromised account or ransomware takes both.
  • Managed database snapshots exist but retention is a few days, and nobody knows how long a restore takes.
  • Uploaded files (invoices, KYC documents, images) are not in the backup at all.
  • Nobody has ever restored a backup into a fresh environment.

There is also a compliance angle. CERT-In's directions of 28 April 2022 require organisations to keep logs of their ICT systems for a rolling 180 days within India, and the Digital Personal Data Protection Act, 2023 expects data fiduciaries to protect personal data with reasonable security safeguards. Losing customer data because backups never worked is a hard position to defend.

A restore-testing routine for a small team

Set the targets first

  • RPO (recovery point objective): how much data can you afford to lose? Six hours, one hour, five minutes? This decides whether nightly dumps are enough or you need continuous WAL archiving / point-in-time recovery.
  • RTO (recovery time objective): how long can you be down? This decides whether an 18-hour copy is acceptable. For most businesses it is not.

Build the backups

  • Use at least two independent methods, for example managed snapshots plus logical dumps or WAL archiving.
  • Keep one copy in a separate account or provider, with delete protection or immutability, so an attacker or a bad script cannot remove it.
  • Include files and object storage, not only the database. Include configuration and secrets needed to rebuild.
  • Match backup tool versions to the database version, and pin them in code.

Monitor them properly

  • Alert on absence of success, not only on failure. If no fresh backup of reasonable size arrived in 26 hours, page someone.
  • Check the size of each backup against the previous one. A 0-byte or suddenly tiny file is an incident.
  • Send alerts to a channel someone reads, and test the alert path itself.

Restore on a schedule

  1. Weekly, automated: restore the latest backup into a throwaway environment, run a few sanity queries (row counts, latest record timestamp) and record the restore time.
  2. Quarterly, manual: a full drill. Someone who did not write the scripts follows the runbook to bring the application up from backups alone. Time it against your RTO.
  3. After every major change (database upgrade, migration, new storage): run the restore test again.

Reduce the chance of the mistake

  • Make production terminals visibly different (prompt colour, hostname in the prompt).
  • Prefer runbook scripts that check which host they are on before destructive steps.
  • Avoid single-person, late-night recovery sessions when a second pair of eyes is available.

If your database is part of a larger migration or modernisation project, build the backup and restore plan before the move, not after.

How Cehpoint can help

Cehpoint's cloud and DevOps team designs backups against your RPO and RTO, sets up off-account copies and point-in-time recovery, adds monitoring that alerts when a backup does not arrive, and automates weekly restore tests with a written runbook your team can follow. If you want an outside check of your current setup first, book a consultation with a senior engineer.

Frequently asked questions

What happened in the GitLab database incident of 2017?

On 31 January 2017, while trying to rebuild a lagging PostgreSQL replica, a GitLab engineer accidentally ran a data-deletion command on the primary database. About 300 GB was removed before it was stopped. GitLab then found its backups were failing or unsuitable, and restored from a six-hour-old snapshot, losing several hours of database records.

Why did GitLab's backups fail?

GitLab's postmortem says the daily pg_dump job used version 9.2 tools against a 9.6 database, so it failed silently, and the failure emails were rejected. Azure disk snapshots were not enabled for the database, the LVM snapshots were meant for staging, and replication had been wiped. Nobody owned or tested the backup process.

Is database replication the same as a backup?

No. Replication copies every change to another server, including mistakes such as deletions and corrupted writes, usually within seconds. It protects against hardware failure, not human error or ransomware. A backup is a separate, point-in-time copy kept independently, which you can restore to a moment before the problem.

How often should a small business test its backups?

Automate a restore test at least weekly: load the latest backup into a temporary environment, check record counts and the latest timestamps, and record how long it took. Do a full manual recovery drill every quarter and after any database upgrade or migration. A backup that has never been restored should be treated as unproven.

What are RPO and RTO?

RPO, the recovery point objective, is how much data you can afford to lose, measured in time, such as one hour of orders. RTO, the recovery time objective, is how long the business can be down while you restore. Together they decide how often you back up, which tools you need and how fast restores must be.

Need help with this?

Tell us what you are dealing with. We reply with a plain plan, and where it makes sense, a working demo before you commit.