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 1jdaRZ-0004Q4-BU for pgsql-general@arkaria.postgresql.org; Tue, 26 May 2020 14:20:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jdaRY-0007jv-8m for pgsql-general@arkaria.postgresql.org; Tue, 26 May 2020 14:20:36 +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 1jdaRY-0007jn-0V for pgsql-general@lists.postgresql.org; Tue, 26 May 2020 14:20:36 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jdaRU-0004BY-Uw for pgsql-general@postgresql.org; Tue, 26 May 2020 14:20:34 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 0DA645F79E; Tue, 26 May 2020 10:20:31 -0400 (EDT) Date: Tue, 26 May 2020 10:20:30 -0400 From: Stephen Frost To: Christopher Pereira Cc: pgsql-general@postgresql.org Subject: Re: pg_basebackup + incremental base backups Message-ID: <20200526142030.GD3418@tamriel.snowman.net> References: <514b14cb-f0b8-157b-2755-d5170ed4d24b@imatronix.cl> <20191204030907.GB6962@tamriel.snowman.net> <367ee69d-9dc7-4de6-f8a1-b460567bcc07@imatronix.cl> <20200521124303.GV3418@tamriel.snowman.net> <03f63a68-14be-978a-ccc8-177a84f115a5@imatronix.cl> <20200524194833.GW3418@tamriel.snowman.net> <6c18a547-f2f3-74b7-32ad-f44cfaef10e3@imatronix.cl> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="UxbNYeHgyZbry9TP" Content-Disposition: inline In-Reply-To: <6c18a547-f2f3-74b7-32ad-f44cfaef10e3@imatronix.cl> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --UxbNYeHgyZbry9TP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Christopher Pereira (kripper@imatronix.cl) wrote: > On 24-May-20 15:48, Stephen Frost wrote: > >That really shouldn't be possible. I'm very curious as to exactly what > >happened that resulted in your primary/replica being 'out of sync', as > >you say. >=20 > Actually this was more a hypothetical question to find a solution in case > some day one of our standby clusters goes out of sync and we have to rebu= ild > it having a very big database. "out of sync" is a bit of an odd concept, but having a replica fall behind a long way is certainly something that can happen and may require a rebuild from a backup (or from a new sync off of the primary in some other way, as you suggest below). In a situation where there's async replication happening and you promote a replica to take over, that's definitely a case where you might also have to rebuild the former primary. > With proper WAL archiving this shouldn't happen but we wanted to be prepa= red > for this scenario just in case. Sure, having WAL archiving and good backups is definitely my strong recommendation for how to address any cases where the replica falls behind, or the replica is promoted and you want to remaster the former primary. > We did some tests measuring IO and traffic and are very happy with the > results. We will definitely be adding pgBackRest to our toolchain. Glad to hear that. > Regarding my initial question, I still believe that the world deserves a > simple direct pg_basebackup replacement even when putting an additional > "repo host" in the middle is a better idea in the long term. Perhaps.. > As you said, all the pieces are there and it would be quite easy to write= a > new "pg_basebackup_delta" script that could be executed on the standby ho= st > to: >=20 > 1) setup a pgBackRest repo on the primary host (via SSH) >=20 > 2) create a backup on the primary host (via SSH) >=20 > 3) do a delta restore on the standby >=20 > Even when the repository on the primary host is only created temporarily > (and require double storage, resources, etc), it may still be worth > considering the traffic that can be saved by doing a delta restore on a > standby host in a different region, right? So... There's actually a way to do this with pgbackrest, but it doesn't support the delta capability. We take care in pgbackrest to make the repo format for full backups actually match exactly what a PG cluster would look like, specifically because we wish to allow users to, if absolutely everything else fails and pgbackrest is non-functional, rebuild from the repo. To that point, we even make sure that command-line tools like gzip, bzip2, openssl, etc, work with the files we create. For what you're asking about though, you would do something like: - Set up a pgbackrest repo on the host you're rebuilding (the replica) - Disable all repo compression, encryption, et al. - Enable archive copy, so the WAL for the backup is put into the backup - Enable parallel jobs - Set up pgbackrest on the primary with the replica configured as the repo host, get WAL archiving working and such. - Run create-stanza - Perform a *full* backup, make sure everything works. Once that's done, you go find the pg_data directory inside the full backup that you made inside of the pgbackrest repo, copy/move/rsync (with checksums enabled!) that to where your PG data directory should be, set up a recovery.conf to point to the primary, maybe also set it up with a restore_command pointing to that repo (may or may not be needed, depending) and start up PG. That should allow PG to start, replay all of the necessary WAL, and then connect to the primary and start streaming. If you have any tablespaces, you'd need to deal with those too, of course. If you start moving things out of the pgbackrest repo, you're corrupting it, naturally, so you wouldn't really want to continue using it once you've gotten all of this done. Again, this isn't an approach which I'd generally recommend... We used to do it when we were first writing pgbackrest with a ZFS filesystem and after a backup we'd create a snapshot off of the repo and start PG right up and then run pg_dump on it and do other checks to make sure it worked, but have moved to using pgbackrest delta restores instead for that kind of use-case. Thanks, Stephen --UxbNYeHgyZbry9TP Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJezSWuAAoJEO1sijiDR2RVXTkP/iEB4yOZBiu0pzPKk/CKTo67 krZOc0iEh1JjSiGa9qVa2MIZRffss+KG+qGqs5pPPAjbjcbx9y4lhzwSypWW8qQb fzUX31Oeee7wy9oI6exeKBQmDpxcfouS82zoSTkBLMRwsr+wltDwgQyu5xdd/YnM f7aFNQA+fvO0LK6/mUrjudjXSzdDxtFLqjs2EORxi8zdTLE1DQSR+zfhcPj0kQTK 8lj2g36DCFV9GWiPYn25kfg3KJ4aHZUEJxfrdI2ow9qB2c0YWFrpNSWjaJ9iwzzb NjEitKMF5jt7IxHWn2y4ZpBediaJ08/mYDHG+kVNw/uBPyK7tPeIx3KCFfOr5Frh gfo8cOzCIRHOwx3vX+I2hlbizZqbl4JXTKrTBcspoEumGDuLAhlNA9c8M8ohefXR s1JRsw4pkfMj/rjLqhl0ZN6QY9ZY057854seuGagMioEeR+i5DQWOW36jD5Rg0UJ Bc4NpdzFm551Zricw9/iN7Fuh+lRmcMNoZU5sDfYq83xrlnEebT8AbTUmMFKV3xs 6MVa/vr5SL5K16z8lq905shPsd9+Y11NJcCNBkiv42kOPg7U1kZ58zQOaOoxfCfT IYpdOD4GVZXrIi1NKxegfg0fnauolYApfWH4vmRq7RSNjaEzLIfmzpsyoOYbPrNJ O/LLqBGpm0RJCl6CvUWo =E6cv -----END PGP SIGNATURE----- --UxbNYeHgyZbry9TP--