我花了几个小时来解决这些问题,但没有达到任何目的.网上有几个关于这个问题的话题,但没有一个说明是解决这个问题的绝对事情.
我刚刚安装了postgresql,以便在我的django项目中使用它.
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2", # Add "postgresql_psycopg2", "postgresql", "mysql", "sqlite3" or "oracle".
"NAME": "name", # Or path to database file if using sqlite3.
"USER": "postgres", # Not used with sqlite3.
"PASSWORD": "pass", # 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.
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的settings.py,错误就是这样
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"?
Run Code Online (Sandbox Code Playgroud)
有人有解决方案吗?
Tom*_*zky 16
你需要找到一个postgres套接字.检查主postgres进程pid(ps auxw | grep postgres)并列出其打开的unix套接字(lsof -p [PID_OF_POSTGRES_PROCESS] | grep unix).将此路径写入HOST选项settings.py.
从分发包(apt-get install postgresql)安装Postgres 会更容易(例如,空的HOST settings.py可以工作)并且更安全,因为您的发行版将为您安装安全更新.
Bre*_*inn 12
这是另一种可能性:如果您在现有版本上安装了新版本的PostgreSQL,安装程序可能已为其分配了非标准端口号.
Django希望PostgreSQL能够侦听端口5432.即使您使用的是Unix套接字,套接字也会以端口号命名,所以这仍然很重要!
检查/etc/postgresql/<version>/main/postgresql.conf线路port = nnnn.如果这个数字不是5432,那那就是你的问题.另一个指标是使用非标准端口号/var/run/postgresql调用您的套接字文件.s.PGSQL.5433.
要修复它,您可以编辑端口号postgresql.conf以使用默认值(5432),或者如果需要它在非标准端口号上运行,则DATABASE_PORT = 'nnnn'在django中设置settings.py.
感谢Erik Forsberg的指针!
| 归档时间: |
|
| 查看次数: |
13822 次 |
| 最近记录: |