Psycopg2 peer authentication for user postgres
<p>I seem to have correctly installed PostgreSQL 9.5.5. and Psycopg2 on Ubuntu 16.04, and can log in via:</p>

<pre><code>sudo -u postgres psql
</code></pre>

<p>If I then issue <code>\conninfo</code>, I get the following:</p>

<pre><code>You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
</code></pre>

<p>Surely I should be able to connect via psycopg2 in the same fashion as shown <a href="http://initd.org/psycopg/docs/usage.html" rel="noreferrer">here</a>, but the script:</p>

<pre><code>#!/usr/bin/python
import psycopg2
conn = psycopg2.connect("dbname=postgres user=postgres") 
conn.close()
</code></pre>

<p>gives me:</p>

<pre><code>psycopg2.OperationalError: FATAL:  Peer authentication failed for user "postgres"
</code></pre>

<p>I only want PostgreSQL for personal usage, so I don't want to enable TCP authentication. </p>

<p>How do I correctly use peer authentication with user "postgres" in Psycopg2?</p>