Re: Providing the password to psql from a script

From: Willem Herremans <willem(dot)herremans(at)belgacom(dot)net>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Providing the password to psql from a script
Date: 2004-02-15 12:23:22
Message-ID: 402F64BA.1090803@belgacom.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stephan Szabo wrote:

>On Sun, 15 Feb 2004, Willem Herremans wrote:
>
>
>
>>Martijn van Oosterhout wrote:
>>
>>
>>
>>>On Sat, Feb 14, 2004 at 05:11:14PM +0100, Willem Herremans wrote:
>>>
>>>
>>>
>>>
>>>>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.
>>>>
>>>>
>>>>
>>>>
>>>Look in the manpage for psql, there are several ways to stop it asking for
>>>passwords, including the PGPASS environment variable, tne .pgpass file and
>>>setting the user as trust in the config.
>>>
>>>Any of these will do what you want...
>>>
>>>Hope this helps,
>>>
>>>
>>>
>>>
>>I am afraid this does not help me very much.
>>
>>The manpage of psql neither mentions the PGPASS environment variable,
>>nor the .pgpass file.
>>
>>
>
>It's actually in the libpq documentation...
>
>The file .pgpass in a user's home directory is a file
>that can contain passwords to be used if the connection requires a
>password (and no password has been specified otherwise).
>This file should have lines of the following format:
>hostname:port:databsae:username:password
>
>Each of the first four fields may be a literal value, or * which matches
>anything. The password field from the first line that matches the
>current connection parameters will be used. (Therefore, put more-specific
>entries first when you are using wildcards.)
>If an entry needs to contain : or
>\, escape this character with \.
>
>The permissions on .pgpass must disallow any
>access to world or group; achieve this by the command
>chmod 0600 ~/.pgpass
>If the permissions are less strict than this, the file will be ignored.
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>
>
>
>
Marvellous!. That solves my problem!

Thank you.

Willem Herremans

--
Willem Herremans E-mail: willem(dot)herremans(at)belgacom(dot)net
Dennenlaan 55
B-2520 Ranst Tel. : +32 3 485 64 09
BELGIUM

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-02-15 16:34:01 Re: SQL99 IGNORE
Previous Message Martijn van Oosterhout 2004-02-15 09:50:35 Re: Providing the password to psql from a script