/var/lib/pgsql/data/pg_hba.conf
Installation and configuration of the CentOS 6.3 under PostgreSQL
Http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html
PostgresAdmin3
Http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html
Http://jingyan.baidu.com/article/3ea51489ec3cb452e71bba52.html
Http://developer.51cto.com/art/201401/426225.htm
Debugging methods
[Email protected] ~]# php/var/www/html/pgsql.php
PHP Warning:pg_connect (): Unable to connect to PostgreSQL server:FATAL:Ident authentication failed for user "Postgres "In/var/www/html/pgsql.php on line 3
Connection failed, unable to connect to database [[email protected] ~]#
Looks like an account password problem.
The PostgreSQL database is created by default to create a Postgres database user as the administrator of the database, the default password is empty, we need to change to the specified password, which is set to ' Postgres '.
# Su-postgres
$ psql
postgres=# ALTER USER postgres with PASSWORD ' postgres ';
ALTER ROLE
postgres=# select * from Pg_shadow;
Usename | Usesysid | Usecreatedb | Usesuper | USECATUPD | passwd
| Valuntil | Useconfig
----------+----------+-------------+----------+-----------+---------------------
----------------+----------+-----------
Dbuser | 16384 | f | f | f | Md5baa6c789c3728a1a4
49b82005eb54a19 | |
Postgres | 10 | T | T | T | md53175bce1d3201d165
94cebf9d7eb3f9d | |
(2 rows)
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access Privileg
Es
-----------+----------+----------+-------------+-------------+------------------
-----
David | Postgres | UTF8 | en_US. UTF-8 | en_US. UTF-8 |
Postgres | Postgres | UTF8 | en_US. UTF-8 | en_US. UTF-8 |
Template0 | Postgres | UTF8 | en_US. UTF-8 | en_US. UTF-8 | =c/postgres
: Postgres=ctc/post
Gres
template1 | Postgres | UTF8 | en_US. UTF-8 | en_US. UTF-8 | =c/postgres
: Postgres=ctc/post
Gres
TestDB | Dbuser | UTF8 | en_US. UTF-8 | en_US. UTF-8 | =tc/dbuser
: Dbuser=ctc/dbuser
(5 rows)
postgres=# ALTER USER dbuser with PASSWORD ' dbuser ';
ALTER ROLE
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access Privileg
Es
-----------+----------+----------+-------------+-------------+------------------
-----
David | Postgres | UTF8 | en_US. UTF-8 | en_US. UTF-8 |
Postgres | Postgres | UTF8 | en_US. UTF-8 | en_US. UTF-8 |
Template0 | Postgres | UTF8 | en_US. UTF-8 | en_US. UTF-8 | =c/postgres
: Postgres=ctc/post
Gres
template1 | Postgres | UTF8 | en_US. UTF-8 | en_US. UTF-8 | =c/postgres
: Postgres=ctc/post
Gres
TestDB | Dbuser | UTF8 | en_US. UTF-8 | en_US. UTF-8 | =tc/dbuser
: Dbuser=ctc/dbuser
(5 rows)
However, there are still ident authentication failed for the user error,
Try to modify/var/lib/pgsql/data/pg_hba.conf, remove
#host All 127.0.0.1/32 ident
Service PostgreSQL Restart
Service httpd Restart
Service PostgreSQL Restart
Re-execute PHP, found this dbuser can access, just dbuser database does not exist
[Email protected] ~]# php/var/www/html/pgsql.php
PHP Warning:pg_connect (): Unable to connect to PostgreSQL server:FATAL:database ' dbuser ' does not exist in/var/www/h Tml/pgsql.php on line 3
Connection failed, unable to connect to database [[email protected] ~]#
To modify a PHP script:
<?php
Connect, select Database
$dbconn = Pg_connect ("host=127.0.0.1 dbname=david user=dbuser password=dbuser");
See if we connection was successful
if (! $dbconn) {
Connection failed-exit the page with an error
You could also try to proceed without the
Database-it ' s up to you
echo "Connection failed, cannot connect to database";
Exit
}else{
echo "Connected successfully";
}
echo "<br>php configuration details are as follows:";
Echo Phpinfo ();
Close connection
Pg_close ($dbconn);
?>
This time the command line executes PHP can display the data successfully, but executes the script in Firefox, still displays the error, why?