pg_dump return status..
pg_dump return status..
От:
Anand Raman <araman@india-today.com>
Дата:
hi guys I am trying to create a shell script which dumps my db to a flat file .. To dump the database i use the pg_dump command.. I find that irrespective of the fact whether pg_dump managed to connect to the db or not the return status ($?) is always zero.. This throws the shell script in a spin which continues even when pg_dump is not able to connect .. Is there anyway around this. I thought of one way was to check stderr for the occurence of the word "failed" and then exit.. Ur suggestions are most welcome version postgresql 702 Regards Anand Raman
RE: pg_dump return status..
От:
Matthew <matt@ctlno.com>
Дата:
I posted a note to the hackers list about this very issue last week. It was never responded to. I am prepared to do the work and submit a patch, but I wanted some input on how best to do it. We had a problem with a backup script silently failing when the disk was full. I guess I will get started on it and will get feedback on the patch when it's submitted. Matt > -----Original Message----- > From: Anand Raman [SMTP:araman@india-today.com] > Sent: Thursday, January 04, 2001 4:12 AM > To: postgresql > Subject: [GENERAL] pg_dump return status.. > > hi guys > > I am trying to create a shell script which dumps my db to a flat file .. > > To dump the database i use the pg_dump command.. > > I find that irrespective of the fact whether pg_dump managed to connect > to the db or not the return status ($?) is always zero.. This throws the > shell script in a spin which continues even when pg_dump is not able to > connect .. > > Is there anyway around this. I thought of one way was to check stderr > for the occurence of the word "failed" and then exit.. > > Ur suggestions are most welcome > > version postgresql 702 > > Regards > Anand Raman >
Re: pg_dump return status..
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Matthew writes: > I posted a note to the hackers list about this very issue last week. It was > never responded to. I am prepared to do the work and submit a patch, but I > wanted some input on how best to do it. We had a problem with a backup > script silently failing when the disk was full. Talk to Philip Warner about detecting output write failures. I think this might be a lot easier in current sources than it would have been in 7.0.* or before; the actual I/O is more centralized, and I think you could reasonably hope to check for write errors at just a couple of places. But I'm not sure where the best places are. >> I find that irrespective of the fact whether pg_dump managed to connect >> to the db or not the return status ($?) is always zero. I think this is probably some sort of mistake in your script. pg_dump certainly returns a nonzero exit status for any failure that it detects, at least in all the versions I've used. Matthew's correct that it doesn't detect write failure on its output file, but that's not the case you're claiming... regards, tom lane
Re: pg_dump return status..
От:
"Anthony E . Greene" <agreene@pobox.com>
Дата:
On Thu, 04 Jan 2001 05:12:25 Anand Raman wrote: >I am trying to create a shell script which dumps my db to a flat file .. > >To dump the database i use the pg_dump command.. > >I find that irrespective of the fact whether pg_dump managed to connect >to the db or not the return status ($?) is always zero.. This throws the >shell script in a spin which continues even when pg_dump is not able to >connect .. > >Is there anyway around this. I thought of one way was to check stderr >for the occurence of the word "failed" and then exit.. You could have the script check for the existence of the dump file and that it has a non-zero size. To dump my personal database, I could use this: #!/bin/bash dumpfile=$HOME/mydatabase.dump pg_dump -d $LOGNAME > $dumpfile if [ -s $dumpfile ] ; then echo 'Dump succeeded' else echo 'Dump failed' fi This should work in sh also. Tony -- Anthony E. Greene PGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26 C484 A42A 60DD 6C94 239D Chat: AOL/Yahoo: TonyG05 ICQ: 91183266 Linux. The choice of a GNU Generation.
Re: [HACKERS] Re: pg_dump return status..
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Philip Warner writes: > There are a few places to check, but a lot less than before. Assuming I > should just die on any failed write (which seems reasonable), Yes, I see no point in continuing after a write failure. Just print the strerror() message and exit. > how do I > check for a failed write in a way that works on all Unixes? Is the > following OK: > - fwrite: ok if return value equals item count > - fprintf: ok if return value > 0. > - fputc: ok if != EOF Probably fprintf() >= 0 --- according to my specs, it returns the number of chars emitted, or a negative value on error. The other two are correct. Don't forget to check for a successful fclose() too, since otherwise you won't notice a failure in dumping the last bufferload of data. I do not recall the success/failure return codes for the zlib calls, but I assume they check for write failure and reflect it back ... regards, tom lane
Re: [HACKERS] Re: pg_dump return status..
От:
Philip Warner <pjw@rhyme.com.au>
Дата:
At 20:50 4/01/01 -0500, Tom Lane wrote:
>
>Talk to Philip Warner about detecting output write failures. I think
>this might be a lot easier in current sources than it would have been in
>7.0.* or before; the actual I/O is more centralized, and I think you
>could reasonably hope to check for write errors at just a couple of
>places.
There are a few places to check, but a lot less than before. Assuming I
should just die on any failed write (which seems reasonable), how do I
check for a failed write in a way that works on all Unixes? Is the
following OK:
- fwrite: ok if return value equals item count
- fprintf: ok if return value > 0.
- fputc: ok if != EOF
----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 0500 83 82 82 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp5.ai.mit.edu:11371 |/
Re: [HACKERS] RE: pg_dump return status..
От:
Philip Warner <pjw@rhyme.com.au>
Дата:
At 19:14 4/01/01 -0600, Matthew wrote:
>I posted a note to the hackers list about this very issue last week. It was
>never responded to. I am prepared to do the work and submit a patch, but I
>wanted some input on how best to do it. We had a problem with a backup
>script silently failing when the disk was full. I guess I will get started
>on it and will get feedback on the patch when it's submitted.
7.0.2 and CVS seem to set $? for me...at least when I try to dump a
nonexistant DB, dump to a nonexistant location or dump to an area I have no
privs for. Also, the code looks like it does an exit(1) whenever there is
an error. Is there a Unix/C/shell interaction that's not working for you?
----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 0500 83 82 82 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp5.ai.mit.edu:11371 |/