“FATAL: no pg_hba.conf entry for host” but I can connect trough pgAdmin

余生颓废 提交于 2019-12-11 05:23:38

问题


I'm having a little trouble with my dev environment for a CakePHP based project. The thing is, CakePHP can connect in production, but if I run trough XAMPP on my PC, then throws me a FATAL: no pg_hba.conf entry for host "myexternalip", user "dbuser", database "dbname", SSL off

but using the same parameters I can connect from my PC trough pgAdmin.

I've tried some googling tips that I've found like copy the libpq.dll from c:\xampp\php to c:\xampp\apache\bin but, no luck, had checked pnp.ini and extension=php_pdo_pgsql.dll line is uncommented, had tried reboot apache several times but nothing changes

The project is hosted under heroku platform and my /app/config/database.php looks like

public $production = array(
    'datasource' => 'Database/Postgres',
    'persistent' => false,
    'host' => 'anywhere.at.amazonaws.com',
    'login' => 'dbuser',
    'password' => 'dbpwd',
    'database' => 'dbname',
    'encoding' => 'utf8',
);

here's the Stack Trace

- CORE\Cake\Model\Datasource\DboSource.php line 260 → Postgres->connect()
- CORE\Cake\Model\ConnectionManager.php line 105 → DboSource->__construct(array)
- CORE\Cake\Model\Model.php line 3613 → ConnectionManager::getDataSource(string)
- CORE\Cake\Model\Model.php line 1155 → Model->setDataSource(string)
- CORE\Cake\Model\Model.php line 3640 → Model->setSource(string)
- CORE\Cake\Model\Model.php line 827 → Model->getDataSource()

Can anyone give me another hint that could help?


回答1:


After while I found a solution.

The problem is that's not straightforward.

As the Postgres server is hosted under heroku platform, the default configuration on server is require ssl, so I've came across to this configuration:

public $production = array(
    ......
    'sslmode' => 'require',
);

Now the error has changed to a sslmode value "require" invalid when ssl support is not compiled

then I've googled it and seems that at least under XAMPP v5.5.19, the libpq.dll inside PHP folder wasn't compiled with ssl support

here's the question that helped me solve this problem: How to installPostgreSQL client library for PHP on Windows with SSL enabled

Seems that pgAdmin's libpq.dll was compiled with ssl support, so that is the cause that I could connect through pgAdmin, but not with php

thanks for help folks!



来源:https://stackoverflow.com/questions/29738989/fatal-no-pg-hba-conf-entry-for-host-but-i-can-connect-trough-pgadmin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!