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

Поиск
Список
Период
Сортировка
Искать

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

От:
Bruce Momjian <pgman@candle.pha.pa.us>
Дата:
Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian  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;
  	}
  }
  

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

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
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   peter_e@gmx.net

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

От:
Bruce Momjian <pgman@candle.pha.pa.us>
Дата:
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
  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
FAQ