I need to run pg_restore on my PC with Windows CMD to restore a dump to a remote DB. I need to save the running report of the pg_restore into a file, to make sure the restoration ran as expected. Below is the pg_restore command I ran.

pg_restore.exe --host= --port=5432 --username=postgres 
               --dbname=mytargetdb --verbose --single-transaction "AT5.DUMP"

It turned out that:

  • Putting > report.txt in the end of the pg_restore command does not render error, but nothing got written to the textfile.
  • Using the --file=report.txt throws "error: options -d/--dbname and -f/--file cannot be used together"

The restoration was actually successful. But copy-paste from the cmd windows is not an option as the resulting report was long enough so the cmd only shows some hundreds of the last line of the report, and not the most from earlier lines.

So how should I do that?

My environment:

  • My PC: pg_restore version 12.2 on Windows 10 Pro
  • Target server: PostgreSQL 9.6 on Windows Server 2008 R2 Data Center
  • 1
    Maybe the output is sent to stderr, did you try ... 2> report.txt or ... 1> report.txt 2>&1 – a_horse_with_no_name Jul 24 '20 at 6:07
  • 1
    2> ... is something different than > ... – a_horse_with_no_name Jul 24 '20 at 8:13
  • @a_horse_with_no_name I just tried the one like "1> report.txt 2>&1" and it works! What is actually the meaning of a pair of ">" ? – Rino Jul 24 '20 at 8:16
  • Oh i get it now: it's part of redirection syntax in CMD. Thank you! – Rino Jul 24 '20 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.