Re: Rollback on include error in psql

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Viktor Shitkovskiy <hanksmail(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Rollback on include error in psql
Date: 2014-12-28 20:47:20
Message-ID: 54A06C58.2020009@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

On 12/28/2014 10:06 AM, Viktor Shitkovskiy wrote:
> I include my own scripts. Each of them creates some table or makes some
> changes to existing tables.

It is hard to say where to go from here without more information. The
options you are passing to psql all have caveats:

AUTOCOMMIT

When on (the default), each SQL command is automatically committed
upon successful completion. To postpone commit in this mode, you must
enter a BEGIN or START TRANSACTION SQL command. When off or unset, SQL
commands are not committed until you explicitly issue COMMIT or END. The
autocommit-off mode works by issuing an implicit BEGIN for you, just
before any command that is not already in a transaction block and is not
itself a BEGIN or other transaction-control command, nor a command that
cannot be executed inside a transaction block (such as VACUUM).

Note: In autocommit-off mode, you must explicitly abandon any
failed transaction by entering ABORT or ROLLBACK. Also keep in mind that
if you exit the session without committing, your work will be lost.

--single-transaction

When psql executes a script, adding this option wraps BEGIN/COMMIT
around the script to execute it as a single transaction. This ensures
that either all the commands complete successfully, or no changes are
applied.

If the script itself uses BEGIN, COMMIT, or ROLLBACK, this option
will not have the desired effects. Also, if the script contains any
command that cannot be executed inside a transaction block, specifying
this option will cause that command (and hence the whole transaction) to
fail.

ON_ERROR_STOP

By default, command processing continues after an error. When this
variable is set, it will instead stop immediately. In interactive mode,
psql will return to the command prompt; otherwise, psql will exit,
returning error code 3 to distinguish this case from fatal error
conditions, which are reported using error code 1. In either case, any
currently running scripts (the top-level script, if any, and any other
scripts which it may have in invoked) will be terminated immediately. If
the top-level command string contained multiple SQL commands, processing
will stop with the current command.

Without information on what is going on in the individual scripts or the
master script, it would be just a guessing game at this point.

> Yes, I want a complete rollback.
>
>
> Where is the \include coming from?
>
> What is in the tableX.cre files?
>
> So if I am following you want a complete rollback on non-SQL or SQL
> errors, correct?
>
> I'm using PostgreSQL 9.2.1.
>
> P.S. Initially I asked this question at dba.stackexchange.com
> <http://dba.stackexchange.com>
> <http://dba.stackexchange.com>__:
> http://dba.stackexchange.com/__questions/87040/rollback-on-__include-error-in-psql
> <http://dba.stackexchange.com/questions/87040/rollback-on-include-error-in-psql>
>
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G Johnston 2014-12-29 01:04:04 Re: Rollback on include error in psql
Previous Message Viktor Shitkovskiy 2014-12-28 18:06:53 Re: Rollback on include error in psql

Browse pgsql-general by date

  From Date Subject
Next Message Pawel Veselov 2014-12-28 21:49:59 Improving performance of merging data between tables
Previous Message Viktor Shitkovskiy 2014-12-28 18:06:53 Re: Rollback on include error in psql