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 1mhafz-00065z-3l for pgsql-general@arkaria.postgresql.org; Mon, 01 Nov 2021 17:00:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mhafx-0004Il-UX for pgsql-general@arkaria.postgresql.org; Mon, 01 Nov 2021 17:00:49 +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 1mhafx-0004I6-KD for pgsql-general@lists.postgresql.org; Mon, 01 Nov 2021 17:00:49 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mhafu-00051m-TH for pgsql-general@lists.postgresql.org; Mon, 01 Nov 2021 17:00:48 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 56B945F799; Mon, 1 Nov 2021 13:00:45 -0400 (EDT) Date: Mon, 1 Nov 2021 13:00:45 -0400 From: Stephen Frost To: Lucas Cc: Mladen Gogala , pgsql-general@lists.postgresql.org Subject: Re: ZFS filesystem - supported ? Message-ID: <20211101170044.GT20998@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> <20211026193503.GM20998@tamriel.snowman.net> <0C9F3351-721F-4218-AD88-0829CD359E4E@sud0.nz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="9LnWyBss4uQTlezA" Content-Disposition: inline In-Reply-To: <0C9F3351-721F-4218-AD88-0829CD359E4E@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 --9LnWyBss4uQTlezA Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Lucas (root@sud0.nz) wrote: > > On 27/10/2021, at 8:35 AM, Stephen Frost wrote: > > 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. >=20 > I think it is worth mentioning that we=E2=80=99re using PG 9.2, so I don= =E2=80=99t benefit from features like logical replication to help with back= ups and such. > (Yes, I know it=E2=80=99s old and that I should upgrade ASAP. We=E2=80=99= re working on it) You'll certainly want to upgrade, of course. That said, logical replication isn't for backups, so not sure how that's relevant here. > The snapshots are done this way: > 1. Grab the latest applied WAL File for further references, stores that i= n a variable in Bash > 2. Stop the Postgres process How is PostgreSQL stopped here..? > 3. Check it is stopped > 4. Start the Block level EBS Snapshot process > 5. Applied tags to the snapshot, such as the WAL file from Step #1 > 6. Wait for snapshot to complete, querying the AWS API for that > 7. Start PG > 8. Check it is started > 9. Check it is replicating from master This doesn't explain how the snapshot is restored. That's a huge part of making sure that any process is implemented properly. > The entire process takes around 10 minutes to complete. Having the database offline for 10 minutes is a luxury that many don't have; I'm a bit surprised that it's not an issue here, but if it isn't, then that's great. As noted down-thread though, if you stop PostgreSQL cleanly in step #2 (that is, either 'fast' or 'smart' shutdown modes are used) then you don't need to do anything else, a 'shutdown' checkpoint will have been written into the WAL that is included in the snapshot and everything should be good. Note that this presumes that the snapshot above includes the entire PG data directory, all tablespaces, and the WAL. If that's not the case then more discussion would be needed. > I copy the WAL files to S3 in case I ever need to restore an old snapshot= (we keep snapshots for 30 days), which won=E2=80=99t have the WAL files in= the volume itself. Also for safety reasons, after reading this article many many times. If the database has been cleanly shut down and the pg_wal (pg_xlog) directory of the running database is included in that snapshot then you don't need any other WAL in order to be able to restore an individual snapshot. If you want to be able to perform PITR (Point-In-Time-Recovery, which you can play forward through the WAL to any point in time that you want to restore to without having to pick one of the snapshots) then you would want to archive *all* of your WAL using archive_command and a tool like pgbackrest. > We=E2=80=99re working on a migration to PG 14 so, please, feel free to su= ggest another best way to achieve this, but it would be better in a new thr= ead I reckon. It isn't terribly clear what you're actually looking for in terms of capability and so it's kind of hard to suggest something to "achieve this". Having snapshots taken while the database is down and then talking about copying WAL files to s3 to restore those snapshots doesn't strike me as making much sense though and I'd worry about other misunderstandings around how PG writes data and how WAL is handled and how to properly perform PG backups (online and offline) and restores. I'm afraid that this is a quite complicated area and reading blog posts about database outage postmortems (or even our own documentation, frankly) is rarely enough to be able to become an expert in writing tools for that purpose. Thanks, Stephen --9LnWyBss4uQTlezA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJhgB08AAoJEO1sijiDR2RVMIUP/A/fDuPetgmS1cuTkqBAeLSX Ff0OrDTGPcnMFK4gq+6KNUfF7v9cMaDGTsSfyNZL+lgX1oKiV3h9CqskspFRRZ5f Ti06+oYtQcPJj2QOV7CrcwiKQHOlrVbOvA/2dKNjETUIgTyVITrhRZ6MGyVV06r7 0iiCEmBVUZX9uQl/ef6DaAX7khuCq573CfXuXwqbSVyl3sGbvrpao6dzP/WFl2cY aG8DvnUktSCA/+xsuFrdz7S8liXqM4d09+KCTZOH+kxUCzB8neGwPD8kKDeuhv8r xR/1MzN/vweBN9afHvPIsaL0y7TgrwOQY2i+cpuNGQJfyJwQZB7+8a2PMOdkt2CI +IkKVYvW9uLoMIOfVJxIA4nrhuwON7rih3sSSpTtCLAmL0ye/ROS5bA92f+kNhpj VnZ95daOo65RZiXk3Yc6VS2RXLAkr9FCtvujQq6CNRoFcZLvXJFCNWQWFK2JwIyu WfTnzXzNAZ32yGPFSxbTaTW9hrCU9pV9iEsz2k2bFhFghAF+/cJNqvkZemekNEbw GFMtwTmMaxMSTYH+NgDbaekNzHW729MHV+zT7oCSZYp1c24IH+g8y7oG9/HAZ0hn jIRN+LqI89jPkL13PTa9OQvq9MKJUa2otUTTLQVTlqTJW/T5oobvwNu9az+oEHMg LZtTv/lTEWjlymw0br1R =QMpD -----END PGP SIGNATURE----- --9LnWyBss4uQTlezA--