Thread: php + postgresql pg_connect problem

php + postgresql pg_connect problem

From
John Taber
Date:
I am having trouble connecting php(5.1.1) and postgresql(8.1) running on
Ubuntu Breezy. Both run fine separately. I created a user (tempuser) and
a database (tempdb).  If I run psql -l it shows the database "tempdb"
with the username "tempuser".  But I get the following error using
pg_connect:

Warning: pg_connect() [function.pg-connect]: Unable to connect to
PostgreSQL server: FATAL: Ident authentication failed for user
"tempuser" in /var/www/db_connect.php on line 14

The line 14 is the pg_connect statement:
    $dbname = "tempdb";
    $user = "tempuser";
    $pass = "";
    $dbstr = "dbname=" . $dbname;
    $dbstr .= " user=" . $user;
    //$dbstr .= " password=" . $pass;
    return(pg_connect($dbstr));

Now I did not create a password when I created the user and in
pg_connect just use the dbname and username values - is that a problem?
thanks.
ps: I tried it with the password value but that failed with same error.


Re: php + postgresql pg_connect problem

From
Richard Huxton
Date:
John Taber wrote:
> I am having trouble connecting php(5.1.1) and postgresql(8.1) running on
> Ubuntu Breezy. Both run fine separately. I created a user (tempuser) and
> a database (tempdb).  If I run psql -l it shows the database "tempdb"
> with the username "tempuser".  But I get the following error using
> pg_connect:
>
> Warning: pg_connect() [function.pg-connect]: Unable to connect to
> PostgreSQL server: FATAL: Ident authentication failed for user
> "tempuser" in /var/www/db_connect.php on line 14

You are using "ident" authentication in your pg_hba.conf file. You
probably don't want this. Start with trust if you are connecting
locally, then turn passwords on once you are happy you can connect.

--
   Richard Huxton
   Archonet Ltd

Re: php + postgresql pg_connect problem

From
John Taber
Date:
Richard Huxton wrote:
> John Taber wrote:
>
>> I am having trouble connecting php(5.1.1) and postgresql(8.1) running on
>> Ubuntu Breezy. Both run fine separately. I created a user (tempuser) and
>> a database (tempdb).  If I run psql -l it shows the database "tempdb"
>> with the username "tempuser".  But I get the following error using
>> pg_connect:
>>
>> Warning: pg_connect() [function.pg-connect]: Unable to connect to
>> PostgreSQL server: FATAL: Ident authentication failed for user
>> "tempuser" in /var/www/db_connect.php on line 14
>
>
> You are using "ident" authentication in your pg_hba.conf file. You
> probably don't want this. Start with trust if you are connecting
> locally, then turn passwords on once you are happy you can connect.

Thks for directing me to the pg_hda file - I have made the changes - But
I may have a bigger problem (postmaster).  I tried to restart postmaster
and found that I don't have a pg_ctl program or script in my /usr/bin
There is a pg_ctlcluster.  Is that new and replaces pg_ctl ?  Any reason
pg_ctl could be missing (am I missing a package ?).  While on this
subject, is there a way to ensure postmaster is started on boot - I see
postgres scripts in the /etc/rd.d folder - is that enough?  I have the
Douglas postgresql book to follow details (but haven't read it all) thks.

Re: php + postgresql pg_connect problem

From
Richard Huxton
Date:
John Taber wrote:
>> You are using "ident" authentication in your pg_hba.conf file. You
>> probably don't want this. Start with trust if you are connecting
>> locally, then turn passwords on once you are happy you can connect.
>
> Thks for directing me to the pg_hda file - I have made the changes - But
> I may have a bigger problem (postmaster).  I tried to restart postmaster
> and found that I don't have a pg_ctl program or script in my /usr/bin
> There is a pg_ctlcluster.  Is that new and replaces pg_ctl ?  Any reason
> pg_ctl could be missing (am I missing a package ?).  While on this
> subject, is there a way to ensure postmaster is started on boot - I see
> postgres scripts in the /etc/rd.d folder - is that enough?  I have the
> Douglas postgresql book to follow details (but haven't read it all) thks.

Ubuntu is basically Debian, and Debian has wrappers so you can run
different versions of PostgreSQL on the same machine. I'm assuming
you've installed from packages, not compiled from source yourself.

On my Debian box, pg_ctl is in /usr/lib/postgresql/bin/, but don't
worry, you don't need to mess with it.
In /etc/init.d/ you'll see a series of scripts that can start/stop
system services. You can run them manually (as root - they switch user
as required) and they also get run from links in /etc/rcX.d (X=1..6)
during startup. There is documentation online about how all this works.

So, on ubuntu you can do the following:
sudo su -
/etc/init.d/postgresql start|stop|reload...
exit

If you run the postgresql script without a parameter, it will show you
all the options.

--
   Richard Huxton
   Archonet Ltd