Обсуждение: Postgresql newbie username/password question

Поиск
Список
Период
Сортировка

Postgresql newbie username/password question

От
Gary
Дата:
I've just installed v7.1 and got the DBD stuff working so I'm able to
connect to a test database and return data within a perl script.

I'm slightly confused how the concept of user authentication works in
Postgresql.  I ideally need to have a specific user to connect to a
database from the web, how do I pass this detail through the DBD, I
don't see an option in the connect string.  I was using Oracle and you
could specify user and password details to the connect string okay ?  Am
I missing something obvious ?

Do I need to do some setup with the hba.conf file for 'local' users ?




Re: Postgresql newbie username/password question

От
will trillich
Дата:
On Wed, May 09, 2001 at 01:58:10AM -0700, Gary wrote:
> I've just installed v7.1 and got the DBD stuff working so I'm able to
> connect to a test database and return data within a perl script.
>
> I'm slightly confused how the concept of user authentication works in
> Postgresql.  I ideally need to have a specific user to connect to a
> database from the web, how do I pass this detail through the DBD, I
> don't see an option in the connect string.  I was using Oracle and you
> could specify user and password details to the connect string okay ?  Am
> I missing something obvious ?

probably.

presuming you're talking about DBD::Pg for perl (used via DBI):

    % man DBD::Pg

    The following connect statement shows all possible
    parameters:

     $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host;port=$port;options=$options;tty=$tty", "$username",
"$password");

    If a parameter is undefined PostgreSQL first looks for
    specific environment variables and then it uses hard
    coded defaults:

       parameter  environment variable  hard coded default
       --------------------------------------------------
       dbname     PGDATABASE            current userid
       host       PGHOST                localhost
       port       PGPORT                5432
       options    PGOPTIONS             ""
       tty        PGTTY                 ""
       username   PGUSER                current userid
       password   PGPASSWORD            ""

so if you authenticate somehow and get a $username you'll also need the
matching $password to use like so--

    my $DSN = "dbi:Pg:dbname=$database";
    $dbh = DBI->connect($DSN,$username,$password);

before then, of course, you'll need to establish postgresql awareness of the
various users you're interested in having log in (from the web server machine,
which may be localhost) and connect.

--
don't visit this page. it's bad for you. take my expert word for it.
http://www.salon.com/people/col/pagl/2001/03/21/spring/index1.html

will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!