How to Back Up a Large Database Without Locking It

Traditional backup approaches can lock a database during the backup process, causing application downtime — a real problem for large databases where backups take significant time. This guide covers approaches avoiding this.

Why Naive Backups Can Cause Locking

A simple database dump reading table data can, depending on the approach and database engine, block writes (or in some cases reads) for the duration — for a small database this is negligible; for a large database taking minutes or hours, this becomes genuinely disruptive.

MySQL/MariaDB: Using --single-transaction (InnoDB)

mysqldump --single-transaction --quick -u root -p mydb > backup.sql

For InnoDB tables, --single-transaction creates a consistent snapshot without locking tables, since InnoDB's MVCC (Multi-Version Concurrency Control) allows this — the standard approach for non-blocking MySQL/MariaDB backups with InnoDB.

Important: This Doesn't Work for MyISAM

MyISAM tables lack MVCC support, so --single-transaction doesn't provide the same non-blocking guarantee — if you have MyISAM tables, they may still require locking during backup; consider migrating to InnoDB if non-blocking backups matter for your specific tables.

PostgreSQL: pg_dump's Natural MVCC Support

pg_dump -U postgres mydb > backup.sql

PostgreSQL's MVCC architecture means pg_dump naturally provides a consistent snapshot without blocking concurrent reads/writes — no special flag needed, unlike MySQL's InnoDB-specific requirement.

Using a Read Replica for Backup Isolation (Best Approach for Large Databases)

See How to Set Up a Read Replica for Scaling Database Reads — running your backup against a read replica rather than the primary database entirely avoids any risk of backup activity impacting production write performance, regardless of the specific database engine's locking behavior.

Using Snapshot-Based Backups (Storage-Level, Not Database-Level)

See How to Use VPS Provider Snapshots Effectively — a storage-level snapshot captures the disk state nearly instantaneously, avoiding the extended duration of a traditional logical dump for very large databases; requires the database to handle crash-consistent recovery correctly (see How to Create Application-Consistent Backups (vs Crash-Consistent)).

MongoDB: Using mongodump with Oplog

mongodump --oplog --out /backups/mongo

--oplog captures the operations log during the dump, allowing a consistent point-in-time recovery even though the underlying dump itself takes time to complete.

Scheduling Backups During Lower-Traffic Windows

Even with non-blocking approaches, backup activity does consume some I/O/resources — schedule during genuinely lower-traffic periods where feasible, minimizing any residual performance impact even if not causing outright locking.

Monitoring Backup Impact on Production Performance

See How to Monitor Database Performance and Slow Queries — monitor query performance during backup windows to confirm your chosen approach genuinely isn't impacting production performance as expected.

Common Errors

Backup completes but application experienced slowdowns during the window — verify you're actually using the non-blocking flags/approach correctly for your specific database engine, and consider the read replica approach if impact persists despite correct configuration.

Continue Reading

Browse more articles in Backup & Disaster Recovery.

  • backup large database without downtime, mysqldump single-transaction, non-blocking database backup, backup database no lock
  • 0 Uživatelům pomohlo
Byla tato odpověď nápomocná?

Související články

Backup Strategy 101: The 3-2-1 Rule Explained

Before diving into specific backup tools, it's worth understanding the industry-standard...

How to Back Up to Object Storage (S3-Compatible)

S3-compatible object storage provides durable, cost-effective off-site backup storage —...

How to Test and Verify Your Backups Actually Work

A backup that has never been restored is not a verified backup — it's an assumption. This...

How to Create a Disaster Recovery Plan for Your VPS

A disaster recovery (DR) plan is a documented, tested procedure for restoring service after a...

How to Use VPS Provider Snapshots Effectively

Most VPS providers offer a snapshot feature — a point-in-time image of your entire server....