Re: [HACKERS] pg_restore -d doesn't display output - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [HACKERS] pg_restore -d doesn't display output
Date
Msg-id 200310080444.h984ijV08758@candle.pha.pa.us
Whole thread Raw
Responses Re: [HACKERS] pg_restore -d doesn't display output  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-patches
Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > Does anyone know why 'pg_restore -d' doesn't display the commands being
> > > executed, like you see when you don't use '-d':
> >
> > >     pg_restore < /tmp/test.db
> > >     pg_restore -d test < /tmp/test.db
> >
> > The first sends a script to stdout (effectively equivalent to pg_dump
> > plain style).  The second sends the commands to a backend.
> >
> > I would have expected there to be a --verbose option that would also echo
> > the commands to stderr, but it doesn't look like there's any support for
> > that in the code.
>
> I don't understand why sending something to a backend should effect the
> script output.

I have patched pg_restore to output the script contents if you restore
with -v:

    pg_restore -v -d test /tmp/x

Patch attached.  I will save this for 7.5.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/bin/pg_dump/pg_backup_archiver.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/pg_dump/pg_backup_archiver.c,v
retrieving revision 1.78
diff -c -c -r1.78 pg_backup_archiver.c
*** src/bin/pg_dump/pg_backup_archiver.c    3 Oct 2003 20:10:59 -0000    1.78
--- src/bin/pg_dump/pg_backup_archiver.c    8 Oct 2003 04:43:39 -0000
***************
*** 1232,1246 ****
           * connected then send it to the DB.
           */
          if (RestoringToDB(AH))
!             return ExecuteSqlCommandBuf(AH, (void *) ptr, size * nmemb);        /* Always 1, currently */
!         else
          {
              res = fwrite((void *) ptr, size, nmemb, AH->OF);
              if (res != nmemb)
                  die_horribly(AH, modulename, "could not write to output file (%lu != %lu)\n",
                               (unsigned long) res, (unsigned long) nmemb);
-             return res;
          }
      }
  }

--- 1232,1247 ----
           * connected then send it to the DB.
           */
          if (RestoringToDB(AH))
!             res = ExecuteSqlCommandBuf(AH, (void *) ptr, size * nmemb);    /* Always 1, currently */
!
!         if (!RestoringToDB(AH) || AH->public.verbose)
          {
              res = fwrite((void *) ptr, size, nmemb, AH->OF);
              if (res != nmemb)
                  die_horribly(AH, modulename, "could not write to output file (%lu != %lu)\n",
                               (unsigned long) res, (unsigned long) nmemb);
          }
+         return res;
      }
  }


pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Bug in pg_restore memory handling
Next
From: Manfred Koizar
Date:
Subject: Re: [HACKERS] Cannot dump/restore text value \N