Search code examples
phppostgresqlplesk

Cannot authenticate in PostgreSQL DB on plesk


We have just installed the PostgreSQL component into plesk but we cannot authenticate using the PHP function @pg_connect()

$connection = @pg_connect("host=localhost port=5432 dbname=my_db_name user=my_user password=my_pwd");
output("Connection: ".$connection);

The error is showed in the connection object that is printed:

Connection: 
Array
(
    [type] => 2
    [message] => pg_connect(): Unable to connect to PostgreSQL server: FATAL:  Ident authentication failed for user "my_user"
    [file] => path/to/my/script.php
    [line] => 5
)

Does anyone tried to use PostgreSQL DB on plesk? Did you use some 'default' username and password ?


Solution

  • Finally we found out that, in Linux, the default installation of PostgreSQL doesn't accept access through network socket connection but only through Unix socket.

    So I can connect to DB using the default Unix socket, and the correct @pg_connect instruction is:

    $connection = @pg_connect("host='' port='' dbname=my_db_name user=my_user password=my_pwd");