Backups with filesystem snapshots

Started by Nick Cleaton9 months ago4 messagesgeneral
Jump to latest
#1Nick Cleaton
nick@cleaton.net

If I take an instantaneous filesystem-level snapshot of the postgres
data directory underneath a running postgres server, is that a safe
backup without doing any pg_start_backup/pg_stop_backup ?

It seems like it should be, so long as I get an atomic snapshot that
includes both data and wal, because starting up from that snapshot
should look the same as recovering from an unclean postgres shutdown
due to a kernel panic.

#2Ron
ronljohnsonjr@gmail.com
In reply to: Nick Cleaton (#1)
Re: Backups with filesystem snapshots

On Mon, Aug 11, 2025 at 9:01 AM Nick Cleaton <nick@cleaton.net> wrote:

If I take an instantaneous filesystem-level snapshot of the postgres
data directory underneath a running postgres server, is that a safe
backup without doing any pg_start_backup/pg_stop_backup ?

It seems like it should be, so long as I get an atomic snapshot that
includes both data and wal, because starting up from that snapshot
should look the same as recovering from an unclean postgres shutdown
due to a kernel panic.

We once restored a whole-system VMware snapshot to a new VM (new IP address
and everything). When I logged in, PG started up without a hiccup; it
took a couple of minutes while WALs rolled forward, but that's to be
expected.

Postgresql didn't (and doesn't) know anything about when snapshots are
taken.

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

#3Greg Sabino Mullane
greg@turnstep.com
In reply to: Nick Cleaton (#1)
Re: Backups with filesystem snapshots

On Mon, Aug 11, 2025 at 9:01 AM Nick Cleaton <nick@cleaton.net> wrote:

If I take an instantaneous filesystem-level snapshot of the postgres
data directory underneath a running postgres server, is that a safe
backup without doing any pg_start_backup/pg_stop_backup ?

Safe, yes[*], but not particularly recommended except for special cases,
like spinning up a fast QA cluster. For backups, use a Postgres-aware
battle tested system like pgBackRest that offers more flexibility and more
safeguards.

* Assuming your hardware/OS drivers are being honest with you about fsync

starting up from that snapshot should look the same as recovering from an

unclean postgres shutdown
due to a kernel panic.

Yes, for all practical purposes it would be identical. Technically more
similar to pulling the plug on the server. :)

Cheers,
Greg

--
Crunchy Data - https://www.crunchydata.com
Enterprise Postgres Software Products & Tech Support

#4Bruce Momjian
bruce@momjian.us
In reply to: Greg Sabino Mullane (#3)
Re: Backups with filesystem snapshots

On Mon, Aug 11, 2025 at 12:41:12PM -0400, Greg Sabino Mullane wrote:

On Mon, Aug 11, 2025 at 9:01 AM Nick Cleaton <nick@cleaton.net> wrote:

If I take an instantaneous filesystem-level snapshot of the postgres
data directory underneath a running postgres server, is that a safe
backup without doing any pg_start_backup/pg_stop_backup ?

Safe, yes[*], but not particularly recommended except for special cases, like
spinning up a fast QA cluster. For backups, use a Postgres-aware battle tested
system like pgBackRest that offers more flexibility and more safeguards.

* Assuming your hardware/OS drivers are being honest with you about fsync

starting up from that snapshot should look the same as recovering from an
unclean postgres shutdown
due to a kernel panic.

Yes, for all practical purposes it would be identical. Technically more similar
to pulling the plug on the server. :)

Also, be careful that any tablespaces are also in the same snapshot.

--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com

Do not let urgent matters crowd out time for investment in the future.