Is there a "pg_restore --quiet" option like "psql --quiet"?

18,996

Solution 1

The question seems to imply that pg_restore is executing these SQL commands and you wouldn't want to see them in the output. But outputting them is what it's only supposed to do.

pg_restore has two modes of operation, with or without connecting to a database. When it's called without a database (-d option) as shown in the question:

$ pg_restore --cluster 8.4/mycluster mycluster.dump

then its sole purpose is to output a set of SQL commands in plain text that should be fed to an SQL interpreter to restore the database. Those SQL commands form a coherent set without any concept of verbosity, and they are not executed by pg_restore itself. They're generally redirected into a file for later execution or piped into psql for immediate execution.

Solution 2

You can redirect stdout to a file:

pg_restore --cluster 8.4/mycluster mycluster.dump > pg_restore.log

Or provide the -d option, but what you want is either -f or -d

pg_restore -f pg_restore.sql --cluster 8.4/mycluster mycluster.dump
pg_restore -d yourdatabase --cluster 8.4/mycluster mycluster.dump
Share:
18,996
Rob Bednark
Author by

Rob Bednark

Software Engineer resume LinkedIn Facebook Twitter github:robbednark Google+ Quora PortlandUpside.com email/Hangouts: rbednark (gmail.com) Skype ID: rbednark

Updated on June 05, 2022

Comments

  • Rob Bednark
    Rob Bednark almost 2 years

    psql has a -q / --quiet option (environment variable QUIET). pg_restore does not have a quiet option. Is there any way to make pg_restore not verbosely show the SQL commands that it's executing?

    # e.g., here's the verbose output that I don't want to see:
    $ pg_restore --cluster 8.4/mycluster mycluster.dump
    ---- PostgreSQL database dump
    --
    SET statement_timeout = 0;SET client_encoding = 'UTF8';
    SET standard_conforming_strings = off;SET check_function_bodies = false;
    ...
    --
    -- Name: data_src; Type: TABLE; Schema: public; Owner: postgres; Tablespace:--
    CREATE TABLE data_src (
    ...
    
  • Rob Bednark
    Rob Bednark almost 12 years
    Aha, now it's all clear! I was mistakenly assuming that without -d, pg_restore would automatically create the database for me. But with your explanation, and with reading the pg_restore(1) man page, it's clear now. My question as a mistaken assumption, so I'll think about how to reword it to make it more clear for future readers. Thanks @Daniel_Vérité!