Обсуждение: login error - Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "kamik"
Hi guys, I am trying connect to Postgres by PHP. I have this PHP code: But web browser writes this error: Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "***" FATAL: password authentication failed for user "***" in /var/www/test/index.php on line 6 Warning: pg_last_error(): No PostgreSQLlink opened yet in /var/www/test/index.php on line 7 Could not connect: Main problem is that I have bad authentication for my user. In my pg_hba.conf is this: # Database administrative login by UNIX sockets local all postgres ident # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust host all all 0.0.0.0/0 md5 hostssl all all 0.0.0.0/0 md5 hostnossl all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 md5 And in postgresql.conf I set listen_addresses = "*" When I delete in PHP script in pg_connect host="localhost", then all works fine, because I use UNIX domain socket (I am thinging...), but when I use "normal" connection, it is wrong. Interesting is that phppgadmin works fine ... . So, question is what I do wrong. I thing that I have mistake in pg_hba.conf, but I am blind. I have postgresql-8.4 Best regards J.K.
=?UTF-8?B?SmFyb23DrXIgS2FtbGVy?= <kamler@centrum.cz> writes: > But web browser writes this error: > Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "***" FATAL: password authentication failed for user "***" in /var/www/test/index.php on line 6 Warning: pg_last_error(): No PostgreSQLlink opened yet in /var/www/test/index.php on line 7 Could not connect: What it looks like is your script isn't supplying the right password. > When I delete in PHP script in pg_connect host="localhost", then all > works fine, because I use UNIX domain socket (I am thinging ...), You've got auth method set to "trust" for local connections, so in that case it's not going to matter whether the script has the right password. regards, tom lane
Just a quick obvious check - can you ping localhost?
2010/11/12 Jaromír Kamler <kamler@centrum.cz>
Hi guys,
I am trying connect to Postgres by PHP. I have this PHP code:
But web browser writes this error:
Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "***" FATAL: password authentication failed for user "***" in /var/www/test/index.php on line 6 Warning: pg_last_error(): No PostgreSQL link opened yet in /var/www/test/index.php on line 7 Could not connect:
Main problem is that I have bad authentication for my user. In my pg_hba.conf is this:
# Database administrative login by UNIX sockets
local all postgres ident
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
hostssl all all 0.0.0.0/0 md5
hostnossl all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
And in postgresql.conf I set listen_addresses = "*"
When I delete in PHP script in pg_connect host="localhost", then all works fine, because I use UNIX domain socket (I am thinging ...), but when I use "normal" connection, it is wrong. Interesting is that phppgadmin works fine ... .
So, question is what I do wrong. I thing that I have mistake in pg_hba.conf, but I am blind. I have postgresql-8.4
Best regards
J.K.
--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Odd - can't explain that. I've just tried creating a new user with the syntax you used and it worked fine when connecting in afterwards.
The only possible explanation I can think of is a typo when you created the original password (or CAPS etc) or possibly a difference in the character set between the command line createuser executable and psql (I'm clutching at straws though).
I personally avoid the command line utilities and do everything through psql. Not to say they shouldn't work reliably though.
Glad its working now though!
The only possible explanation I can think of is a typo when you created the original password (or CAPS etc) or possibly a difference in the character set between the command line createuser executable and psql (I'm clutching at straws though).
I personally avoid the command line utilities and do everything through psql. Not to say they shouldn't work reliably though.
Glad its working now though!
2010/11/12 Jaromír Kamler <kamler@centrum.cz>
Thanks for reply, that is it. I altered user, set same password and it works!!! Why? I can not understand it. My user postgis was created by user postgres by command createuser postgis -s -d -P -E and then I typed the same pwd like now. I still do not know where was problem. Any ideas? I know that it is not much important now, but for better understanding PostgreSQL it is good to know.
Best regards> Datum: 12.11.2010 22:55
Jaromir Kamler
______________________________________________________________
> Od: "LazyTrek" <lazytrek@gmail.com>
> Komu: Jaromír Kamler <kamler@centrum.cz>
> Předmět: Re: [NOVICE] login error - Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "kamik"
>
Jaromir,
I'm a novice myself so apologies if I'm of no help but I thought I'd try.
I've just tested your pg_hba.conf with a test database. I hit problems too where the user was not set up with a password but the UNIX login would obviously still let it login.
If you're willing to give something else a go, can you use a working method to connect to the database and issue the following -
ALTER USER <user> encrypted password '<password>';
Then reattempt the localhost connection string.
Hope you don't mind another novice offering you advice but sometimes it just needs a second pair of eyes!2010/11/12 Jaromír Kamler <kamler@centrum.cz>quick answer:
YES
phppgadmin works, pgAdmin III works, PHP framework CodeIgniter works when i set this $db['default']['hostname'] = ""; but when I set localhost, there is problem.
Regards
Jaromir Kamler
______________________________________________________________
> Od: "LazyTrek" <lazytrek@gmail.com>
> Komu: Jaromír Kamler <kamler@centrum.cz>
> Datum: 12.11.2010 22:24
> Předmět: Re: [NOVICE] login error - Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "kamik"
>
Just a quick obvious check - can you ping localhost?2010/11/12 Jaromír Kamler <kamler@centrum.cz>
Hi guys,
I am trying connect to Postgres by PHP. I have this PHP code:
But web browser writes this error:
Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "***" FATAL: password authentication failed for user "***" in /var/www/test/index.php on line 6 Warning: pg_last_error(): No PostgreSQL link opened yet in /var/www/test/index.php on line 7 Could not connect:
Main problem is that I have bad authentication for my user. In my pg_hba.conf is this:
# Database administrative login by UNIX sockets
local all postgres ident
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
hostssl all all 0.0.0.0/0 md5
hostnossl all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
And in postgresql.conf I set listen_addresses = "*"
When I delete in PHP script in pg_connect host="localhost", then all works fine, because I use UNIX domain socket (I am thinging ...), but when I use "normal" connection, it is wrong. Interesting is that phppgadmin works fine ... .
So, question is what I do wrong. I thing that I have mistake in pg_hba.conf, but I am blind. I have postgresql-8.4
Best regards
J.K.
--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
On 2010-11-12, Jaromír Kamler <kamler@centrum.cz> wrote: > > Main problem is that I have bad authentication for my user. In my pg_hba.conf is this: > # Database administrative login by UNIX sockets > local all postgres ident > # TYPE DATABASE USER CIDR-ADDRESS METHOD > # "local" is for Unix domain socket connections only > local all all trust > # IPv4 local connections: > host all all 127.0.0.1/32 trust > host all all 0.0.0.0/0 md5 > hostssl all all 0.0.0.0/0 md5 > hostnossl all all 0.0.0.0/0 md5 > # IPv6 local connections: > host all all ::1/128 md5 > When I delete in PHP script in pg_connect host="localhost", then all works fine, because I use UNIX domain socket (I amthinging ...), but when I use "normal" connection, it is wrong. Interesting is that phppgadmin works fine ... . > > So, question is what I do wrong. I thing that I have mistake in pg_hba.conf, but I am blind. I have postgresql-8.4 what address is "localhost"? I'm guessing it's not what you think it is. -- ⚂⚃ 100% natural