title: Perl - Connect to PostgreSQL Database - Failing to find proper socket
body: <p>I can connect fine with PHP and locally using Psql, but Perl does not.  </p>
  
  <pre><code>my $dbh = DBI-&gt;connect("DBI:Pg:dbname=mydb,host=localhost:5432","user","pass",{'RaiseError' =&gt; 1});
  </code></pre>
  
  <p>I believe the error is because my socket is in tmp:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>And when I run my simple perl script it seems to look in /var/run:</p>
  
  <pre><code>./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
  </code></pre>
  
  <p>I tried to simply create a symlink, but that doesn't seem to be working:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Some other simple stuff:
  pg_hba.conf trusts all localhost connections as well as those of my subnet.</p>
  
  <p>postgresql.conf has the following:<br>
      listen_addresses = '*'</p>