title: psql can connect to a unix domain socket, but py-postgresql with the same parameters gets 'Permission denied'
body: <h1>Problem description:</h1>
  <p>My system user is <code>milosz</code>, which is mapped to the PostgreSQL user <code>project_great</code> in <code>pg_ident.conf</code>. I am using peer authentication to connect to a PostgreSQL database over a unix domain socket. This connection method works when using <code>psql</code>, but fails to work when using <code>py-postgresql</code> using the same parameters from within a Python script.</p>
  <p>Here I am successfully connecting to the database using <code>psql</code>:</p>
  <pre><code>$ psql -U project_great \
  &gt;      -d project_great \
  &gt;      -h /var/run/postgresql
  psql (9.3.4)
  Type &quot;help&quot; for help.
  
  project_great=&gt; 
  </code></pre>
  <p>Here is <code>database_test.py</code>:</p>
  <pre><code>#!/usr/bin/env python3
  
  import postgresql
  
  params = {
      'user':     'project_great',
      'database': 'project_great',
      'unix':     '/var/run/postgresql',
  }
  
  connection = postgresql.open(**params)
  </code></pre>
  <p>Here I am attempting to connect to the database by running <code>./database_test.py</code>:</p>
  <pre><code>$ ./database_test.py 
  Traceback (most recent call last):
    File &quot;./database_test.py&quot;, line 11, in &lt;module&gt;
      sys.exit(main(sys.argv))
    File &quot;./database_test.py&quot;, line 13, in main
      connection = postgresql.open(**params)
    File &quot;/home/milosz/devel/project_great/.virtualenv/lib/python3.3/site-packages/postgresql/__init__.py&quot;, line 94, in open
      c.connect()
    File &quot;/home/milosz/devel/project_great/.virtualenv/lib/python3.3/site-packages/postgresql/driver/pq3.py&quot;, line 2422, in connect
      self._establish()
    File &quot;/home/milosz/devel/project_great/.virtualenv/lib/python3.3/site-packages/postgresql/driver/pq3.py&quot;, line 2548, in _establish
      self.typio.raise_client_error(could_not_connect, creator = self, cause = exc)
    File &quot;/home/milosz/devel/project_great/.virtualenv/lib/python3.3/site-packages/postgresql/driver/pq3.py&quot;, line 514, in raise_client_error
      raise client_error
  postgresql.exceptions.ClientCannotConnectError: could not establish connection to server
    CODE: 08001
    LOCATION: CLIENT
  CONNECTION: [failed]
    failures[0]:
      socket'/var/run/postgresql'
      Traceback (most recent call last):
        File &quot;/home/milosz/devel/project_great/.virtualenv/lib/python3.3/site-packages/postgresql/protocol/client3.py&quot;, line 136, in connect
          self.socket = self.socket_factory(timeout = timeout)
        File &quot;/home/milosz/devel/project_great/.virtualenv/lib/python3.3/site-packages/postgresql/python/socket.py&quot;, line 64, in __call__
          s.connect(self.socket_connect)
      PermissionError: [Errno 13] Permission denied
  
      The above exception was the direct cause of the following exception:
  
      postgresql.exceptions.ConnectionRejectionError: Permission denied
        CODE: 08004
        LOCATION: CLIENT
  CONNECTOR: [Unix] pq://project_great@[unix::var:run:postgresql]/project_great
    category: None
  DRIVER: postgresql.driver.pq3.Driver
  </code></pre>
  <p>Since the parameters to the two connections are ostensibly the same and my permissions on the socket and its containing directory are fairly open, I do not know what the issue is. Using TCP is not a solution; I want to use unix domain sockets. The <a href="http://python.projects.pgfoundry.org/docs/1.0/driver.html#connection-keywords" rel="nofollow noreferrer">py-postgresql documentation</a> indicates that connecting using unix domain sockets should work.</p>
  <h1>Configuration:</h1>
  <p><strong>pg_hba.conf:</strong></p>
  <pre><code># TYPE   DATABASE  USER      ADDRESS             METHOD  OPTION
  local    all       all                           peer    map=default
  </code></pre>
  <p><strong>pg_ident.conf:</strong></p>
  <pre><code># MAPNAME       SYSTEM-USERNAME         PG-USERNAME
  default         postgres                postgres
  default         milosz                  project_great
  </code></pre>
  <p><strong>postgresql.conf:</strong></p>
  <pre><code>...
  port = 5432
  unix_socket_directories = '/var/run/postgresql'
  ...
  </code></pre>
  <p>Here are the permissions on my socket directory:</p>
  <pre><code>$ ll /var/run/postgresql/
  total 8
  drwxrwsr-x  2 postgres postgres 100 May 17 00:20 ./
  drwxr-xr-x 31 root     root     900 May 17 00:41 ../
  -rw-r--r--  1 postgres postgres   5 May 17 00:20 9.3-main.pid
  srwxrwxrwx  1 postgres postgres   0 May 17 00:20 .s.PGSQL.5432=
  -rw-------  1 postgres postgres  70 May 17 00:20 .s.PGSQL.5432.lock
  </code></pre>
  <p>The PostgreSQL user <code>project_great</code> has been granted all privileges on the database <code>project_great</code> and both the user and the database exist.</p>
  <p>I do not have a <code>~/.pgpass</code>.</p>
  <h1>Environment:</h1>
  <ul>
  <li>Ubuntu 13.10</li>
  <li>Python 3.3</li>
  <li>PostgreSQL 9.3</li>
  <li>py-postgresql 1.1.0</li>
  </ul>