ON_ERROR_EXIT and interactive mode (or, how to force interactive mode off)

From: Tim Kane <tim(dot)kane(at)gmail(dot)com>
To: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: ON_ERROR_EXIT and interactive mode (or, how to force interactive mode off)
Date: 2013-12-27 12:30:24
Message-ID: CEE32360.52C9E%tim.kane@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

HI all,

I have a fairly complex python script which calls a number of ‘psql’
sessions via a subprocess to perform bulk load operations.
The bulk loads are generated on the fly, and are written directly to the
stdin of the subprocess.

I would like to rely on the ON_ERROR_STOP=1 functionality to force the
process to exit with an error code – however, psql rightly believes the
process it is operating under is an interactive one – since it is receiving
its input from stdin.

For performance (and disk) reasons, I’d rather not have to rely on writing
my input to a file, before passing it to psql with –f

This part of the man page gave me hope…

> -f filename
> --file filename
> Use the file filename as the source of commands instead of reading commands
> interactively. After the file is processed, psql terminates. This is in many
> ways equivalent to the internal command \i.
> If filename is - (hyphen), then standard input is read.
> Using this option is subtly different from writing psql < filename. In
> general, both will do what you expect, but using -f enables some nice features
> such as error messages with line numbers. There is also a slight chance that
> using this option will reduce the start-up overhead. On the other hand, the
> variant using the shell's input redirection is (in theory) guaranteed to yield
> exactly the same output that you would have gotten had you entered everything
> by hand.

Eg:
psql –v ON_ERROR_STOP=1 –f -

But it seems this is still understood by psql to be an interactive session,
and fails to exit the process on an error.

Is there any way to force psql to read from stdin, in a non-interactive
manner? (that is, to ensure it exits the process on an error condition?)

Thanks for any advice

Tim

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Clemens Eisserer 2013-12-27 13:01:01 Why is wal_writer_delay limited to 10s?
Previous Message Magnus Hagander 2013-12-27 09:42:44 Re: postgresql-common breaks logrotate