我可以用 PHP 很好地连接并在本地使用 Psql,但 Perl 不能。
my $dbh = DBI->connect("DBI:Pg:dbname=mydb,host=localhost:5432","user","pass",{'RaiseError' => 1});
我相信错误是因为我的套接字在 tmp 中:
postgres@host/opt/psql/bin $ netstat -an | grep 5432
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
tcp6 0 0 :::5432 :::* LISTEN
unix 2 [ ACC ] STREAM LISTENING 24728255 /tmp/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 24729004 /tmp/.s.PGSQL.5432
当我运行我的简单 perl 脚本时,它似乎在 /var/run 中查找:
./test.pl
DBI connect('dbname=mydb','user',...) failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? at ./test.pl line 6
我试图简单地创建一个符号链接,但这似乎不起作用:
sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
ln: failed to create symbolic link `/var/run/postgresql/.s.PGSQL.5432': No such file or directory
其他一些简单的东西:pg_hba.conf 信任所有 localhost 连接以及我的子网的连接。
postgresql.conf 有以下内容:
listen_addresses = '*'