Thread: BUG #2931: Can't capture pg_dump Password prompt

BUG #2931: Can't capture pg_dump Password prompt

From
"Michael Schmidt"
Date:
The following bug has been logged online:

Bug reference:      2931
Logged by:          Michael Schmidt
Email address:      MichaelMSchmidt@msn.com
PostgreSQL version: 8.2
Operating system:   Windows XP Pro
Description:        Can't capture pg_dump Password prompt
Details:

I have a Java user app that allows database backup and restore by accessing
pg_dump and pg_restore.  With PostgreSQL version 8.1, I was able to capture
the Password: prompt on stderr, which allowed me to send to password at the
proper time.  This no longer works with PostgreSQL 8.2.  I've worked on this
for three days and even wrote a separate Java app to test various PostgreSQL
utilities, posting results on the General list (got no help there).  I
further confirmed the behavior by redirecting stderr from Windows cmd.exe.
Although the password prompt appears on the screen, it does not appear to be
in either stdout or stderr.  For Windows command prompt, the following was
used:
pg_dump.exe -Upostgres --host=localhost --port=5432 -W -v
--file=E:\Backup\test.bak npbase 2>>log.txt

As expected from using -v, a nice log of output was present in log.txt but
not the "Password: " prompt.  I will supply the Java test app if you like.


If the prompt is, in fact, being output on stderr, it cannot be accessed
from either cmd.exe or Java.  If it has been changed, documentation on how
to access it would be useful for app developers.

Incidentally, I also found that when pg_restore is run without any
parameters it hangs.  Shouldn't it close neatly with an error message?

Thanks for your time!

Re: BUG #2931: Can't capture pg_dump Password prompt

From
Magnus Hagander
Date:
Michael Schmidt wrote:
> The following bug has been logged online:
>
> Bug reference:      2931
> Logged by:          Michael Schmidt
> Email address:      MichaelMSchmidt@msn.com
> PostgreSQL version: 8.2
> Operating system:   Windows XP Pro
> Description:        Can't capture pg_dump Password prompt
> Details:
>
> I have a Java user app that allows database backup and restore by accessing
> pg_dump and pg_restore.  With PostgreSQL version 8.1, I was able to capture
> the Password: prompt on stderr, which allowed me to send to password at the
> proper time.  This no longer works with PostgreSQL 8.2.  I've worked on this
> for three days and even wrote a separate Java app to test various PostgreSQL
> utilities, posting results on the General list (got no help there).  I
> further confirmed the behavior by redirecting stderr from Windows cmd.exe.
> Although the password prompt appears on the screen, it does not appear to be
> in either stdout or stderr.  For Windows command prompt, the following was
> used:
> pg_dump.exe -Upostgres --host=localhost --port=5432 -W -v
> --file=E:\Backup\test.bak npbase 2>>log.txt
>
> As expected from using -v, a nice log of output was present in log.txt but
> not the "Password: " prompt.  I will supply the Java test app if you like.
>
>
> If the prompt is, in fact, being output on stderr, it cannot be accessed
> from either cmd.exe or Java.  If it has been changed, documentation on how
> to access it would be useful for app developers.

This is not a bug, it's a feature ;-) It's written to the console, not
to the standard stream. If you launch the tools externally and want to
pass the password, you should either use the pgpass.conf file, or set
the PGPASSWORD (this is safe on Win32).

//Magnus

Re: BUG #2931: Can't capture pg_dump Password prompt

From
Magnus Hagander
Date:
(please keep responses on the list)

Michael Schmidt wrote:
> Mr. Hagander,
> Thanks for taking the time to look at this.  Unfortunately, the 8.2
> documentation and information obtained from 'pg_dump --help' indicate
> PGPASSWORD is no longer available.  Using pgpass.conf creates
> cross-platform issues, as it is stored in different places on different
> systems.

It's definitly still available, see
http://www.postgresql.org/docs/8.2/static/libpq-envars.html.

It may not always be clear, but all the "libpq environment varilables"
apply to all the utilities that are based on libpq, which is pretty much
all of them.

I can see how using pgpass can be a cross platform problem. If you're
doing cross platform, you may have a security problem from PGPASSWORD
though - I don't know the detauls.


> While I understand that sending the Password: prompt to the console is a
> new "feature", the rationale in changing it from stderr is unclear.
> When it is on a *standard* stream it is - well - standard!  This good
> behavior is appreciated by at least one developer (me)!

It was changed to be consistent with Unix, IIRC.


> Given the issues with PGPASSWORD and password.conf, would you folks
> consider putting the Password: prompt back the way it was?

I doubt it. I don't hold a strong opinion myself, but I think it has
been proposed and rejected before.

//Magnus

Re: BUG #2931: Can't capture pg_dump Password prompt

From
Magnus Hagander
Date:
On Sun, Jan 28, 2007 at 09:51:11AM -0700, Michael Schmidt wrote:
> Mr. Hagander,
> I have taken the discussion of the password issue to the General group.  Again, thanks.  There are still two minor
issues.
>
> 1.  Entering pg_restore at the command prompt without any parameters hangs.  Shouldn't it exit neatly with an error
message?

No. It will then try to read the information from stdin. See
http://www.postgresql.org/docs/8.2/static/app-pgrestore.html, under
Optinos.

> 2.  The pg_dump application help (pg_dump --help) states both -U and --username= are valid while the manual (section
VI)only mentions -U.  Should the manual entry be edited? 

Yes, I beleive so. Same problems are present for at least -W also, and
also present on pg_restore. so yes, that should be fixed. I'll try to
put together a patch unless beaten to it.

//Magnus

Re: BUG #2931: Can't capture pg_dump Password prompt

From
"Michael Schmidt"
Date:
Mr. Hagander,
I have taken the discussion of the password issue to the General group.  Ag=
ain, thanks.  There are still two minor issues.

1.  Entering pg_restore at the command prompt without any parameters hangs.=
  Shouldn't it exit neatly with an error message?

2.  The pg_dump application help (pg_dump --help) states both -U and --user=
name=3D are valid while the manual (section VI) only mentions -U.  Should t=
he manual entry be edited?

Thanks again for all your time.
Michael Schmidt=