Re: psql -L log errors

From: Felipe Santos <felipepts(at)gmail(dot)com>
To: Hans Ginzel <hans(at)matfyz(dot)cz>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: psql -L log errors
Date: 2015-03-11 11:47:13
Message-ID: CAPYcRiV-yLUkY7hrUGuBrVSQHMsMiR-b1Jw9+ieVBMrmk7ZZ=A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

2015-03-11 6:00 GMT-03:00 Hans Ginzel <hans(at)matfyz(dot)cz>:

> Hello!
>
> There is, in documentation of psql client (http://www.postgresql.org/
> docs/9.4/static/app-psql.html):
> --log-file=filename
> Write all query output into file filename, in addition to the normal
> output destination.
>
> But it seems, that psql logs only the query output (and input if -e or -a),
> but does not write the error output. How to also log the errors, please?
>
> Thanks
> Hans
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice

Hi Hans,

It's the operating system "fault" .

The normal output and the error output are different things, although we
experience them as the same in most of the cases.

The OS sends both normal and error output to the standard output device,
which is usually our display/screen.

When you are using the "--log-file" clause, you are telling the psql to
redirect the normal output to the file indicated, but the error output
keeps being sent to the standard output device.

To redirect the error output you have to append it to the file you're
logging into.

To do that, do the following (both Win and Linux, replace the psql
arguments ofr yours) :
psql -U sample_user -W -c "select * from foo;" sample_database
--log-file=sample_file.txt 2>> sample_file.txt

The part that accomplishes the "trick" is this:
2>> sample_file.txt

The ">>" sign tells the OS to append to the file, if you use ">" it will
overwrite it, and you dont want to overwrite it because you are already
writing on it with the "--log-file" clause.

Best regards,

Felipe

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Hans Ginzel 2015-03-11 14:01:12 Re: psql -L log errors
Previous Message Gurunadh Venkata 2015-03-11 09:30:34 Reg Failover Script in Pgpool