From enio@pmpf.rs.gov.br Fri Aug 8 18:01:06 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 75DCED1C9A6 for ; Fri, 8 Aug 2003 18:01:06 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 62437-10 for ; Fri, 8 Aug 2003 14:59:37 -0300 (ADT) Received: from mail.passofundo.rs.gov.br (unknown [200.182.187.131]) by svr1.postgresql.org (Postfix) with ESMTP id 0CAE1D1C91F for ; Fri, 8 Aug 2003 15:00:46 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.passofundo.rs.gov.br (Postfix) with ESMTP id 1D5EC46E25 for ; Fri, 8 Aug 2003 14:56:01 -0300 (BRT) Received: from compaq (unknown [10.0.5.226]) by mail.passofundo.rs.gov.br (Postfix) with SMTP id 43A6E46E22 for ; Fri, 8 Aug 2003 14:55:59 -0300 (BRT) Message-ID: <000c01c35dd6$d62b43d0$e205000a@compaq> From: "Enio Schutt Junior" To: Subject: Backup routine Date: Fri, 8 Aug 2003 14:59:39 -0300 Organization: pmpf MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0009_01C35DBD.B0C3CD10" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Virus-Scanned: by AMaViS perl-11 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=1.5 tagged_above=0.0 required=5.0 tests=HTML_20_30 X-Spam-Level: * X-Archive-Number: 200308/124 X-Sequence-Number: 9846 This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C35DBD.B0C3CD10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Here, where I work, the backups of the postgresql databases are being done = the following way: There is a daily copy of nearly all the hd (excluding /tmp, /proc, /dev and= so on) in which databases are=20 and besides this there is also one script which makes the pg_dump of each o= ne of the databases on the server. This daily copy of the hd is made with postmaster being active (without sto= pping the daemon), so the data from /usr/local/pgsql/data would not be 100% consistent, I guess.=20 Supposing there was a failure and it was needed to restore the whole thing,= I think the procedure to recovery would be the following: 1) Copy data from the backup hd to a new hd 2) Once this was done, delete the postmaster.pid file and start the postmas= ter service 3) Drop all databases and recreate them from those pg_dump files There are some questions I have about this backup routine: If I recover data from that "inconsistent" backup hd, I know that the binar= y files (psql, pg_dump and so on) will remain ok. The data may have some inconsistencies. Would these inconsi= stencies let the postmaster start and work properly (that is, even with the possible presence of incons= istent data) Would it start and be able to work normally and keep the information about users and groups? I= am talking about users and groups information because these ones are not dumped by pg_dump. I was thin= king about using=20 "pg_dump -g" to generate this information. I was also thinking about excluding /usr/local/pgsql/data from the backup r= outine, as the data is also in other files generated by pg_dump. The problem is that this director= y has not only the databases data but also some config files, like postgresql.conf. Opinions are welcome. ------=_NextPart_000_0009_01C35DBD.B0C3CD10 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi
 
Here, where I work, the backups of the pos= tgresql=20 databases are being done the following way:
There is a daily copy of nearly all the hd= =20 (excluding /tmp, /proc, /dev and so on) in which databases are
and besides this there is also one script which makes the pg_dump of each one of the= =20 databases on the server.
This daily copy of the hd is made with pos= tmaster=20 being active (without stopping the daemon), so the data
from /usr/local/pgsql/data would not be 10= 0%=20 consistent, I guess.
Supposing there was a failure and it was n= eeded to=20 restore the whole thing, I think the procedure to
recovery would be=20 the following:
1) Copy data from the backup hd to a new= =20 hd
2) Once this was done, delete the=20 postmaster.pid file and start the postmaster service
3) Drop all databases and recreate th= em from=20 those pg_dump files
 
There are some questions I have about this= backup=20 routine:
If I recover data from that "inconsistent"= backup=20 hd, I know that the binary files (psql, pg_dump and so on)
will remain ok. The data may have some=20 inconsistencies. Would these inconsistencies let the postmaster
start and work properly (that is, even wit= h the=20 possible presence of inconsistent data) Would it start and
be able to work normally and keep the info= rmation=20 about users and groups? I am talking about users and
groups information because these ones are = not=20 dumped by pg_dump. I was thinking about using
"pg_dump -g" to generate this=20 information.
 
I was also thinking about excluding=20 /usr/local/pgsql/data from the backup routine, as the data is
also in other files generated by pg_dump. = The=20 problem is that this directory has not only the databases
data but also some config files, like=20 postgresql.conf.
 
Opinions are welcome.
<= /HTML> ------=_NextPart_000_0009_01C35DBD.B0C3CD10-- From tgl@sss.pgh.pa.us Sat Aug 9 15:34:10 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 18257D1C4C8 for ; Sat, 9 Aug 2003 15:34:10 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 80940-01 for ; Sat, 9 Aug 2003 12:32:39 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 1D8F4D1C9D5 for ; Sat, 9 Aug 2003 12:33:59 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h79FXfSa005778; Sat, 9 Aug 2003 11:33:41 -0400 (EDT) To: "Enio Schutt Junior" Cc: pgsql-admin@postgresql.org Subject: Re: Backup routine In-reply-to: <000c01c35dd6$d62b43d0$e205000a@compaq> References: <000c01c35dd6$d62b43d0$e205000a@compaq> Comments: In-reply-to "Enio Schutt Junior" message dated "Fri, 08 Aug 2003 14:59:39 -0300" Date: Sat, 09 Aug 2003 11:33:41 -0400 Message-ID: <5777.1060443221@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/129 X-Sequence-Number: 9851 "Enio Schutt Junior" writes: > Here, where I work, the backups of the postgresql databases are being done = > the following way: > There is a daily copy of nearly all the hd (excluding /tmp, /proc, /dev and= > so on) in which databases are=20 > and besides this there is also one script which makes the pg_dump of each o= > ne of the databases on the server. > This daily copy of the hd is made with postmaster being active (without sto= > pping the daemon), so the data > from /usr/local/pgsql/data would not be 100% consistent, I guess.=20 > Supposing there was a failure and it was needed to restore the whole thing,= > I think the procedure to > recovery would be the following: > 1) Copy data from the backup hd to a new hd > 2) Once this was done, delete the postmaster.pid file and start the postmas= > ter service > 3) Drop all databases and recreate them from those pg_dump files I would just initdb and then load the pg_dump files. An unsynchronized copy of /usr/local/pgsql/data is just about completely untrustworthy. You should use pg_dumpall to make a dump of user and group status; pg_dump will not do that. > I was also thinking about excluding /usr/local/pgsql/data from the > backup routine, as the data is also in other files generated by > pg_dump. The problem is that this directory has not only the databases > data but also some config files, like postgresql.conf. Yeah. Instead, exclude the directories below it ($PGDATA/base, etc). regards, tom lane From peterandsarah@blueyonder.co.uk Sat Aug 9 16:10:10 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id C22BBD1C939 for ; Sat, 9 Aug 2003 16:10:10 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 81233-09 for ; Sat, 9 Aug 2003 13:08:39 -0300 (ADT) Received: from smtp.blueyonder.co.uk (pc-62-30-143-217-gl.blueyonder.co.uk [62.30.143.217]) by svr1.postgresql.org (Postfix) with ESMTP id 4AD9FD1C4E1 for ; Sat, 9 Aug 2003 13:09:59 -0300 (ADT) Received: from reddragon.localdomain ([127.0.0.1]) by smtp.blueyonder.co.uk with esmtp (Exim 4.10) id 19lWJY-0002TY-00 for pgsql-admin@postgresql.org; Sat, 09 Aug 2003 17:11:32 +0100 From: Peter and Sarah Childs To: Subject: Re: Backup routine Date: Sat, 9 Aug 2003 17:11:31 +0100 User-Agent: KMail/1.5 References: <000c01c35dd6$d62b43d0$e205000a@compaq> In-Reply-To: <000c01c35dd6$d62b43d0$e205000a@compaq> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308091711.31439.peterandsarah@blueyonder.co.uk> X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=3.8 tagged_above=0.0 required=5.0 tests=EMAIL_ATTRIBUTION, IN_REP_TO, QUOTED_EMAIL_TEXT, RCVD_IN_DSBL, RCVD_IN_NJABL, REFERENCES, REPLY_WITH_QUOTES, USER_AGENT X-Spam-Level: *** X-Archive-Number: 200308/131 X-Sequence-Number: 9853 On Friday 08 August 2003 18:59, Enio Schutt Junior wrote: > Hi > > Here, where I work, the backups of the postgresql databases are being done > the following way: There is a daily copy of nearly all the hd (excluding > /tmp, /proc, /dev and so on) in which databases are and besides this there > is also one script which makes the pg_dump of each one of the databases on > the server. This daily copy of the hd is made with postmaster being active > (without stopping the daemon), so the data from /usr/local/pgsql/data would > not be 100% consistent, I guess. > Supposing there was a failure and it was needed to restore the whole thing, > I think the procedure to recovery would be the following: > 1) Copy data from the backup hd to a new hd > 2) Once this was done, delete the postmaster.pid file and start the > postmaster service 3) Drop all databases and recreate them from those > pg_dump files > > There are some questions I have about this backup routine: > If I recover data from that "inconsistent" backup hd, I know that the > binary files (psql, pg_dump and so on) will remain ok. The data may have > some inconsistencies. Would these inconsistencies let the postmaster start > and work properly (that is, even with the possible presence of inconsistent > data) Would it start and be able to work normally and keep the information > about users and groups? I am talking about users and groups information > because these ones are not dumped by pg_dump. I was thinking about using > "pg_dump -g" to generate this information. > > I was also thinking about excluding /usr/local/pgsql/data from the backup > routine, as the data is also in other files generated by pg_dump. The > problem is that this directory has not only the databases data but also > some config files, like postgresql.conf. > In most cases so long as you have not actually had a hard disk failure. When postgres comes up after it has crashed, it uses its WAL logs to clean up the database. So If your machine crashes with out hard disk failure you database should come up fine. If you have had a disk failure. The problem is that the beginning of the database may be backed up before the end. So you will need to use the dump. ie WAL logs may not agree with database and Table A not agree with Table B etc. Hence the general advise is bring it up from dump. The database will either come up so you can drop the databases or failure badly in which case you can always work out whats gone wrong and work round it. However there is a third way. That should be safe but some people may disagree with me! If you can "freeze" the disk while you take the backup. The backup can be used as if the computer had crashed with no hard disk failure at all. Ie WAL will be consistant and database may take longer but once it is up it will be safe (like paragaph 1). Now freezeing a disk for backup is not that difficult. You should be doing it anyway for user file consistancy. (You don't want the first 30 pages of you document to disagree with the end because somone was saving it during the backup! Freezing a disk can be done with LVM for example. http://www.tldp.org/HOWTO/LVM-HOWTO/ and is not difficult. RAID can also be used to avoid disk failure in the first place. Always however keep a dump as the dump will be your only way out if your basic sanity checks fail! Peter Childs From cbbrowne@acm.org Sun Aug 10 03:47:03 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 08861D1C9BE for ; Sun, 10 Aug 2003 03:47:03 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 14041-04 for ; Sun, 10 Aug 2003 00:45:35 -0300 (ADT) Received: from news.hub.org (news.hub.org [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id 71CFFD1F462 for ; Sat, 9 Aug 2003 23:07:26 -0300 (ADT) Received: from news.hub.org (news.hub.org [64.117.224.194]) by news.hub.org (8.12.9/8.12.9) with ESMTP id h7A27Pw6020446 for ; Sun, 10 Aug 2003 02:07:26 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h7A1wJC6018454 for pgsql-admin@postgresql.org; Sun, 10 Aug 2003 01:58:19 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.admin Subject: Re: Backup routine Date: Sat, 09 Aug 2003 21:19:10 -0400 Organization: cbbrowne Computing Inc Lines: 26 Message-ID: References: <000c01c35dd6$d62b43d0$e205000a@compaq> <200308091711.31439.peterandsarah@blueyonder.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne X-Emacs-Acronym: Elsewhere Maybe Alternative Civilizations Survive Microsoft: Where even the version numbers aren't Y2K-compliant X-Uboat-Death-Message: TORPEDOED BY ATOMIC BOMB. DEPTH CHARGES. SINKING. U-539. User-Agent: Gnus/5.1003 (Gnus v5.10.3) XEmacs/21.4 (Rational FORTRAN, linux) Cancel-Lock: sha1:I83uD7JkOkdU+n2sNeIg8CvDd/U= To: pgsql-admin@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/133 X-Sequence-Number: 9855 The world rejoiced as peterandsarah@blueyonder.co.uk (Peter and Sarah Childs) wrote: > However there is a third way. That should be safe but some > people may disagree with me! If you can "freeze" the disk while you > take the backup. The backup can be used as if the computer had > crashed with no hard disk failure at all. Ie WAL will be consistant > and database may take longer but once it is up it will be safe (like > paragaph 1). Now freezeing a disk for backup is not that > difficult. You should be doing it anyway for user file > consistancy. (You don't want the first 30 pages of you document to > disagree with the end because somone was saving it during the > backup! I heard D'Arcy Cain indicate that some SAN systems (I think he mentioned NetApp) support this sort of thing, too. Digital's AdvFS also supports it. Of course, if you take this approach, you have to make _certain_ that when you "freeze" a replica of a filesystem, that _ALL_ of the database is contained in that one filesystem. If you move WAL to a different filesystem, bets would be off again... -- let name="cbbrowne" and tld="ntlug.org" in String.concat "@" [name;tld];; http://www3.sympatico.ca/cbbrowne/ The real problem with the the year 2000 is that there are too many zero bits and that adversely affects the global bit density. -- Boyd Roberts From pgman@candle.pha.pa.us Mon Aug 11 03:12:40 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 0CDF9D1C4D9 for ; Mon, 11 Aug 2003 03:12:40 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 39862-02 for ; Mon, 11 Aug 2003 00:11:10 -0300 (ADT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id 79D6AD1C910 for ; Mon, 11 Aug 2003 00:12:26 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h7B3CA106392; Sun, 10 Aug 2003 23:12:10 -0400 (EDT) From: Bruce Momjian Message-Id: <200308110312.h7B3CA106392@candle.pha.pa.us> Subject: Re: Backup routine In-Reply-To: <5777.1060443221@sss.pgh.pa.us> To: Tom Lane Date: Sun, 10 Aug 2003 23:12:10 -0400 (EDT) Cc: Enio Schutt Junior , pgsql-admin@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/138 X-Sequence-Number: 9860 Tom Lane wrote: > "Enio Schutt Junior" writes: > > Here, where I work, the backups of the postgresql databases are being done = > > the following way: > > There is a daily copy of nearly all the hd (excluding /tmp, /proc, /dev and= > > so on) in which databases are=20 > > and besides this there is also one script which makes the pg_dump of each o= > > ne of the databases on the server. > > This daily copy of the hd is made with postmaster being active (without sto= > > pping the daemon), so the data > > from /usr/local/pgsql/data would not be 100% consistent, I guess.=20 > > Supposing there was a failure and it was needed to restore the whole thing,= > > I think the procedure to > > recovery would be the following: > > 1) Copy data from the backup hd to a new hd > > 2) Once this was done, delete the postmaster.pid file and start the postmas= > > ter service > > 3) Drop all databases and recreate them from those pg_dump files > > I would just initdb and then load the pg_dump files. An unsynchronized > copy of /usr/local/pgsql/data is just about completely untrustworthy. > > You should use pg_dumpall to make a dump of user and group status; > pg_dump will not do that. > > > I was also thinking about excluding /usr/local/pgsql/data from the > > backup routine, as the data is also in other files generated by > > pg_dump. The problem is that this directory has not only the databases > > data but also some config files, like postgresql.conf. > > Yeah. Instead, exclude the directories below it ($PGDATA/base, etc). Yes, but if he restores everything but /base, he gets xlog and clog, and other stuff he shouldn't be restoring. This is why I would like the config files move into a separate directory under /data. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From pgman@candle.pha.pa.us Mon Aug 11 03:13:25 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 25C22D1C910 for ; Mon, 11 Aug 2003 03:13:25 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 32600-10 for ; Mon, 11 Aug 2003 00:11:55 -0300 (ADT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id 7A71AD1C4E3 for ; Mon, 11 Aug 2003 00:13:13 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h7B3DCv06482; Sun, 10 Aug 2003 23:13:12 -0400 (EDT) From: Bruce Momjian Message-Id: <200308110313.h7B3DCv06482@candle.pha.pa.us> Subject: Re: Backup routine In-Reply-To: To: Christopher Browne Date: Sun, 10 Aug 2003 23:13:12 -0400 (EDT) Cc: pgsql-admin@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/137 X-Sequence-Number: 9859 Christopher Browne wrote: > The world rejoiced as peterandsarah@blueyonder.co.uk (Peter and Sarah Childs) wrote: > > However there is a third way. That should be safe but some > > people may disagree with me! If you can "freeze" the disk while you > > take the backup. The backup can be used as if the computer had > > crashed with no hard disk failure at all. Ie WAL will be consistant > > and database may take longer but once it is up it will be safe (like > > paragaph 1). Now freezeing a disk for backup is not that > > difficult. You should be doing it anyway for user file > > consistancy. (You don't want the first 30 pages of you document to > > disagree with the end because somone was saving it during the > > backup! > > I heard D'Arcy Cain indicate that some SAN systems (I think he > mentioned NetApp) support this sort of thing, too. Digital's AdvFS > also supports it. > > Of course, if you take this approach, you have to make _certain_ that > when you "freeze" a replica of a filesystem, that _ALL_ of the > database is contained in that one filesystem. If you move WAL to a > different filesystem, bets would be off again... Also, I assume you have to stop the server just for a moment while you do the freeze, right? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From cbbrowne@acm.org Mon Aug 11 03:48:46 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 850DDD1C4D9 for ; Mon, 11 Aug 2003 03:48:46 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 39396-06 for ; Mon, 11 Aug 2003 00:47:16 -0300 (ADT) Received: from news.hub.org (news.hub.org [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id AB921D1C4D6 for ; Mon, 11 Aug 2003 00:48:35 -0300 (ADT) Received: from news.hub.org (news.hub.org [64.117.224.194]) by news.hub.org (8.12.9/8.12.9) with ESMTP id h7B3mZek005515 for ; Mon, 11 Aug 2003 03:48:35 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h7B3afDg003738 for pgsql-admin@postgresql.org; Mon, 11 Aug 2003 03:36:41 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.admin Subject: Re: Backup routine Date: Sun, 10 Aug 2003 23:36:10 -0400 Organization: cbbrowne Computing Inc Lines: 53 Message-ID: References: <200308110313.h7B3DCv06482@candle.pha.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne X-Emacs-Acronym: Evenings, Mornings, And a Couple of Saturdays Microsoft: With our software, there's no limit to what you can't do! X-Uboat-Death-Message: CLICKED BY FIVE CARRIERS. ENGAGING VALIUM NOZZLE. U-576. User-Agent: Gnus/5.1003 (Gnus v5.10.3) XEmacs/21.4 (Rational FORTRAN, linux) Cancel-Lock: sha1:d1dRXD/HmH4vJSrhZcptBwC8RCA= To: pgsql-admin@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/147 X-Sequence-Number: 9869 Centuries ago, Nostradamus foresaw when pgman@candle.pha.pa.us (Bruce Momjian) would write: > Christopher Browne wrote: >> The world rejoiced as peterandsarah@blueyonder.co.uk (Peter and Sarah Childs) wrote: >> > However there is a third way. That should be safe but some >> > people may disagree with me! If you can "freeze" the disk while you >> > take the backup. The backup can be used as if the computer had >> > crashed with no hard disk failure at all. Ie WAL will be consistant >> > and database may take longer but once it is up it will be safe (like >> > paragaph 1). Now freezeing a disk for backup is not that >> > difficult. You should be doing it anyway for user file >> > consistancy. (You don't want the first 30 pages of you document to >> > disagree with the end because somone was saving it during the >> > backup! >> >> I heard D'Arcy Cain indicate that some SAN systems (I think he >> mentioned NetApp) support this sort of thing, too. Digital's AdvFS >> also supports it. >> >> Of course, if you take this approach, you have to make _certain_ >> that when you "freeze" a replica of a filesystem, that _ALL_ of the >> database is contained in that one filesystem. If you move WAL to a >> different filesystem, bets would be off again... > > Also, I assume you have to stop the server just for a moment while > you do the freeze, right? I'm sure that's _preferable_. Supposing you don't, the result is that the backup will be treated much like the condition where a server is "terminated by power failure," and, at restart, the system will have to rummage around the WAL to clean up a bit. Obviously not what you'd want, in an _ideal_ world, but it fits into what WAL is supposed to be able to protect against, right? If-and-when PITR gets into place, I'd think one a valued feature would be the notion of being able to signal the postmaster to tell it to close off a WAL and open a new one (even though we might not strictly be due for it). (Note that the "O-guys" can do something like this with their "archive logs.") If that signal can be submitted, then someone might be able to take this sort of "cloned filesystem" backup, and just drop off the last WAL file as irrelevant. That might not be quite exactly what's imminent for 7.5, mind you... -- select 'cbbrowne' || '@' || 'acm.org'; http://www.ntlug.org/~cbbrowne/sap.html (eq? 'truth 'beauty) ; to avoid unassigned-var error, since compiled code ; will pick up previous value to var set!-ed, ; the unassigned object. -- from BBN-CL's cl-parser.scm From tgl@sss.pgh.pa.us Mon Aug 11 14:36:01 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 2DD24D1C514 for ; Mon, 11 Aug 2003 14:36:01 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 04580-01 for ; Mon, 11 Aug 2003 11:34:35 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 1CB02D1C4E1 for ; Mon, 11 Aug 2003 11:35:50 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h7BEY9Sa002294; Mon, 11 Aug 2003 10:34:09 -0400 (EDT) To: Bruce Momjian Cc: Enio Schutt Junior , pgsql-admin@postgresql.org Subject: Re: Backup routine In-reply-to: <200308110312.h7B3CA106392@candle.pha.pa.us> References: <200308110312.h7B3CA106392@candle.pha.pa.us> Comments: In-reply-to Bruce Momjian message dated "Sun, 10 Aug 2003 23:12:10 -0400" Date: Mon, 11 Aug 2003 10:34:09 -0400 Message-ID: <2293.1060612449@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/139 X-Sequence-Number: 9861 Bruce Momjian writes: > Tom Lane wrote: >> Yeah. Instead, exclude the directories below it ($PGDATA/base, etc). > Yes, but if he restores everything but /base, he gets xlog and clog, and > other stuff he shouldn't be restoring. That's why I said "etc". Only the loose files in the top-level directory are interesting. regards, tom lane From oderbolz@ecologic.de Mon Aug 11 16:18:07 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 10C44D1C4E7 for ; Mon, 11 Aug 2003 16:18:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 10376-10 for ; Mon, 11 Aug 2003 13:16:36 -0300 (ADT) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.188]) by svr1.postgresql.org (Postfix) with ESMTP id EA9BED1C4B9 for ; Mon, 11 Aug 2003 13:17:55 -0300 (ADT) Received: from [212.227.126.205] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 19mFMl-0002t9-00; Mon, 11 Aug 2003 18:17:51 +0200 Received: from [217.230.194.139] (helo=ecologic.de) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 19mFMk-0007cN-00; Mon, 11 Aug 2003 18:17:50 +0200 Message-ID: <3F37C1AD.5040709@ecologic.de> Date: Mon, 11 Aug 2003 18:17:49 +0200 From: Dani Oderbolz User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Enio Schutt Junior , "'pgsql-admin@postgresql.org'" Subject: Re: Backup routine References: <000c01c35dd6$d62b43d0$e205000a@compaq> In-Reply-To: <000c01c35dd6$d62b43d0$e205000a@compaq> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/140 X-Sequence-Number: 9862 Hi Enio, Enio Schutt Junior wrote: > Hi > > Here, where I work, the backups of the postgresql databases are being > done the following way: > There is a daily copy of nearly all the hd (excluding /tmp, /proc, > /dev and so on) in which databases are > and besides this there is also one script which makes the pg_dump of > each one of the databases on the server. Hmm, I don't really see what you are doing with a backup of /tmp, /proc, /dev/tmp, /proc, /dev. I mean /tmp might be ok, but /proc shouldnt be backuped in my opinion, as /proc is NOT on your hd, but pointing directly to Kernel Memory. I would not dare to restore such a Backup! And /dev as well, I mean, these are your devices, so its completely Hardwarebound. > This daily copy of the hd is made with postmaster being active > (without stopping the daemon), so the data > from /usr/local/pgsql/data would not be 100% consistent, I guess. You need to stop Postgres, else forget about your backup. The DB might not even come up again. Here at my site, we have a nice little script, which can be configured to do certain actions before doing a backup of a given directory, and also after the backup. > > There are some questions I have about this backup routine: > If I recover data from that "inconsistent" backup hd, I know that the > binary files (psql, pg_dump and so on) > will remain ok. The data may have some inconsistencies. Would these > inconsistencies let the postmaster > start and work properly (that is, even with the possible presence of > inconsistent data) Would it start and > be able to work normally and keep the information about users and > groups? I am talking about users and > groups information because these ones are not dumped by pg_dump. I was > thinking about using > "pg_dump -g" to generate this information. I would really not go down this road. Regards, Dani From dalgoda@ix.netcom.com Mon Aug 11 21:26:14 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 2618AD1C47A for ; Mon, 11 Aug 2003 21:26:14 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 37970-08 for ; Mon, 11 Aug 2003 18:24:39 -0300 (ADT) Received: from a.smtp-out.sonic.net (a.smtp-out.sonic.net [208.201.224.38]) by svr1.postgresql.org (Postfix) with SMTP id EC472D1C4DF for ; Mon, 11 Aug 2003 18:25:56 -0300 (ADT) Received: (qmail 18082 invoked from network); 11 Aug 2003 21:25:58 -0000 Received: from ultra.sonic.net (208.201.224.22) by a.smtp-out.sonic.net with SMTP; 11 Aug 2003 21:25:58 -0000 Received: from thune.mrc-home.org (adsl-209-204-178-126.sonic.net [209.204.178.126]) by ultra.sonic.net (8.11.6p2/8.8.5) with ESMTP id h7BLPPM05272 for ; Mon, 11 Aug 2003 14:25:25 -0700 X-envelope-info: Received: by thune.mrc-home.org (8.11.4) id h7BLPvp01226; Mon, 11 Aug 2003 14:25:57 -0700 Newsgroups: local.ml.postgresql.admin From: dalgoda@ix.netcom.com (Mike Castle) Subject: Re: Backup routine References: <200308110313.h7B3DCv06482@candle.pha.pa.us> Organization: House of Linux X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Path: not-for-mail Originator: nexus@thune.mrc.org (Mike Castle) Date: Mon, 11 Aug 2003 14:25:57 -0700 Message-ID: <58el01x9nv.ln2@thune.mrc-home.org> To: pgsql-admin@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/141 X-Sequence-Number: 9863 In article <200308110313.h7B3DCv06482@candle.pha.pa.us>, Bruce Momjian wrote: >Also, I assume you have to stop the server just for a moment while you >do the freeze, right? It depends on if you need known state or just consistent state. Taking a snapshot of the system will get you a consistent state just like if the machine crashed. You can restore that snapshot, bring PG back up and everything will work. Of course, you really have no way of knowing what transactions were commited and what were not. On the other hand, stop the server/snapshot/start the server gives you not only consistency, but a known state. That is, you know for sure that whatever was done before you stopped the server is what was done. Which approach is necessary for you depends on your needs, I as always. mrc -- Mike Castle dalgoda@ix.netcom.com www.netcom.com/~dalgoda/ We are all of us living in the shadow of Manhattan. -- Watchmen fatal ("You are in a maze of twisty compiler features, all different"); -- gcc From pgman@candle.pha.pa.us Mon Aug 11 22:15:08 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id A1AA8D1C47A for ; Mon, 11 Aug 2003 22:15:08 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 50225-06 for ; Mon, 11 Aug 2003 19:13:37 -0300 (ADT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id 572F5D1C4DF for ; Mon, 11 Aug 2003 19:14:51 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h7BMEkZ06017; Mon, 11 Aug 2003 18:14:46 -0400 (EDT) From: Bruce Momjian Message-Id: <200308112214.h7BMEkZ06017@candle.pha.pa.us> Subject: Re: Backup routine In-Reply-To: <58el01x9nv.ln2@thune.mrc-home.org> To: Mike Castle Date: Mon, 11 Aug 2003 18:14:46 -0400 (EDT) Cc: pgsql-admin@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/142 X-Sequence-Number: 9864 Oh, good point. By grabbing xlog along with the data files, you do get a consistent snapshot just like if it had crashed. --------------------------------------------------------------------------- Mike Castle wrote: > In article <200308110313.h7B3DCv06482@candle.pha.pa.us>, > Bruce Momjian wrote: > >Also, I assume you have to stop the server just for a moment while you > >do the freeze, right? > > It depends on if you need known state or just consistent state. > > Taking a snapshot of the system will get you a consistent state just like > if the machine crashed. You can restore that snapshot, bring PG back up > and everything will work. Of course, you really have no way of knowing > what transactions were commited and what were not. > > On the other hand, stop the server/snapshot/start the server gives you not > only consistency, but a known state. That is, you know for sure that > whatever was done before you stopped the server is what was done. > > Which approach is necessary for you depends on your needs, I as always. > > mrc > -- > Mike Castle dalgoda@ix.netcom.com www.netcom.com/~dalgoda/ > We are all of us living in the shadow of Manhattan. -- Watchmen > fatal ("You are in a maze of twisty compiler features, all different"); -- gcc > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From scott.marlowe@ihs.com Tue Aug 12 14:44:26 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 835FFD1C47A for ; Tue, 12 Aug 2003 14:44:26 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 70783-05 for ; Tue, 12 Aug 2003 11:42:56 -0300 (ADT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 7E905D1C4BF for ; Tue, 12 Aug 2003 11:44:15 -0300 (ADT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h7CEhVbS001484; Tue, 12 Aug 2003 08:43:31 -0600 (MDT) Date: Tue, 12 Aug 2003 08:44:28 -0600 (MDT) From: "scott.marlowe" To: Christopher Browne Cc: Subject: Re: Backup routine In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/148 X-Sequence-Number: 9870 On Sun, 10 Aug 2003, Christopher Browne wrote: > Centuries ago, Nostradamus foresaw when pgman@candle.pha.pa.us (Bruce Momjian) would write: > > Christopher Browne wrote: > >> The world rejoiced as peterandsarah@blueyonder.co.uk (Peter and Sarah Childs) wrote: > >> > However there is a third way. That should be safe but some > >> > people may disagree with me! If you can "freeze" the disk while you > >> > take the backup. The backup can be used as if the computer had > >> > crashed with no hard disk failure at all. Ie WAL will be consistant > >> > and database may take longer but once it is up it will be safe (like > >> > paragaph 1). Now freezeing a disk for backup is not that > >> > difficult. You should be doing it anyway for user file > >> > consistancy. (You don't want the first 30 pages of you document to > >> > disagree with the end because somone was saving it during the > >> > backup! > >> > >> I heard D'Arcy Cain indicate that some SAN systems (I think he > >> mentioned NetApp) support this sort of thing, too. Digital's AdvFS > >> also supports it. > >> > >> Of course, if you take this approach, you have to make _certain_ > >> that when you "freeze" a replica of a filesystem, that _ALL_ of the > >> database is contained in that one filesystem. If you move WAL to a > >> different filesystem, bets would be off again... > > > > Also, I assume you have to stop the server just for a moment while > > you do the freeze, right? > > I'm sure that's _preferable_. > > Supposing you don't, the result is that the backup will be treated > much like the condition where a server is "terminated by power > failure," and, at restart, the system will have to rummage around the > WAL to clean up a bit. Note that many NAS storage systems support a "snapshot" mechanism that basically does this in about 1/10th of a second. It produced horrible hickups for our Linux boxen with default NFS settings, whereby our NFS mounts would disappear for three or four minutes after a snapshot. I've never, by the way, run my database on a NAS, and probably never will, if I have any say in it. We just use NAS for static document storage (hundreds of gigs of it.) From murthy.kambhampaty@goeci.com Tue Aug 12 17:37:49 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 52A1ED1C4BA for ; Tue, 12 Aug 2003 17:37:49 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 92896-03 for ; Tue, 12 Aug 2003 14:36:15 -0300 (ADT) Received: from THOR.goeci.com (thor.goeci.com [66.28.220.99]) by svr1.postgresql.org (Postfix) with ESMTP id 549DDD1B539 for ; Tue, 12 Aug 2003 14:37:37 -0300 (ADT) Received: by THOR.goeci.com with Internet Mail Service (5.5.2653.19) id ; Tue, 12 Aug 2003 13:37:37 -0400 Message-ID: <2D92FEBFD3BE1346A6C397223A8DD3FC09239E@THOR.goeci.com> From: Murthy Kambhampaty To: 'Bruce Momjian' , Christopher Browne Cc: pgsql-admin@postgresql.org Subject: Re: Backup routine Date: Tue, 12 Aug 2003 13:37:37 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C360F6.8CE4CE94" X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/151 X-Sequence-Number: 9873 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C360F6.8CE4CE94 Content-Type: text/plain; charset="iso-8859-1" There's an extensive discussion of doing file system level backups off an LVM snapshot taken on a frozen XFS filesystem (XFS provides xfs_freeze command which allows the sysadmin to freeze and unfreeze a given file system at will). See http://marc.theaimsgroup.com/?l=postgresql-admin&w=2&r=1&s=LVM+snapshots&q=b (as Mike Castle points out in this thread, this gives you a "consistent state" but not a know one). If your hardware gives you the ability to freeze I/O, you might get similar capabilities with other filesystems/OSes than XFS on Linux. In that thread, I also discussed a strategy for getting consistent backups when the $PGDATA/pg_xlog/ folder is on a different filesystem: freeze $PGDATA/pg_xlog/ freeze $PGDATA create snapshot $PGDATA/pg_xlog/ and mount that to $PGDATA.snap/pg_xlog\ create snapshot $PGDATA and mount that to $PGDATA.snap unfreeze $PGDATA unfreeze $PGDATA/pg_xlog/ (notice that since you only need to freeze the filesystem during snapshot creation, which is fast, you don't hold the postmaster up very long) rsync $PGDATA.snap/ to a backup volume umount and lvremove the snapshot of $PGDATA/pg_xlog/ umount and lvremove the snapshot of $PGDATA/ Filesystem performance is adversely affected as long as the snapshots exist; so I do a "preliminary rsync" (giving an inconsistent backup) at the beginning of the sequence to minimize the amount of data to be backed up from the snapshot(s). An example bash script which handles $PGDATA/pg_xlog/ being on a different filesystem (and mounted, not symlinked, to $PGDATA/pg_xlog) is attached. It has been tested under a fairly heavy load and seems to handle the job. I'd be interested in comments on the strategy/implementation from the postgresql gurus on this list (the script is rather messy, sorry). Thanks, Murthy >-----Original Message----- >From: Bruce Momjian [mailto:pgman@candle.pha.pa.us] >Sent: Sunday, August 10, 2003 23:13 >To: Christopher Browne >Cc: pgsql-admin@postgresql.org >Subject: Re: [ADMIN] Backup routine > > >Christopher Browne wrote: >> The world rejoiced as peterandsarah@blueyonder.co.uk (Peter >and Sarah Childs) wrote: >> > However there is a third way. That should be safe but some >> > people may disagree with me! If you can "freeze" the disk while you >> > take the backup. The backup can be used as if the computer had >> > crashed with no hard disk failure at all. Ie WAL will be consistant >> > and database may take longer but once it is up it will be >safe (like >> > paragaph 1). Now freezeing a disk for backup is not that >> > difficult. You should be doing it anyway for user file >> > consistancy. (You don't want the first 30 pages of you document to >> > disagree with the end because somone was saving it during the >> > backup! >> >> I heard D'Arcy Cain indicate that some SAN systems (I think he >> mentioned NetApp) support this sort of thing, too. Digital's AdvFS >> also supports it. >> >> Of course, if you take this approach, you have to make _certain_ that >> when you "freeze" a replica of a filesystem, that _ALL_ of the >> database is contained in that one filesystem. If you move WAL to a >> different filesystem, bets would be off again... > >Also, I assume you have to stop the server just for a moment while you >do the freeze, right? > >-- > Bruce Momjian | http://candle.pha.pa.us > pgman@candle.pha.pa.us | (610) 359-1001 > + If your life is a hard drive, | 13 Roberts Road > + Christ can be your backup. | Newtown Square, >Pennsylvania 19073 > >---------------------------(end of >broadcast)--------------------------- >TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to >majordomo@postgresql.org) > ------_=_NextPart_000_01C360F6.8CE4CE94 Content-Type: application/octet-stream; name="pgSnapBack2.sh.discuss" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pgSnapBack2.sh.discuss" #!/bin/bash # FN: pgsnapshot.sh # AB: creates and mounts snapshot of $PGDATA; rsyncs from bkHost; # unmounts and removes snapshot; reinitializes database on backup server # DT: 2003-03-05 # AU: S. Murthy Kambhampaty # DISCLAIMER=3D" This document is provided without restriction to aid discussion about files= ystem online backup and recovery (BAR) of the postgresql database cluster. Any other use is very likely to cause all sorts of damage, and is hazardous." # PREREQUISITES: # postgresql (version 7.2.4 and 7.3.2 have been found to work) # rsync (2.5.6) with suitable server configuration on the backup server # LVM (1.0.3, included in latest SGI XFS enhanced kernels, and 1.0.7 have b= een found to work) # ssh with certificate based authentication of postgres user logging in fro= m production server # to backup server echo $DISCLAIMER exit 9999 PATH=3D/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # What is this script called and where is it running: ThisCMD=3D$(echo -e "$(basename $0)" | awk 'BEGIN{FS=3D"."}{print $1}') pgSRV=3D$(echo -e "$(hostname)" | awk 'BEGIN{FS=3D"."}{print $1}') # The postgresql superuser # (if you want to mail error logs somewhere else, either # set your mail server to forward pgSuper's mail, or add a pgMonitor # and change the two sendmail command lines below: pgSuper=3Dpostgres BackupSRV=3DbkHost DataFS=3D/home/db pgData=3D/home/db/pgsql/pgdata RsyncDM=3D"mirrors_$pgSRV" # What is the rsync module on the backup server = called SnapNM=3Dpgsnapshot XLSnapNM=3Dpgxlsnapshot # # As long as you have installed postgresql in # "/usr/bin/pgsql-M.m/, where M.m=3D$(echo -n $(cat $PGDATA/PG_VERSION)), # on both the production server and the backup server, # you shouldn;t have to edit beyond this point # # If $pgData is a symlink, redefine pgData [[ -L "$pgData" ]] && pgData=3D$(ls -l "$pgData" | awk '{FS=3D" "}{print $N= F}') # Which version of postgresql? pgMinor=3D$(echo -n "$(cat "$pgData/PG_VERSION")") # A function to execute commands on the backup server: RMTExec () { ssh -i "/home/$pgSuper/.ssh/id_rsa" $pgSuper@$BackupSRV "$1" } # A function to do the rsync # /etc/rsync.d on the backup server must be configured # A module named mirrors_$pgSRV must point to a directory # on the backup server. Within that folder a subdirectory # named pgdata must exist, and will contain the backup # copy of the database RsyncLockFile=3D"/home/$pgSuper/$ThisCMD.lock" # rsync options: # The -B option to increase block size on large files: # 1. Reduces the chance of changes being missed # 2. Uses more bandwidth # If you are really paranoid about missing changes, or if most # tables have very little common data from backup to backup, add the # -W option to rsync whole files, rather than changes only. # NOTE: give the -n option to rsync until sure that it # is configured properly. rsync is not forgiviging. RsyncCMD () { rsync -avW -B $((1024 *1024)) --stats \ --delete --force --exclude=3D'postmaster.pid' \ $1/ \ $BackupSRV::$RsyncDM/pgdata/$2/ # If you don't give a second arguement, $2= is null } # When the postmaster is started on the backup server, # the data directory is: pgDataBK=3D$(RMTExec "cat /etc/rsyncd.conf" | sed -n /$RsyncDM/,/^$/p | gre= p path | awk 'BEGIN{FS=3D" =3D "}{print $2}')"/pgdata" # A function to print a formatted timestamp in the log DateCMD () { # Two trailing spaces are intentional echo -n "$(date +%Y-%m-%d) $(date +%X) " return 0 } # A function to mail the error log and bailout; called on program error ExitOnError () { # This function takes two arguments an "exit code" and and "error message" # in order rm -f "$DoSnapLockFile" &>/dev/null echo $'\n\n'"$(DateCMD) $2"$'\n\t'\ "Notified superuser"\ | tee -a "$STASFile" >&2 exec >&6 6>&- exec 2>&7 7>&- cat <(echo "Subject: ATTN: $2"\ $'\n'"X-Priority: 2 (high)"\ $'\n'"!"\ $'\n\t'"Review $(echo -n "$LogFile"), the command log"\ $'\n\t\t'"Error report listed below:" $'\n')\ "$LogFile.err"\ | sendmail "$pgSuper" exit $1 return $1 # Superfluous: this function does not return } # A function for LVM snapshot creation and mounting # There must exist a directory named /mnt/$SnapNM # to which the snapshot is mounted DataLV=3D"$(mount | grep "$DataFS\>[^/]" | awk 'BEGIN{FS=3D" "}{print $1}')" DataVG=3D"$(dirname "$DataLV")" # Please keep the XLogLV and DataLV in the = same VG SnapDir=3D"/mnt/$SnapNM" XlogLV=3D"$(mount | grep "$pgData/pg_xlog\>[^/]" | awk 'BEGIN{FS=3D" "}{pri= nt $1}')" [[ -n "$XlogLV" ]] && XLSnapMB=3D512 DoSnap () { AvailMB=3D"$(echo -n $(vgdisplay --colon "$DataVG") | awk 'BEGIN{FS=3D":"}= {print $16 *$13/2048}')" # 2048 512-byte blocks per MB if [[ -n "$(lvscan | grep "$SnapNM")" || -n "$(lvscan | grep "$XLSnapNM")"= ]]; then echo $'\n\t'"WARNING: Snapshot named $SnapNM or $XLSnapNM already exists.= Terminating ..." >&2 SnapTest=3D32 # lvcreate error: "32 snapshot already exists" elif ((-XLSnapMB +AvailMB <=3D0)); then # Variables need not be preceeded = by '$' in arithmetic expansion; # the above syntax does not work if you test ((-$XLSnapMB +$AvailMB)), s= o you'll # have to put up with the confusion over referencing variables without t= he preceding # $-sign sometimes echo $'\n\t'"WARNING: No space left in $DataVG for snapshot creation. Ter= minating ..." >&2 SnapTest=3D19 # lvcreate error: "19 not enoungh space available to create= logical volume" else # Use all the free space available in $DataVG for the snapshot! [[ -n "$XlogLV" ]] && xfs_freeze -f "$pgData/pg_xlog" xfs_freeze -f "$DataFS" [[ -n "$XlogLV" ]] && { lvcreate -s -L "$XLSnapMB"M -n "$XLSnapNM" "$Xlog= LV"; XLSnapTest=3D$?; } lvcreate -s -L "$((-XLSnapMB +AvailMB))"M -n "$SnapNM" "$DataLV" SnapTest=3D$? xfs_freeze -u "$DataFS" [[ -n "$XlogLV" ]] && xfs_freeze -u "$pgData/pg_xlog" fi # If snapshot creation failed bail; else mount the snapshot volume if ((+XLSnapTest +SnapTest >0)); then ExitOnError 991$SnapTextXL$SnapTest "pgBackup; Snapshot creation failed" else echo $'\n\t'"$(DateCMD) Successfully created snapshot" lvscan | grep snap # Report the snapshot volumes [[ -n "$XlogLV" ]] && { mount -t xfs "$DataVG/$XLSnapNM" "/mnt/$XLSnapNM"= -o nouuid,ro; XLMountTest=3D$?; } LogDev=3D"$(cat "/etc/mtab" | grep "$DataFS\>[^/]" | awk 'BEGIN{FS=3D"log= dev=3D"}{print $2}' | awk 'BEGIN{FS=3D","}{print $1}')" if [[ -n "$LogDev" ]]; then mount -t xfs "$DataVG/$SnapNM" "$SnapDir" -o nouuid,ro,logdev=3D"$LogDe= v" MountTest=3D$? else mount -t xfs "$DataVG/$SnapNM" "$SnapDir" -o nouuid,ro MountTest=3D$? fi mount | grep snap # Report the mounts fi # If snapshot mount failed, then bail; else return if ((+$MountTestXL +$MountTest >0)); then lvremove -f "$DataVG/$SnapNM" [[ -n "$XlogLV" ]] && lvremove -f "$DataVG/$XLSnapNM" ExitOnError 992$MountTest "pgBackup; Snapshot mount failed" fi return 0 # Only returns on success } # Setup logging, and get going: STASFile=3D"$pgData/pgSnapBack.status" LogFile=3D"/home/$pgSuper/$ThisCMD-$(date +%Y%m%d-%H%M)" exec 6>&1; exec > "$LogFile" exec 7>&2; exec 2> "$LogFile.err" echo "$(DateCMD) Backup initiated"\ | tee "$STASFile" # First vacuum all databases # echo $'\n\n'"$(DateCMD) Vacuuming databases on $(hostname)" # # Mark vacuum start and end in the log to ease log navigation # /usr/local/pgsql/bin/psql -U gouser -d template1 -c \ # "select '+++++ Nightly Vacuum About To Commence +++++'" >/dev/null # /usr/local/pgsql/bin/vacuumdb -U postgres -q -a -z && \ # /usr/local/pgsql/bin/psql -U gouser -d template1 -c \ # "select '+++++ Nightly Vacuum Completed +++++'" >/dev/null && \ # echo $'\n\t' "$(DateCMD) Successfully vacuumed databases on $(hostname)" # Phase 1 rsync echo $'\n\n'"$(DateCMD) Phase 1 - rsync from pgdata to mirror on $BackupSRV= "\ | tee -a "$STASFile" while [[ -f "$RsyncLockFile" ]]; do echo "$(DateCMD) previous Rsync still running"$'\n'\ "Waiting for completion" >&2 sleep 300 done # Before you start the backup, make sure that no postmaster is running on t= he backup folder: # (test cribbed from the pg_ctl script) while [[ -n $(RMTExec "sed -n 1p $pgDataBK/postmaster.pid 2>/dev/null") ]];= do echo "$(DateCMD) A postmaster is running at the remote location; waiting = 5 minutes ..." sleep 300 done # You don't want to start simultaneous rsyncs, and you don't want to # start the postmaster while an rsync is running; so put down some # lock files (there was something on linux-xfs about xfs not recovering # inodes allocated to empty files, so don't just "touch" a lockfile, put # something in it). echo "$(DateCMD) Phase 1 - rsync" > "$RsyncLockFile" cat "$RsyncLockFile" | RMTExec "cat - > ~/RsyncLockFile" RsyncCMD "$pgData/" && echo $'\n'"$(DateCMD) Rsync complete"$'\n\n' rm -f "$RsyncLockFile" # Now create and mount the snapshot volume # I'm still seing XFS lockups that go away with xfs_freeze -u $DataFS # So, put up a monitor for all processes wanting to write to to the $DataFS= , and if # you see a D-state on those processes, issue xfs_freeze -u $DataFS DoSnapLockFile=3D"/usr/var/lock/$(basename "$LogFile").PID" ParentPID=3D$$ echo $ParentPID > "$DoSnapLockFile" # Initailize "$DoSnapLockFile" ( while [[ -f "$DoSnapLockFile" ]]; do sleep 60.$ParentPID # snaphsots should not take a full minute, but keep an= eye on this one [[ -f "$DoSnapLockFile" ]] && # In a successful run, it could be gone by t= he time we wake this loop { if [[ "$(ps -eo pid,ppid,session,stat,wchan | grep "D xfs_check_frozen"= | grep $ParentPID )" !=3D "" ]]; then echo $'\n'"Snapshot creation seems to have led to system lockup." \ $'\n\t'"Process list from backup session:" >&2 ps -eo pid,ppid,session,flags,pagein,stackp,stat,args,wchan | grep $Paren= tPID | sed -e "/grep/d" >&2 echo $'\n'"Issuing xfs_freeze -u $DataFS" \ $'\n\t'"Consider this backup unsuccessful." >&2 xfs_freeze -u "$DataFS" [[ -n "$XlogLV" ]] && xfs_freeze -u "$pgData/pg_xlog" rm -f "$DoSnapLockFile" break fi } done ) & echo $'\n\n'"$(DateCMD) Snapshot creation and mounting"\ | tee -a "$STASFile" DoSnap # Phase 2 rsync echo $'\n\n'"$(DateCMD) Phase 2 - rsync from snapshot to mirror on ""$Backu= pSRV" while [[ -f "$RsyncLockFile" ]]; do echo "$(DateCMD) previous Rsync still running"$'\n'\ "Waiting for completion" >&2 sleep 300 done echo "$(DateCMD) Phase 2 rsync" > "$RsyncLockFile" cat "$RsyncLockFile" | RMTExec "cat - > ~/RsyncLockFile" RsyncCMD "--exclude=3D'pg_xlog/' $SnapDir${pgData#$DataFS}" / && { [[ -n "$XlogLV" ]] && RsyncCMD "/mnt/$XLSnapNM/" "pg_xlog"; } && echo $'\n\t'"$(DateCMD) Phase 2 rsync complete"$'\n'\ | tee -a "$STASFile" rm -f "$RsyncLockFile" RMTExec "rm -f ~/RsyncLockFile" # Now remove the snapshot and monitoring stuff umount "$DataVG/$SnapNM" umount "/mnt/$XLSnapNM" lvremove -f "$DataVG/$SnapNM" [[ -n "$XlogLV" ]] && lvremove -f "$DataVG/$XLSnapNM" # should no longer be an issue rm -f "$DoSnapLockFile" kill -INT $(ps ax | grep sleep | grep $ParentPID | awk 'BEGIN{FS=3D" "}{pri= nt $1}') &>/dev/null && \ echo "$(DateCMD) Removed snapshot of \$PGDATA"$'\n\n' # "Reinitialize" the snapshot of the database on the backup server echo $'\n\n'"$(DateCMD) Start postmaster on $BackupSRV, capture output, and= shutdown" RMTExec "/usr/local/pgsql-$pgMinor/bin/postmaster -B4096 -p55432\ -D $pgDataBK 2>&1" & sleep 300 # give the postmaster time for recovery RMTExec "/usr/local/pgsql-$pgMinor/bin/pg_ctl stop -D $pgDataBK -m immediat= e" && echo $'\n\n'"$(DateCMD) Attempted to reinitialize backup; check for errors= above" # Mop up if [[ ! -s "$LogFile.err" ]]; then echo "Completed, no errors" > "$LogFile.err" rm -f "$LogFile.err" echo $'\n\n'"$(DateCMD) Backup completed."\ | tee -a "$STASFile" echo "$(DateCMD) Verify postmaster-messages, listed above, for success." exec >&6 6>&- exec 2>&7 7>&- exit 0 else ExitOnError 999 "pgBackup; Backup encountered errors" fi true # Superflous ------_=_NextPart_000_01C360F6.8CE4CE94-- From murthy.kambhampaty@goeci.com Wed Aug 13 22:29:18 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 8A2D8D1B56B for ; Wed, 13 Aug 2003 22:29:18 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 77026-06 for ; Wed, 13 Aug 2003 19:27:43 -0300 (ADT) Received: from THOR.goeci.com (thor.goeci.com [66.28.220.99]) by svr1.postgresql.org (Postfix) with ESMTP id 3E5FBD1B53A for ; Wed, 13 Aug 2003 19:29:07 -0300 (ADT) Received: by THOR.goeci.com with Internet Mail Service (5.5.2653.19) id ; Wed, 13 Aug 2003 18:29:09 -0400 Message-ID: <2D92FEBFD3BE1346A6C397223A8DD3FC0923A7@THOR.goeci.com> From: Murthy Kambhampaty To: "'dalgoda@ix.netcom.com'" Cc: pgsql-admin@postgresql.org Subject: Re: Backup routine Date: Wed, 13 Aug 2003 18:29:09 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/166 X-Sequence-Number: 9888 On Monday, August 11, 2003 17:26, dalgoda@ix.netcom.com [mailto:dalgoda@ix.netcom.com] wrote: >From: dalgoda@ix.netcom.com [mailto:dalgoda@ix.netcom.com] >Sent: Monday, August 11, 2003 17:26 >To: pgsql-admin@postgresql.org >Subject: Re: [ADMIN] Backup routine > > >In article <200308110313.h7B3DCv06482@candle.pha.pa.us>, >Bruce Momjian wrote: >>Also, I assume you have to stop the server just for a moment while you >>do the freeze, right? > >It depends on if you need known state or just consistent state. > >Taking a snapshot of the system will get you a consistent >state just like >if the machine crashed. You can restore that snapshot, bring >PG back up >and everything will work. Of course, you really have no way of knowing >what transactions were commited and what were not. > >On the other hand, stop the server/snapshot/start the server >gives you not >only consistency, but a known state. That is, you know for sure that >whatever was done before you stopped the server is what was done. > But these considerations apply to pg_dump-s as well, no? I guess with pg_dump you CAN dump one database at a time, and you can "quiesce" each database before dumping -- disallow connections to that database for the duration of the pg_dump, and wait for all transactions to complete before starting pg_dump -- which is a little more flexible. Given the time it takes to do a pg_dump on databases over a few gigabytes in size, though, I can't say I find the flexibility valuable. Cheers, Murthy From scott.marlowe@ihs.com Wed Aug 13 22:49:39 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id A0DDCD1C4BF for ; Wed, 13 Aug 2003 22:49:39 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 86653-02 for ; Wed, 13 Aug 2003 19:48:03 -0300 (ADT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 58B07D1B561 for ; Wed, 13 Aug 2003 19:49:26 -0300 (ADT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h7DMmibS028610; Wed, 13 Aug 2003 16:48:44 -0600 (MDT) Date: Wed, 13 Aug 2003 16:49:30 -0600 (MDT) From: "scott.marlowe" To: Murthy Kambhampaty Cc: "'dalgoda@ix.netcom.com'" , Subject: Re: Backup routine In-Reply-To: <2D92FEBFD3BE1346A6C397223A8DD3FC0923A7@THOR.goeci.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/167 X-Sequence-Number: 9889 On Wed, 13 Aug 2003, Murthy Kambhampaty wrote: > On Monday, August 11, 2003 17:26, dalgoda@ix.netcom.com > [mailto:dalgoda@ix.netcom.com] wrote: > >From: dalgoda@ix.netcom.com [mailto:dalgoda@ix.netcom.com] > >Sent: Monday, August 11, 2003 17:26 > >To: pgsql-admin@postgresql.org > >Subject: Re: [ADMIN] Backup routine > > > > > >In article <200308110313.h7B3DCv06482@candle.pha.pa.us>, > >Bruce Momjian wrote: > >>Also, I assume you have to stop the server just for a moment while you > >>do the freeze, right? > > > >It depends on if you need known state or just consistent state. > > > >Taking a snapshot of the system will get you a consistent > >state just like > >if the machine crashed. You can restore that snapshot, bring > >PG back up > >and everything will work. Of course, you really have no way of knowing > >what transactions were commited and what were not. > > > >On the other hand, stop the server/snapshot/start the server > >gives you not > >only consistency, but a known state. That is, you know for sure that > >whatever was done before you stopped the server is what was done. > > > But these considerations apply to pg_dump-s as well, no? I guess with > pg_dump you CAN dump one database at a time, and you can "quiesce" each > database before dumping -- disallow connections to that database for the > duration of the pg_dump, and wait for all transactions to complete before > starting pg_dump -- which is a little more flexible. Given the time it takes > to do a pg_dump on databases over a few gigabytes in size, though, I can't > say I find the flexibility valuable. But that's still not exactly the same. If you pg_dump a single database in a cluster, THAT database will be consistent to itself, guaranteed by MVCC. Sure, one database in a cluster may not be consistent with another database, but generally, seperate databases are treated / considered to be independent. From murthy.kambhampaty@goeci.com Thu Aug 14 21:31:05 2003 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id D53F4D1F4F0 for ; Thu, 14 Aug 2003 21:31:05 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 94826-10 for ; Thu, 14 Aug 2003 18:30:57 -0300 (ADT) Received: from THOR.goeci.com (thor.goeci.com [66.28.220.99]) by svr1.postgresql.org (Postfix) with ESMTP id 02684D1F4BE for ; Thu, 14 Aug 2003 18:24:48 -0300 (ADT) Received: by THOR.goeci.com with Internet Mail Service (5.5.2653.19) id ; Thu, 14 Aug 2003 17:24:51 -0400 Message-ID: <2D92FEBFD3BE1346A6C397223A8DD3FC0923AD@THOR.goeci.com> From: Murthy Kambhampaty To: "'pgsql-admin@postgresql.org'" Subject: Re: Backup routine Date: Thu, 14 Aug 2003 17:24:48 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/180 X-Sequence-Number: 9901 On Wednesday, August 13, 2003 18:50, scott.marlowe [mailto:scott.marlowe@ihs.com] wrote: >On Wed, 13 Aug 2003, Murthy Kambhampaty wrote: >> On Monday, August 11, 2003 17:26, dalgoda@ix.netcom.com ... >> >It depends on if you need known state or just consistent state. >> > >> >Taking a snapshot of the system will get you a consistent >> >state just like >> >if the machine crashed. You can restore that snapshot, bring >> >PG back up >> >and everything will work. Of course, you really have no >way of knowing >> >what transactions were commited and what were not. >> > >> >On the other hand, stop the server/snapshot/start the server >> >gives you not >> >only consistency, but a known state. That is, you know for >sure that >> >whatever was done before you stopped the server is what was done. >> > >> But these considerations apply to pg_dump-s as well, no? I guess with >> pg_dump you CAN dump one database at a time, and you can >"quiesce" each >> database before dumping -- disallow connections to that >database for the >> duration of the pg_dump, and wait for all transactions to >complete before >> starting pg_dump -- which is a little more flexible. Given >the time it takes >> to do a pg_dump on databases over a few gigabytes in size, >though, I can't >> say I find the flexibility valuable. > >But that's still not exactly the same. If you pg_dump a >single database >in a cluster, THAT database will be consistent to itself, >guaranteed by >MVCC. > >Sure, one database in a cluster may not be consistent with another >database, but generally, seperate databases are treated / >considered to be >independent. > What I had in mind was: 1. If you stop the server and run either (a.) pg_dumpall or (b.) copy of $PGDATA from a snapshot created with a frozen filesystem (the one containing $PGDATA), then you get a consistent backup with a known state. 2. If you leave the server running and either (a.) pg_dumpall or (b.) copy of $PGDATA from a snapshot created with a frozen filesystem (the one containing $PGDATA), then you get a consistent backup with an unknown state. Additionally, with pg_dump you can, unlike with "the consistent filesystem-level backup strategy", independently "quisce" each database while other databases continue normal operations. This gives you the "flexibility" to get pg_dumps with known state for each individual database, without taking down ALL databases at one time (by shutting down the server). This does not seem very valuable. Sorry for any confusion I created, Murthy