Re: psql COPY vs. ON_ERROR_ROLLBACK, multi-command strings

From: Noah Misch <noah(at)leadboat(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql COPY vs. ON_ERROR_ROLLBACK, multi-command strings
Date: 2012-02-25 05:57:17
Message-ID: 20120225055717.GA3986@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 25, 2012 at 06:25:46PM -0300, Alvaro Herrera wrote:
> Excerpts from Noah Misch's message of s??b ene 14 12:40:02 -0300 2012:
> > It has bothered me that psql's \copy ignores the ON_ERROR_ROLLBACK setting.
> > Only SendQuery() takes note of ON_ERROR_ROLLBACK, and \copy, like all
> > backslash commands, does not route through SendQuery(). Looking into this
> > turned up several other weaknesses in psql's handling of COPY.
>
> Interesting.
>
> Committed, thanks.

Thanks. While testing a crashing function, I noticed that my above patch
added some noise to psql output when the server crashes:

[local] test=# select crashme();
The connection to the server was lost. Attempting reset: Failed.
The connection to the server was lost. Attempting reset: Failed.
unexpected transaction status (4)
Time: 6.681 ms
!> \q

Status 4 is PQTRANS_UNKNOWN, which is expected when the connection is not
CONNECTION_OK. The double message arrives because ProcessResult() now calls
CheckConnection() at least twice, for the benefit of COPY. (Incidentally, the
reconnect fails because the server has not yet finished recovering; that part
is nothing new.)

The attached small patch has SendQuery() keep quiet about PQTRANS_UNKNOWN when
the connection is down. It makes ProcessResult() skip the second
CheckConnection() when the command string had no COPY results. This restores
the pre-08146775acd8bfe0fcc509c71857abb928697171 psql output:

[local] test=# select crashme();
The connection to the server was lost. Attempting reset: Failed.
Time: 4.798 ms
!> \q

Thanks,
nm

Attachment Content-Type Size
psql-crashoutput-v1.patch text/plain 1.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jasen Betts 2012-02-25 09:07:55 Re: Behavior of subselects in target lists and order by
Previous Message Tom Lane 2012-02-25 05:46:09 Re: psql \i tab completion initialization problem on HEAD