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 = '*'