无法将postgreSQL与psycopg2连接 [英] Can't connect the postgreSQL with psycopg2

查看:152
本文介绍了无法将postgreSQL与psycopg2连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次找不到有关某些技术问题的答案
这是我的问题:

It's the first time that I can't find the answer about some tech problems Here's my problems:

>> conn=psycopg2.connect(database="mydb", user="postgres", password="123",port=5432)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
psycopg2.OperationalError: 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"?




  1. 我的postgreSQL正在运行

  2. 我的监听端口肯定是5432

  3. root @ lanston-laptop:〜#psql -l
    密码:




                                       List of databases
         Name      |  Owner   | Encoding | Collation  |   Ctype    |   Access privileges 
    ---------------+----------+----------+------------+------------+-----------------------
     checkdatabase | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
     mydb          | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
     postgres      | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
     template0     | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
                   |          |          |            |            | postgres=CTc/postgres
     template1     | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
                   |          |          |            |            | postgres=CTc/postgres

非常感谢!

推荐答案

您的psycopg2使用的libpq期望Postgres套接字位于 / var / run / postgresql / 中,但是从源代码安装Postgres时是默认为 / tmp /

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/.

检查是否有文件 / tmp / .s.PGSQL.5432 而不是 /var/run/postgresql/.s.PGSQL.5432 。尝试:

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"
)

这篇关于无法将postgreSQL与psycopg2连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆