简体   繁体   English

流浪者上的Django,psycopg2 OperationalError:无法连接到服务器:没有这样的文件或目录

[英]Django on vagrant, psycopg2 OperationalError: could not connect to server: No such file or directory

On vagrant box, installed postgres via apt-get install python-psycopg2 . 在无业游民的盒子上,通过apt-get install python-psycopg2安装了postgres。 Tested import successfully. 测试导入成功。

$ python
Python 2.6.5 (r265:79063, Oct  1 2012, 22:04:36) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> exit()

Django settings file: Django设置文件:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/vagrant/v-root/projects/tdg/tdg/mydata.db',                      # Or path to database file if using sqlite3.
        'USER': 'username',                      # Not used with sqlite3.
        'PASSWORD': 'password',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

Having an issue with postgres_psycopg2 not being found on new vagrant box. 在新的流浪者盒子上找不到postgres_psycopg2的问题。

$ python manage.py shell
Python 2.6.5 (r265:79063, Oct  1 2012, 22:04:36) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.db import connection
>>> cursor = connection.cursor()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
    self.connection = Database.connect(**conn_params)
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"?

>>> 

I ran a netstat —listen and I did not see port 5432 listening. 我运行了netstat —listen听了,但没有看到5432端口在监听。 Only 22 (SSH) and 8000 (Django app) are listening. 只有22(SSH)和8000(Django应用程序)在监听。

You didn't quite install postgres - you just installed psycopg2, which is a python client for postgres. 您没有完全安装postgres-您刚刚安装了psycopg2,这是postgres的python客户端。 You'll need to install and run postgres like so: 您需要像这样安装和运行postgres:

apt-get install postgresql
/etc/init.d/postgresql start

(You will probably also need to log into it and create yourself a database for your project to talk to) (您可能还需要登录到该数据库并为您的项目创建一个自己的数据库以供交谈)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Psycopg2 操作错误:无法连接到服务器:没有这样的文件或目录 - Psycopg2 Operational Error: could not connect to server : No such file or directory django.db.utils.OperationalError:无法连接到服务器:没有这样的文件或目录 - django.db.utils.OperationalError: could not connect to server: No such file or directory Django-OperationalError:无法连接到服务器 - Django - OperationalError: could not connect to server Docker- django 在连接到 postgres 时抛出错误:psycopg2.OperationalError:无法连接到服务器:连接被拒绝 - Docker- django throws error while connecting to postgres: psycopg2.OperationalError: could not connect to server: Connection refused (psycopg2.OperationalError)无法连接到服务器:连接被拒绝是服务器 - (psycopg2.OperationalError) could not connect to server: Connection refused Is the server psycopg2.OperationalError:无法连接到服务器:连接被拒绝 - psycopg2.OperationalError: could not connect to server: Connection refused 在 Dockerfile 中运行“manage.py compilemessages”给出“django.db.utils.OperationalError:无法连接到服务器:没有这样的文件或目录” - Running “manage.py compilemessages” in Dockerfile gives “django.db.utils.OperationalError: could not connect to server: No such file or directory” 连接时出现OperationalError-Psycopg2 - OperationalError When Connecting - Psycopg2 psycopg2.OperationalError:无法使用 psycopg2 和 docker 将主机名转换为地址 - psycopg2.OperationalError: could not translate host name to address using psycopg2 and docker PythonAnywhere,Flask 应用程序,heroku postgres psycopg2.OperationalError:无法连接到服务器:连接被拒绝 - PythonAnywhere, Flask application, heroku postgres psycopg2.OperationalError: could not connect to server: Connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM