Can't connect the postgreSQL with psycopg2

Your libpq, which is used by psycopg2 expects Postgres socket to be in /var/run/postgresql/ but when you install Postgres from source it is by default it in /tmp/.

Check if there is a file /tmp/.s.PGSQL.5432 instead of /var/run/postgresql/.s.PGSQL.5432. Try:

conn=psycopg2.connect(
  database="mydb",
  user="postgres",
  host="/tmp/",
  password="123"
)

Only this solved my problem, make a symbolic link to the /tmp/.s.PGSQL.5432:

sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432

Thanks to, Sukhjit Singh Sehra - s-postgresql-server-is-running


Try change port to 5433 instead of 5432