Re: [PATCHES] [HACKERS] pg_restore -d doesn't display output

2003-10-07 Thread Bruce Momjian
Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <[EMAIL PROTECTED]> 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
  [EMAIL PROTECTED]   |  (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.c3 Oct 2003 20:10:59 -   1.78
--- src/bin/pg_dump/pg_backup_archiver.c8 Oct 2003 04:43:39 -
***
*** 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;
}
  }
  

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [PATCHES] [HACKERS] pg_restore -d doesn't display output

2003-10-08 Thread Peter Eisentraut
Bruce Momjian writes:

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

I don't think it's a good idea to overload the -v switch with it.  A
separate switch seems OK, but I don't quite get the point of this
functionality, actually.

-- 
Peter Eisentraut   [EMAIL PROTECTED]


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [PATCHES] [HACKERS] pg_restore -d doesn't display output

2003-10-08 Thread Bruce Momjian
Peter Eisentraut wrote:
> Bruce Momjian writes:
> 
> > I have patched pg_restore to output the script contents if you restore
> > with -v:
> 
> I don't think it's a good idea to overload the -v switch with it.  A
> separate switch seems OK, but I don't quite get the point of this
> functionality, actually.

Oh, OK.  When I was testing, I didn't realize that pg_restore doesn't do
anything unless you specify the database via -d, but I see it in the
docs now:

   pg_restore can operate in two modes: If a database name is
   specified, the  archive  is  restored  directly  into  the
   database.  Otherwise, a script containing the SQL commands
   necessary to rebuild the database is created (and  written
   to a file or standard output), similar to the ones created
   by the pg_dump plain text format. Some of the options con-
   trolling  the  script  output  are  therefore analogous to
   pg_dump options.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org