I seem to have correctly installed PostgreSQL 9.5.5. and Psycopg2 on Ubuntu 16.04, and can log in via:
sudo -u postgres psql
If I then issue \conninfo
, I get the following:
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
Surely I should be able to connect via psycopg2 in the same fashion as shown here, but the script:
#!/usr/bin/python
import psycopg2
conn = psycopg2.connect("dbname=postgres user=postgres")
conn.close()
gives me:
psycopg2.OperationalError: FATAL: Peer authentication failed for user "postgres"
I only want PostgreSQL for personal usage, so I don't want to enable TCP authentication.
How do I correctly use peer authentication with user "postgres" in Psycopg2?