1

I've created a pgsql script and saved it into a file. This script is creating idexes. I need to run this script on several database. I use PostgreSQL 9.3 on Windows 8.

I've created a batch file to call psql on every database and run the script. This works fine except in the shell I have a lot more messages than in my output file. Meaning when something goes wrong (i.e. a failed unique index) I see it in the shell but not in my output file. And because the shell is filled with messages I'm missing errors and warnings.

In my pgsql script I use

    SET client_min_messages to 'LOG';
    raise log 'Dropped index %', l_index_name;

My Windows batch file is

    @echo off
    set _psql="D:\Program Files\PostgreSQL\9.3\bin\psql.exe"
    set _server=localhost
    set _port=5432
    set _file=create_indexes.sql
    set _log=create_indexes.log

    FOR %%G IN (db1 db2 db3)  DO (
      %_psql% -d %%G -h %_server% -p %_port% -U postgres -w postgres <%_file% >>%_log%
      echo Done with %%G 
    )

    pause

I've been reading post about using >output.log, like

    create_indexes.bat >output.log

The file is created but has only a few irrelevant messages.

Any suggestion is more than welcome.

1 Answer 1

8

You need to redirect not only stdout (stream 1) but also stderr (stream 2)

create_indexes.bat >output.log 2>&1

That is, send the output of the stderr to wherever the stream 1 is being sent

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.