Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ERRORLEVEL values in batch files for reindexdb etc.

345 views
Skip to first unread message

Justus Janssen

unread,
Aug 10, 2009, 10:48:18 AM8/10/09
to
Hi,

we've been using a batch file containing a call to reindexdb.exe ,
vacuumdb.exe and pg_dump.exe on a regular basis, and recently found that
sometimes one or more of these commands fail. To check that, I've added

IF %ERRORLEVEL%==0 GOTO (next step) ...
GOTO PGERROR

lines in the batch file, which seem to work perfectly for reindexdb.exe
and vacuumdb.exe . pg_dump however, does not set the ERRORLEVEL
variable. Is there a way to detect pg_dump has encountered a problem?
Right now, I'm testing by stopping the PostgreSQL service.

Also, is there a list of possible error values available for these commands?

Thanks,
Justus Janssen
Arpa, Veldhoven NL

Laurenz Albe

unread,
Aug 11, 2009, 3:15:28 AM8/11/09
to

Which version are you using?

I tried with an 8.2 Windows client installation, and ERRORLEVEL was set
appropriately.

For all tests I ran, the only error level returned was "1", no matter
if it was a connection problem or a problem with the database.

So your test as quoted above should work fine.

What do you get if you run:

pg_dump -h notexists nondatabase
echo %ERRORLEVEL%

in your MS-DOS box?

Yours,
Laurenz Albe


Justus Janssen

unread,
Aug 11, 2009, 3:39:12 AM8/11/09
to
Hi Laurenz,

>
> Which version are you using?
>
> I tried with an 8.2 Windows client installation, and ERRORLEVEL was set
> appropriately.
>
> For all tests I ran, the only error level returned was "1", no matter
> if it was a connection problem or a problem with the database.
>
> So your test as quoted above should work fine.
>
> What do you get if you run:
>
> pg_dump -h notexists nondatabase
> echo %ERRORLEVEL%
>

your example worked fine, thanks. It made me take a closer look at the
batch file, and only then I found I was reading the ERRORLEVEL of the
DIR command in stead of PG_DUMP ...

01. :backupstart
02. rem
**********************************************************************
03. rem * Backup database
04. rem
**********************************************************************
05. call datetime
06. echo
---------------------------------------------------------------------->>"%dbbackuppath%\backup.log"
07. echo Backup : %longdate% %longtime%
08. echo Backup : %longdate% %longtime%>>"%dbbackuppath%\backup.log"
09. "%pgbinpath%\pg_dump.exe" -h %pghost% -p %pgport% -U %pguser% -F c
-b -v -o -f "%dbbackuppath%\%dbbackupfile%" %dbname%
>>"%dbbackuppath%\backup.log"
10. set error_level=%errorlevel%
11. dir "%dbbackuppath%\%dbbackupfile%" /b>>"%dbbackuppath%\backup.log"
12. if "%error_level%"=="0" goto defragtest
13. echo
**********************************************************************>>"%dbbackuppath%\backup.log"
14. echo * Backup error %error_level% >>"%dbbackuppath%\backup.log"
15. echo
**********************************************************************>>"%dbbackuppath%\backup.log"
16. goto pgerror

After swapping lines 10 and 11, the script ran without a hitch, indeed
resulting in errorlevel 1 for various errors.

It's a shame though we can't get more detailed information on different
kinds of errors from the commandline.

Running PG 8.3.7 on WinXP, btw, although that's not relevant any more.


Thanks again, I will sleep better from now on :-)
Justus

0 new messages