pg_connect troubles on localhost

Started by John Taberover 20 years ago5 messagesgeneral
Jump to latest
#1John Taber
jtaber@johntaber.net

using postgresql 8.1 on Ubuntu Breezy
I cannot connect to a database I created - checking \du the username is
listed. I also created a password with #ALTER ROLE yyyy WITH PASSWORD
'zzzz' I tried without password but it calls for a password. Any ideas?

<?php
$vhost = 'localhost';
$vname = 'xxxx';
$vuser = 'yyyy';
$vpassword = 'zzzz';
$db_handle = pg_connect("dbname=$vname user=$vuser password=$vpassword");
pg_close($db_handle);
?>

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

#2Jerry Sievers
jerry@jerrysievers.com
In reply to: John Taber (#1)
Re: pg_connect troubles on localhost

John Taber <jtaber@johntaber.net> writes:

using postgresql 8.1 on Ubuntu Breezy
I cannot connect to a database I created - checking \du the username is
listed. I also created a password with #ALTER ROLE yyyy WITH PASSWORD
'zzzz' I tried without password but it calls for a password. Any ideas?

<?php
$vhost = 'localhost';
$vname = 'xxxx';
$vuser = 'yyyy';
$vpassword = 'zzzz';
$db_handle = pg_connect("dbname=$vname user=$vuser password=$vpassword");
pg_close($db_handle);
?>

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

See to it that there's an entry in pg_ident.conf to map the webserver
process owner to your vuser DB username.

The error message is telling you that your pg_hba.conf file has an
entry for the database that uses the ident map file.

See comments in both files and the Postgres docs as well for more
info.

HTH

--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/

#3John Taber
jtaber@johntaber.net
In reply to: Jerry Sievers (#2)
Re: pg_connect troubles on localhost

thks for info - but my pg_ident is empty (correctly I believe since
users are equal to pg_users) so I have:

pg_ident.conf
# MAPNAME IDENT-USERNAME PG-USERNAME

pg_hba.conf
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident sameuser

I don't want to start manually editing these files before figuring out
what is going wrong or if something, somehow got corrupted, then how to
clean up and recreate. I am just starting out, so I can delete and
start over if I need to. Any ideas ?

Jerry Sievers wrote:

Show quoted text

John Taber <jtaber@johntaber.net> writes:

using postgresql 8.1 on Ubuntu Breezy
I cannot connect to a database I created - checking \du the username is
listed. I also created a password with #ALTER ROLE yyyy WITH PASSWORD
'zzzz' I tried without password but it calls for a password. Any ideas?

<?php
$vhost = 'localhost';
$vname = 'xxxx';
$vuser = 'yyyy';
$vpassword = 'zzzz';
$db_handle = pg_connect("dbname=$vname user=$vuser password=$vpassword");
pg_close($db_handle);
?>

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

See to it that there's an entry in pg_ident.conf to map the webserver
process owner to your vuser DB username.

The error message is telling you that your pg_hba.conf file has an
entry for the database that uses the ident map file.

See comments in both files and the Postgres docs as well for more
info.

HTH

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: John Taber (#3)
Re: pg_connect troubles on localhost

John Taber <jtaber@johntaber.net> writes:

# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident sameuser

"ident sameuser" means you can only connect as the PG user with the same
name as the operating system account that's running the program you try
to connect from. (In the case of a PHP program that's probably going to
be the Apache daemon user.) Passwords are not relevant for ident auth.

regards, tom lane

#5John Taber
jtaber@johntaber.net
In reply to: Tom Lane (#4)
Re: pg_connect troubles on localhost

Hmmm, I have no idea what the Apache daemon user is(root?) but not sure
how to check. So what would be the workaround ? Should I setup users
as different from OS user names ?

Tom Lane wrote:

Show quoted text

John Taber <jtaber@johntaber.net> writes:

# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident sameuser

"ident sameuser" means you can only connect as the PG user with the same
name as the operating system account that's running the program you try
to connect from. (In the case of a PHP program that's probably going to
be the Apache daemon user.) Passwords are not relevant for ident auth.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings