Re: psql -L log errors

Поиск
Список
Период
Сортировка
От Felipe Santos
Тема Re: psql -L log errors
Дата
Msg-id CAPYcRiV-yLUkY7hrUGuBrVSQHMsMiR-b1Jw9+ieVBMrmk7ZZ=A@mail.gmail.com
обсуждение исходный текст
Ответ на psql -L log errors  (Hans Ginzel <hans@matfyz.cz>)
Ответы Re: psql -L log errors  (Hans Ginzel <hans@matfyz.cz>)
Список pgsql-novice


2015-03-11 6:00 GMT-03:00 Hans Ginzel <hans@matfyz.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@postgresql.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


В списке pgsql-novice по дате отправления:

Предыдущее
От: Gurunadh Venkata
Дата:
Сообщение: Reg Failover Script in Pgpool
Следующее
От: Hans Ginzel
Дата:
Сообщение: Re: psql -L log errors