无法通过 Laravel SQLSTATE [08006] [7] FATAL 连接到 PgSQL

2022-01-13 00:00:00 postgresql centos php laravel sysadmin

我正在尝试通过 laravel 连接到 pgsql,并最终完成了所有设置(运行 pgsql 服务器,安装了 pdo,安装了所有库).我在通过 CPanel/WHM 管理的 VPS (CentOS) 上运行.

I'm trying to connect to pgsql via laravel and finally got everything setup (pgsql server running, pdo installed, all libs installed). I'm running on a VPS (CentOS) managed via CPanel/WHM.

这就是我正在做的事情:我正在尝试使用 migrate:install 通过 artisan(Laravel 的命令行)创建一个用户数据库.

Here's what I'm doing: I'm trying to create a user database via artisan (Laravel's command line) using migrate:install.

对于不使用 Laravel 的,artisan 使用 php 的 PDO 进行 pgsql 连接.这是我的设置:

For those that don't use Laravel, artisan uses php's PDO for pgsql to connect. Here are my settings:

    'pgsql' => array(
        'driver'   => 'pgsql',
        'host'     => 'localhost',
        'database' => 'dbname',
        'username' => 'username',
        'password' => 'password',
        'charset'  => 'utf8',
        'prefix'   => '',
    ),

我还设置了一个 test.php 文件:

I've also setup a test.php file:

$dbconn = pg_connect("host=localhost port=5432 dbname=dbname user=username password=password");

这也失败了.我使用 phpPgAdmin 来查看发生了什么,并且所有权限都设置正确,数据库显示,用户名正确,密码相同.我检查了 postgre(版本 8.4.12 btw)在哪里运行,phpPgAdmin 告诉我localhost:5432".

which also fails. I used phpPgAdmin to see what's up and all of the permissions are set correctly, the database shows up, the username is correct, same with password. I checked where postgre (version 8.4.12 btw) was running and phpPgAdmin tells me "localhost:5432".

我通过命令行得到的错误如下:

The error I get via the command line is the following:

SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host "::1", user "myusername", database "my_database", SSL OFF

现在,我试图找到 pg_hba.conf 文件,但我不完全确定在哪里寻找它.pg 的错误/访问日志也是如此,就这一点而言,谷歌没有任何帮助.

Now, I tried to find the pg_hba.conf file but I'm not entirely sure where to look for it. Same goes for the error/access logs for pg and google hasn't been any help as far as this goes.

知道我能做什么吗?

推荐答案

localhost 指向您系统上的 IPV6 ::1 地址.Postgresql 在处理访问列表时会区分 ipv6 和 ipv4 地址.

localhost points to IPV6 ::1 address on your system. Postgresql makes the difference between ipv6 and ipv4 addresses when dealing with access list.

相关文章