There's no exact equivalent to what you want. Options include:
Atomic file-system snapshot
If you're using an atomic file system snapshot you don't need to freeze the database. It might make recovery a little faster if you force a CHECKPOINT
first, but that's about it. When you take a filesystem snapshot and copy it, then start the copy, to PostgreSQL it's as if it crashed and is starting back up. That's perfectly fine, it's crash safe and designed to work that way.
This approach is only valid if the snapshot is atomic - it's all at the same virtual instant. You can't get an atomic snapshot across multiple file systems (on Linux, at least), so if your DB is split across multiple tablespaces or WAL is on a separate disk to the heap you cannot use this approach.
pg_start_backup
/ pg_stop_backup
If you can't do an atomic snapshot you can enable WAL archiving, run pg_start_backup
, copy the DB, run pg_stop_backup
and capture the last WAL archives generated.
It's a bit more complicated, but it gives you a consistent backup without stopping writes and without needing file-system level atomic snapshots.
pg_basebackup
An alternative to using pg_start_backup
and pg_stop_backup
is to use pg_basebackup
to do a streaming copy of the DB over the PostgreSQL replication protocol with --xlog-method=stream
. This requires only a PostgreSQL replication connection, doesn't require the DB to be stopped, and is pretty seamless.
--xlog-method=stream
was only added in pretty recent versions, and pg_basebackup
its self is fairly new.
pg_dump
I didn't initially mention it because you were looking for external tools, but there's always pg_dump
, which gets a SERIALIZABLE
snapshot of the database and dumps it. The DB keeps running like normal (it can still accept writes) and the dump is entirely internally consistent from the time you started the dump.
Write quiescence
Stopping all incoming transactions won't stop PostgreSQL writing. It'll still have VACUUM
work to do with autovacuum, checkpoints to perform, stats to write, etc.
There's no feature in Pg to stop all writes at this point. It might be nice to add, but I'm not aware of anyone working on it.
Some file systems, like XFS, support write freezing at the file system level; this causes all writes to block until the freeze is released. It's safe to freeze all file systems then copy all file systems.
Best Answer
It sounds like you'd be best suited by using a physical base backup + WAL archiving, with regularly updated snapshots of the base backup. I strongly recommend taking regular dumps anyway.
Using newer PostgreSQL versions (9.2 and up, IIRC) you can take fresh base backups from a replica server so you don't have to disrupt the master.
File-system or logical volume level snapshot backups work fine with PostgreSQL so long as your snapshots are atomic. Restoring one is like starting PostgreSQL back up after unexpected power loss or OS reboot, not a big deal.
See also: