Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 23rd, 2005, 01:35 AM
David Garamond
Guest
 
Posts: n/a
Default psql: immediately exit after an error?

Can psql be told to exit immediately after an error (especially when
doing commands from a file, -f)? This is the default behaviour of the
mysql client, except when we give it -f option ("force").

The problem is, when restoring a dump, a failure at the some point might
cause the subsequent commands to produce wrong results (e.g. I redefine
a builtin function with a plruby function with different behaviour, but
plruby failed to be installed due to wrong path. Thus the subsequent
commands are executed using the builtin function which is not the
expected one.) Furthermore, you can't check on psql exit code to see
whether _any_ command was not successfully executed.

Of course one should examine the full psql output after a restore
anyway, and the option to exit immediately after an error can save time
(especially for large dumps).

--
dave


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

  #2  
Old November 23rd, 2005, 01:36 AM
Mike G
Guest
 
Posts: n/a
Default Re: psql: immediately exit after an error?

I would think that depends upon how the sql in the file is coded. You can use the RAISE NOTICE / ERROR commands to abort a function's execution.
[color=blue]
> Can psql be told to exit immediately after an error (especially when
> doing commands from a file, -f)? This is the default behaviour of the
> mysql client, except when we give it -f option ("force").
>
> The problem is, when restoring a dump, a failure at the some point might
> cause the subsequent commands to produce wrong results (e.g. I redefine
> a builtin function with a plruby function with different behaviour, but
> plruby failed to be installed due to wrong path. Thus the subsequent
> commands are executed using the builtin function which is not the
> expected one.) Furthermore, you can't check on psql exit code to see
> whether _any_ command was not successfully executed.
>
> Of course one should examine the full psql output after a restore
> anyway, and the option to exit immediately after an error can save time
> (especially for large dumps).
>
> --
> dave
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html[/color]

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

  #3  
Old November 23rd, 2005, 01:36 AM
Peter Eisentraut
Guest
 
Posts: n/a
Default Re: psql: immediately exit after an error?

David Garamond wrote:[color=blue]
> Can psql be told to exit immediately after an error (especially when
> doing commands from a file, -f)? This is the default behaviour of the
> mysql client, except when we give it -f option ("force").[/color]

\set ON_ERROR_STOP on

Look into the psql man page for additional semantic details.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

  #4  
Old November 23rd, 2005, 01:36 AM
David Garamond
Guest
 
Posts: n/a
Default Re: psql: immediately exit after an error?

Peter Eisentraut wrote:[color=blue][color=green]
>>Can psql be told to exit immediately after an error (especially when
>>doing commands from a file, -f)? This is the default behaviour of the
>>mysql client, except when we give it -f option ("force").[/color]
>
> \set ON_ERROR_STOP on
>
> Look into the psql man page for additional semantic details.[/color]

Thanks! Just what I was looking for.

Btw, may I suggest this line be added by pg_dump/pg_dumpall? Or even the
default being changed to on when -f is given? Or maybe add a command
line option for this?

--
dave

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

  #5  
Old November 23rd, 2005, 01:36 AM
Tom Lane
Guest
 
Posts: n/a
Default Re: psql: immediately exit after an error?

David Garamond <lists@zara.6.isreserved.com> writes:[color=blue]
> Peter Eisentraut wrote:[color=green]
>> \set ON_ERROR_STOP on[/color][/color]
[color=blue]
> Btw, may I suggest this line be added by pg_dump/pg_dumpall?[/color]

No. The fact that pg_dump scripts keep going is a feature, not a bug.
We recently changed pg_restore to match that behavior, in fact, because
people were constantly having trouble when it didn't.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles