Thread: Bug #631: pg_dumpall does not accept -F or -f

Bug #631: pg_dumpall does not accept -F or -f

From
pgsql-bugs@postgresql.org
Date:
Don Pellegrinio (donald.a.pellegrino@usa.dupont.com) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
pg_dumpall does not accept -F or -f

Long Description
The pg_dumpall script seems to ignore the file and format switches that are used with pg_dump.  pg_dumpall always
writesto stdout in text format.  Also, the -b switch can not be used with pg_dumpall since text output is being forced. 

Sample Code


No file was uploaded with this report

Re: Bug #631: pg_dumpall does not accept -F or -f

From
Peter Eisentraut
Date:
> The pg_dumpall script seems to ignore the file and format switches
> that are used with pg_dump.  pg_dumpall always writes to stdout in
> text format.  Also, the -b switch can not be used with pg_dumpall
> since text output is being forced.

That's not a bug.

--
Peter Eisentraut   peter_e@gmx.net

Re: Bug #631: pg_dumpall does not accept -F or -f

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> > The pg_dumpall script seems to ignore the file and format switches
> > that are used with pg_dump.  pg_dumpall always writes to stdout in
> > text format.  Also, the -b switch can not be used with pg_dumpall
> > since text output is being forced.
>
> That's not a bug.

Peter, can you explain why to the user; it is not clear to me why
either, though I have my suspicions, and shouldn't we throw an error to
the user when they try it?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: Bug #631: pg_dumpall does not accept -F or -f

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> Peter Eisentraut wrote:
> > > The pg_dumpall script seems to ignore the file and format switches
> > > that are used with pg_dump.  pg_dumpall always writes to stdout in
> > > text format.  Also, the -b switch can not be used with pg_dumpall
> > > since text output is being forced.
> >
> > That's not a bug.
>
> Peter, can you explain why to the user; it is not clear to me why
> either, though I have my suspicions, and shouldn't we throw an error to
> the user when they try it?

The pg_dumpall reference page explicitly cautions against this situation.

--
Peter Eisentraut   peter_e@gmx.net

Re: Bug #631: pg_dumpall does not accept -F or -f

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > Peter Eisentraut wrote:
> > > > The pg_dumpall script seems to ignore the file and format switches
> > > > that are used with pg_dump.  pg_dumpall always writes to stdout in
> > > > text format.  Also, the -b switch can not be used with pg_dumpall
> > > > since text output is being forced.
> > >
> > > That's not a bug.
> >
> > Peter, can you explain why to the user; it is not clear to me why
> > either, though I have my suspicions, and shouldn't we throw an error to
> > the user when they try it?
>
> The pg_dumpall reference page explicitly cautions against this situation.

I see that now:

       Any other command line parameters are passed to the under-
       lying pg_dump(1) calls. This is  useful  to  control  some
       aspects of the output format, but some options such as -f,
       -t, and dbname should be avoided.

However, it seems we should explicitly throw an error if someone tries
to use these flags.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: Bug #631: pg_dumpall does not accept -F or -f

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> However, it seems we should explicitly throw an error if someone tries
> to use these flags.

I agree with Bruce that it's be friendlier if pg_dumpall did a little
more checking.  Not a real high priority, perhaps.

            regards, tom lane

Re: Bug #631: pg_dumpall does not accept -F or -f

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > Peter Eisentraut wrote:
> > > > The pg_dumpall script seems to ignore the file and format switches
> > > > that are used with pg_dump.  pg_dumpall always writes to stdout in
> > > > text format.  Also, the -b switch can not be used with pg_dumpall
> > > > since text output is being forced.
> > >
> > > That's not a bug.
> >
> > Peter, can you explain why to the user; it is not clear to me why
> > either, though I have my suspicions, and shouldn't we throw an error to
> > the user when they try it?
>
> The pg_dumpall reference page explicitly cautions against this situation.

Also, Peter, CVS pg_dumpall is not working for me.  It isn't dumping any
database contents.   This new DATABASES line doesn't work in pg_dumpall:

    DATABASES="$DATABASES $DATABASE"

The problem is that this is done inside a 'while' loop, so the value
doesn't get outside the loop.  I tested with BSD/OS sh and bash
2.02.1(2).

    #$ X=1
    #$ echo 1 2 3 | while read X
    > do
    > X=2
    > done
    #$ echo $X
    1

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: Bug #631: pg_dumpall does not accept -F or -f

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > However, it seems we should explicitly throw an error if someone tries
> > to use these flags.
>
> I agree with Bruce that it's be friendlier if pg_dumpall did a little
> more checking.  Not a real high priority, perhaps.

OK, Donald, I have added this patch to CVS that will return a proper
error message when invalid pg_dumpall options are used.  I added the
options mentioned in the pg_dumpall manual page, plus -F (which wasn't
mentioned in the manual page).

The reason -Ft can't be used is that ASCII SQL commands are output by
pg_dumpall, and these can't be merged with non-ASCII pg_dump output
formats.


--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: src/bin/pg_dump/pg_dumpall.sh
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.sh,v
retrieving revision 1.16
diff -c -r1.16 pg_dumpall.sh
*** src/bin/pg_dump/pg_dumpall.sh    24 Feb 2002 21:57:23 -0000    1.16
--- src/bin/pg_dump/pg_dumpall.sh    11 Apr 2002 04:46:09 -0000
***************
*** 8,14 ****
  #
  # $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.sh,v 1.16 2002/02/24 21:57:23 tgl Exp $

! CMDNAME=`basename $0`

  # substituted at build
  VERSION='@VERSION@'
--- 8,14 ----
  #
  # $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.sh,v 1.16 2002/02/24 21:57:23 tgl Exp $

! CMDNAME="`basename $0`"

  # substituted at build
  VERSION='@VERSION@'
***************
*** 21,27 ****
  PGPATH=
  if echo "$0" | grep '/' > /dev/null 2>&1 ; then
      # explicit dir name given
!     PGPATH=`echo $0 | sed 's,/[^/]*$,,'`       # (dirname command is not portable)
  else
      # look for it in PATH ('which' command is not portable)
      for dir in `echo "$PATH" | sed 's/:/ /g'` ; do
--- 21,27 ----
  PGPATH=
  if echo "$0" | grep '/' > /dev/null 2>&1 ; then
      # explicit dir name given
!     PGPATH=`echo "$0" | sed 's,/[^/]*$,,'`       # (dirname command is not portable)
  else
      # look for it in PATH ('which' command is not portable)
      for dir in `echo "$PATH" | sed 's/:/ /g'` ; do
***************
*** 78,84 ****


  while [ "$#" -gt 0 ] ; do
!     case $1 in
          --help)
                  usage=t
                  break
--- 78,84 ----


  while [ "$#" -gt 0 ] ; do
!     case "$1" in
          --help)
                  usage=t
                  break
***************
*** 94,100 ****
                  connectopts="$connectopts $1"
                  ;;
          --host=*)
!                 connectopts="$connectopts -h "`echo $1 | sed 's/^--host=//'`
                  ;;
      --port|-p)
          connectopts="$connectopts -p $2"
--- 94,100 ----
                  connectopts="$connectopts $1"
                  ;;
          --host=*)
!                 connectopts="$connectopts -h `echo $1 | sed 's/^--host=//'`"
                  ;;
      --port|-p)
          connectopts="$connectopts -p $2"
***************
*** 103,109 ****
                  connectopts="$connectopts $1"
                  ;;
          --port=*)
!                 connectopts="$connectopts -p "`echo $1 | sed 's/^--port=//'`
                  ;;
      --user|--username|-U)
          connectopts="$connectopts -U $2"
--- 103,109 ----
                  connectopts="$connectopts $1"
                  ;;
          --port=*)
!                 connectopts="$connectopts -p `echo $1 | sed 's/^--port=//'`"
                  ;;
      --user|--username|-U)
          connectopts="$connectopts -U $2"
***************
*** 112,118 ****
          connectopts="$connectopts $1"
          ;;
      --user=*|--username=*)
!         connectopts="$connectopts -U "`echo $1 | sed 's/^--user[^=]*=//'`
          ;;
      -W|--password)
          connectopts="$connectopts -W"
--- 112,118 ----
          connectopts="$connectopts $1"
          ;;
      --user=*|--username=*)
!         connectopts="$connectopts -U `echo $1 | sed 's/^--user[^=]*=//'`"
          ;;
      -W|--password)
          connectopts="$connectopts -W"
***************
*** 125,130 ****
--- 125,134 ----
          -g|--globals-only)
                  globals_only=yes
                  ;;
+         -F*|--format=*|-f|--file=*|-t|--table=*)
+                 echo "pg_dump can not process option $1, exiting" 1>&2
+                 exit 1
+                 ;;
          *)
                  pgdumpextraopts="$pgdumpextraopts $1"
                  ;;
***************
*** 214,225 ****
  # We skip databases marked not datallowconn, since we'd be unable to
  # connect to them anyway (and besides, we don't want to dump template0).

- DATABASES=""
-
  $PSQL -d template1 -At -F ' ' \
    -c "SELECT datname, coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database
wheredatname='template0'))), pg_encoding_to_char(d.encoding), datistemplate, datpath FROM pg_database d LEFT JOIN
pg_shadowu ON (datdba = usesysid) WHERE datallowconn ORDER BY 1;" | \ 
  while read DATABASE DBOWNER ENCODING ISTEMPLATE DBPATH; do
-     DATABASES="$DATABASES $DATABASE"

      if [ "$DATABASE" != template1 ] ; then
      echo
--- 218,226 ----
***************
*** 242,248 ****
      fi
  done

! for DATABASE in $DATABASES; do
      echo "dumping database \"$DATABASE\"..." 1>&2
      echo
      echo "--"
--- 243,251 ----
      fi
  done

! $PSQL -d template1 -At -F ' ' \
!   -c "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;" | \
! while read DATABASE; do
      echo "dumping database \"$DATABASE\"..." 1>&2
      echo
      echo "--"