Re: Providing the password to psql from a script - Mailing list pgsql-general

From Richard Huxton
Subject Re: Providing the password to psql from a script
Date
Msg-id 40BD8FC4.50108@archonet.com
Whole thread Raw
In response to Providing the password to psql from a script  (Willem Herremans <willem.herremans@belgacom.net>)
List pgsql-general
Willem Herremans wrote:
> I am developing a client application for postgreSQL in Tcl/Tk (see
> http://gborg.postgresql.org/project/pfm ).
>
> It mainly uses PgTcl or pgintcl. I don't have any problems with those,
> but I am also trying to call psql from my application for SQL statements
> typed directly by the user.
>
> I have used the Tcl command
>
>    set psqlChannel [open "|psql $dbname" RDWR]
>
> to create a channel that effectively becomes the input/output channel
> for psql. By writing to that channel, SQL statements are sent to psql,
> by reading from that channel, the results are received from psql.
>
> That works fine, as long as psql does not prompt for a password. The
> problem is that psql does not use this channel for prompting for or
> reading the password. Instead, the password is prompted for on, and read
> from, the terminal from which the tcl application was started and that
> is not what I want, because the Tcl application has already received the
> password from the user. It is, as if psql does not use stdout and stdin
> for the password.

You need to look in the libpq section of the manuals. There is a
PGPASSWORD environment variable, but that is deprecated. The preferred
method is to create a ~/.pgpass file containing password information.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Dynamic SQL
Next
From: Thomas Schoen
Date:
Subject: Re: ORDER BY with plpgsql parameter