Mika Fischer [2008-03-17 10:19 +0000]: > Description: psql should provide option to not prompt for password > Details: > > Hi, > > I'm currently working on the bash-completion package. The problem with > postgresql is that psql cannot safely be called because there is no way to > know whether it will prompt for a password and there is also no way to avoid > the prompt. > > Needless to say a password prompt is very bad in the context of > tab-completion. > > Ideally, psql should provide an option --no-password which would cause it to > never promt for a password, and in case one is needed, fail as if a wrong > one was given. > > However if you can think of an easier way to accomplish this, I'd be > grateful for pointers.
Indeed I have a similar problem. I use psql to probe for actual availability of cluster startup in the integration scripts (pg_ctl does not provide that) and also stumbled over this. Earlier versions did not prompt if PGPASSWD was supplied, 8.3 changed this behaviour. That's why I applied the attached patch to the Debian/Ubuntu packages to restore the older behaviour, which works pretty well. I already proposed that some months ago [1], but didn't get very far. Martin [1] http://www.mail-archive.com/pgsql-bugs@postgresql.org/msg18440.html -- Martin Pitt | http://www.piware.de Ubuntu Developer (www.ubuntu.com) | Debian Developer (www.debian.org)
# Description: Change psql to not prompt for a password if PGPASSWORD is given, just as in earlier versions. Without that, there is no way to suppress the password input prompt, which is bad for scripts. --- postgresql-8.3RC1/src/bin/psql/startup.c 2008-01-04 14:48:17.000000000 +0100 +++ postgresql-8.3RC1/src/bin/psql/startup.c 2008-01-04 14:49:24.000000000 +0100 @@ -199,7 +199,7 @@ if (PQstatus(pset.db) == CONNECTION_BAD && PQconnectionNeedsPassword(pset.db) && - password == NULL && + password == NULL && !getenv("PGPASSWORD") && !feof(stdin)) { PQfinish(pset.db);
signature.asc
Description: Digital signature