无法使用Bitnami Django堆栈连接到Postgres数据库 [英] Can't connect to Postgres database with Bitnami Django stack

查看:69
本文介绍了无法使用Bitnami Django堆栈连接到Postgres数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直遇到无法连接数据库的问题:

I keep running into the problem of not being able to connect to the database:

psycopg2.OperationalError: could not connect to server: No such file or directory

服务器是否在本地运行并接受Unix域套接字"/tmp/.s.PGSQL.5432"上的连接?

我读了一些书,看来这是一个很普遍的问题,大多数人通过检查端口是否正确来解决,即在setup.py中将5432更改为5433.但这似乎不是我的问题-在/opt/bitnami/postgresql目录中,我看到.s.PGSQL.5432.我可以登录到psql,它似乎可以正常工作.我认为默认的数据库名称是postgresql,但我也尝试使用一个名为djangostack的数据库,但也没有用.我在Django的setting.py中的数据库信息如下:

I did some reading and it seems like it’s a quite common problem that most people fix by checking that the port is correct, ie from changing 5432 to 5433 in their setup.py. But this does not seem to be my problem – in the /opt/bitnami/postgresql directory i see .s.PGSQL.5432. I can log into psql and it seems to work correctly. I think the default database name is postgresql, but i also tried it with the one called djangostack and it didn’t work either. My database information in Django's setting.py looks like this:

DATABASES = {
'default': {
    'ENGINE': 'postgresql_psycopg2', #'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'postgres',                      # Or path to database file if using sqlite3.
    'USER': 'postgres',                      # Not used with sqlite3.
    'PASSWORD': 'bitnami',                  # Not used with sqlite3.
    'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '5432',                      # Set to empty string for default. Not used with sqlite3.
}

我在/tmp/目录中查找,那里没有任何东西,无论是隐藏的还是其他的东西.应该有吗?有人知道我在做什么错吗?我愚蠢地重写了原始示例项目,因此看不到那里的设置.

I look in the /tmp/ directory and there isn’t anything there, hidden or otherwise. Is there supposed to be? Does anyone know what I’m doing wrong? I stupidly overwrote the original example project so I can’t see what the settings were there.

非常感谢,亚历克斯

推荐答案

因此PostgreSQL套接字位于/opt/bitnami/postgresql 中,但是您的 libpq (C库(psycopg2 包装好的)正在寻找/tmp 中的套接字,对吗?尝试更改 HOST 设置以指向正确的套接字位置:

So the PostgreSQL socket is in /opt/bitnami/postgresql but your libpq (the C library that psycopg2 wraps) is looking for the socket in /tmp, right? Try changing the HOST setting to point at the proper socket location:

'default': {
    'ENGINE':   'postgresql_psycopg2',
    'NAME':     'postgres',
    'USER':     'postgres'
    'PASSWORD': 'bitnami',
    'HOST':     '/opt/bitnami/postgresql/.s.PGSQL.5432', # <-------
    'PORT':     '5432',
}

或此:

'default': {
    'ENGINE':   'postgresql_psycopg2',
    'NAME':     'postgres',
    'USER':     'postgres'
    'PASSWORD': 'bitnami',
    'HOST':     '/opt/bitnami/postgresql', # <-------
    'PORT':     '5432',
}

您可能还想更改PostgreSQL密码.

And you might want to change the the PostgreSQL password too.

这篇关于无法使用Bitnami Django堆栈连接到Postgres数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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