Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfSE5-0008D6-M9 for pgsql-general@arkaria.postgresql.org; Tue, 26 Oct 2021 19:35:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mfSE4-0001vm-Br for pgsql-general@arkaria.postgresql.org; Tue, 26 Oct 2021 19:35:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfSE4-0001vc-1H for pgsql-general@lists.postgresql.org; Tue, 26 Oct 2021 19:35:12 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mfSDw-0006AE-VX for pgsql-general@lists.postgresql.org; Tue, 26 Oct 2021 19:35:10 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 8E1D45F799; Tue, 26 Oct 2021 15:35:03 -0400 (EDT) Date: Tue, 26 Oct 2021 15:35:03 -0400 From: Stephen Frost To: Lucas Cc: Mladen Gogala , pgsql-general@lists.postgresql.org Subject: Re: ZFS filesystem - supported ? Message-ID: <20211026193503.GM20998@tamriel.snowman.net> References: <49ijds_99IK_4iDOHuZH8CJsKGZw7DEVtJPf0s_oPEvUKwFewHcDQFCUnutcA9GYIkOrRfFAKRsyj0ZFN9ECAbLm-NYPR8jMxTl-RU-U3hA=@protonmail.ch> <1e0db1d2-6a9e-f5f7-44af-e7a1997bafcf@gmail.com> <917520e4-0023-2842-db5f-2e1cbd72b004@gmail.com> <741d4f14b64a45d7a9670042ac8ecf66@sud0.nz> <77b0fb54-64f5-833d-19ba-2c731af1f700@gmail.com> <20211025171342.GH20998@tamriel.snowman.net> <866F3B6D-737F-4F71-BED2-EF03E32EC2E7@sud0.nz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="EJCnrJiDxBM3d8Vu" Content-Disposition: inline In-Reply-To: <866F3B6D-737F-4F71-BED2-EF03E32EC2E7@sud0.nz> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --EJCnrJiDxBM3d8Vu Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Lucas (root@sud0.nz) wrote: > On 26/10/2021, at 6:13 AM, Stephen Frost wrote: > > * Mladen Gogala (gogala.mladen@gmail.com) wrote: > >> On 10/23/21 23:12, Lucas wrote: > >>> This has proven to work very well for me. I had to restore a few back= ups > >>> already and it always worked. The bad part is that I need to stop the > >>> database before performing the Snapshot, for data integrity, so that = means > >>> that I have a hot-standby server only for these snapshots. > >>> Lucas > >>=20 > >> Actually, you don't need to stop the database. You need to execute > >> pg_start_backup() before taking a snapshot and then pg_stop_backup() w= hen > >> the snapshot is done. You will need to recover the database when you f= inish > >> the restore but you will not lose any data. I know that pg_begin_backu= p() > >> and pg_stop_backup() are deprecated but since PostgreSQL doesn't have = any > >> API for storage or file system snapshots, that's the only thing that c= an > >> help you use storage snapshots as backups. To my knowledge,the only da= tabase > >> that does have API for storage snapshots is DB2. The API is called "Ad= vanced > >> Copy Services" or ACS. It's documented here: > >>=20 > >> https://www.ibm.com/docs/en/db2/11.1?topic=3Drecovery-db2-advanced-cop= y-services-acs > >>=20 > >> For Postgres, the old begin/stop backup functions should be sufficient. > >=20 > > No, it's not- you must also be sure to archive any WAL that's generated > > between the pg_start_backup and pg_stop_backup and then to be sure and > > add into the snapshot the appropriate signal files or recovery.conf, > > depending on PG version, to indicate that you're restoring from a backup > > and make sure that the WAL is made available via restore_command. > >=20 > > Just doing stat/stop backup is *not* enough and you run the risk of > > having an invalid backup or corruption when you restore. > >=20 > > If the entire system is on a single volume then you could possibly just > > take a snapshot of it (without any start/stop backup stuff) but it's > > very risky to do that and then try to do PITR with it because we don't > > know where consistency is reached in such a case (we *must* play all the > > way through to the end of the WAL which existed at the time of the > > snapshot in order to reach consistency). > >=20 > > In the end though, really, it's much, much, much better to use a proper > > backup and archiving tool that's written specifically for PG than to try > > and roll your own, using snapshots or not. >=20 > When I create a snapshot, the script gets the latest WAL file applied fro= m [1] and adds that information to the Snapshot Tags in AWS. I then use tha= t information in the future when restoring the snapshot. The script will re= ad the tag and it will download 50 WAL Files before that and all the WAL fi= les after that required. > The WAL files are being backed up to S3. >=20 > I had to restore the database to a PITR state many times, and it always w= orked very well. >=20 > I also create slaves using the snapshot method. So, I don=E2=80=99t mind = having to stop/start the Database for the snapshot process, as it=E2=80=99s= proven to work fine for the last 5 years. I have to say that the process used here isn't terribly clear to me (you cleanly shut down the database ... and also copy the WAL files?), so I don't really want to comment on if it's actually correct or not because I can't say one way or the other if it is or isn't. I do want to again stress that I don't recommend writing your own tools for doing backup/restore/PITR and I would caution people against people trying to use this approach you've suggested. Also, being able to tell when such a process *doesn't* work is non-trivial (look at how long it took us to discover the issues around fsync..), so saying that it seems to have worked for a long time for you isn't really enough to make me feel comfortable with it. Thanks, Stephen --EJCnrJiDxBM3d8Vu Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJheFhnAAoJEO1sijiDR2RV+vIQALbPYGBwUm+qvTTYh8XOPbcr 4gsHeKyHvESueUJ0L6XN1FRrtydyxzpoCjtbW+8HMQKlEXq4zCLpEYycz4dzPGp8 ptsTy8hFur4poR3hCx/4yIOh/Huw5+52OtFwOdZr7DO1ipMRTLFIwB6Nt8zNiFNy PJpBo/bsvC2jkPnNsO3LEWcwyVInFwFCfTJ6d/NcB7XXD28bV1ldU2gaHSIrxRNC jPijq3x+ajnYrOnO2W8QD6In6vO1gviLtADfRVYiPzV6sZD8W6MFfcsBmtL+9Q+6 FZ3Crw1O4gDwZ1r+p7uosQpFe1Sr53RKkpqZ2OB9uo9WV/KvGoQl36+e/mY0yGMd YHyWpF+armK+rzy/SvhNlTAetRKO70p0dBUMgwxlovBw2EC6T0GIad4VAGDAkrAe q4sS3GSPl3dYQd7YdcQfEZKQmlViCQtzuVJfBi2JrkO9DVaCxVxJcR60HeLyaWc0 fwntieLDkPjXH2syesUjHxA3+PKOtOSoDC2Py98Inn+tI/QCvIrpuVmBH3sGsL3B NsFWmZc5NuctJCPPu2ZkPLkNLng1nTuUPxt+5tb2Lzt0LXXWJBpB/NyLy39ne2l8 V46nP++kRPrO8EbxpzFMjiLhgiBrtC2gOyxFq7gZcJ/arNc4mCm1Ln9lHj0xPxxp 7+l4i3QjqPfI3XnAnYDh =rTMj -----END PGP SIGNATURE----- --EJCnrJiDxBM3d8Vu--