Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fKneF-0007Eb-4m for pgsql-general@arkaria.postgresql.org; Mon, 21 May 2018 16:26:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fKneD-00061j-Rf for pgsql-general@arkaria.postgresql.org; Mon, 21 May 2018 16:26:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fKneD-00061Y-KE for pgsql-general@lists.postgresql.org; Mon, 21 May 2018 16:26:57 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fKne5-0002h4-Mm for pgsql-general@postgresql.org; Mon, 21 May 2018 16:26:56 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 8248D5F79F; Mon, 21 May 2018 12:26:48 -0400 (EDT) Date: Mon, 21 May 2018 12:26:48 -0400 From: Stephen Frost To: Yashwanth Govinda Setty Cc: "pgsql-general@postgresql.org" Subject: Re: Will Altering and Modifying tables during backup result in a corrupted server after the restore? Message-ID: <20180521162648.GC27724@tamriel.snowman.net> References: <4a42c6eb5542496ba13944c95e848325@POST-1.gp.cv.commvault.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="OksffZMn7kG6MWuy" Content-Disposition: inline In-Reply-To: <4a42c6eb5542496ba13944c95e848325@POST-1.gp.cv.commvault.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --OksffZMn7kG6MWuy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Yashwanth Govinda Setty (ygovindasetty@commvault.com) wrote: > 1. Creating a big table. Identify the physical file on the disk. > 1. While backup process is backing up a file associated with the table -= update the rows , add a column. > 2. Restore the server with transaction logs >=20 > We are backing up (copying) the entire postgres data directory. The datab= ase/table file being backed up (copied), is modified by running alter/updat= e queries on the table. > When we restore the copied data directory and replay/apply the transactio= n logs, will the server be restored to an healthy state? You haven't really spelled out your actual backup process but it certainly sounds like it's lacking. > (The files modified during backup can be corrupted, will this affect the = restore?) With a proper PG-style filesystem-backup, any corruption due to ongoing writes from PG will be handled by the transaction log. To perform a proper PG-style filesystem-backup, you need to: - Ensure that WAL is being archived somewhere. This can be done with archive_command or with pg_receivewal. All WAL archived during the backup *must* be saved or the backup will be inconsistent and incomplete (and, therefore, basically useless). - Make sure to run pg_start_backup() before you begin copying *any* files - Make sure to run pg_stop_backup() after you have copied all files - Verify that all of the WAL generated between the pg_start_backup() call and the pg_stop_backup() call have been archived. The information about what WAL is needed is returned from those calls. - On restore, create and populate the backup_label file in the data directory to indicate that it was a backup being restored. (Alternatively, create that file during the backup itself and store it in the backup system, to be restored when the backup is restored). Ideally, you'd also verify the page-level checksums (if they're enabled) when doing the backup, calculate your own checksum of the file (to detect if it gets corrupted between the backup time and the restore time) and verify that everything is physically written out to permanent storage before claiming to have a successful backup. Further information is available here: https://www.postgresql.org/docs/current/static/continuous-archiving.html#BA= CKUP-BASE-BACKUP Generally speaking, however, I would strongly discourage people from trying to write yet-another-PG-backup-tool, there are several already, my favorite being pgbackrest, and contributing to one of them would be a better approach. Thanks! Stephen --OksffZMn7kG6MWuy Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJbAvNIAAoJEO1sijiDR2RVQAAQAMe9EhU3gjMBBV+N53aUN3w8 XAypOGKdSd3wJrgN7W+cL7n8aMUY6CaXQs0DDdmMsafdggbzzCibxffKwH89UcOy WVmfaB59g2P2cBLeNpWTt/6X2SpWRsrsVTF0T9fxPLPzSZm2VXJxlZOGMrZ+vyKO WkFGTVlcAy3kQSABr2CLapewXNqwYETI/ZzS3sXgEaQ4k531cqYGXrEeO7Ms0thq iksLnLsLcuemO4+zzQPY932krfpQb3t1AB+DKaL86n+3VSwcQ1mZQ7ad+li8zmnT k8noeZpcopAg8cDhuMGnd3vxQX/x5oinC5hDhiVgJl+bmtTlr0Jjz7RJ6K6aMPAV pCnjUR8mS4Pn/3Jbk+GfKnJleDi87AI0PzM0PJBNHohL+f+N4QGhffIXN0B+/RWL PY+JUjirEhN43uYlZOtyxhg1bYoRt4E9SGXdP4dF4nq+awYnLh1L8qkUqZ6gMdH5 oqEjZZySwsgm0BJxWjjkVmPcifvTw8/QC337pAkFQJ0A/GtoqEenTItnFLHvMivG QPzk9hVvzzZ9y2zbqk9a5jKuWGEdsQooQFBc87nEOe3xRDWotg0w+VSh5c3xL8tz tz5dQV2KJzvOzugntIL5JD1VyOBc9MWCSMCipI/IVoIa6HBats7Ev/LeIwdarMBS 1zZjSMYhdVoQ3c1xqIDy =HKYk -----END PGP SIGNATURE----- --OksffZMn7kG6MWuy--