无法连接到 postgresql 服务器 django Lightsail [英] could not connect to postgresql server django lightsail

查看:72
本文介绍了无法连接到 postgresql 服务器 django Lightsail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/opt/bitnami/postgresql/.s.PGSQL.5432/.s.PGSQL.5432"?

这是我的数据库列表:

                                  List of databases
    Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
------------+----------+----------+-------------+-------------+-----------------------
 postgres   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
            |          |          |             |             | postgres=CTc/postgres
 template1  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
            |          |          |             |             | postgres=CTc/postgres
(3 rows)

及其 settings.py 的 postgres 配置部分:

and its the postgres config section of settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'HOST': '/opt/bitnami/postgresql/.s.PGSQL.5432',
        'PORT': '5432',
        'USER': 'postgres',
        'PASSWORD': 'mypass'
    }
}

我也试过回答这两个问题

I also tried answers to these two questions

  • Can't connect to Postgres database with Bitnami Django stack
  • Can't connect the postgreSQL with psycopg2 but none of them helped.

这里是pip list:

 psycopg2-binary==2.8.6

我的调试模式是错误的:

my debug mode is false:

DEBUG = False

在允许的主机中,我有我的私有 IP:

and in allowed hosts I have my private IP:

 ALLOWED_HOSTS = ['XXX.XXX.XXX.XXX']

推荐答案

Bitnami 文档中存在混淆.文件回溯说它找不到文件:.s.PGSQL.5432该文件实际上位于 /tmp 文件夹中.(不要问)

There is a confusion in Bitnami documentation. The file traceback says it can't find the file: .s.PGSQL.5432 This file is actually located in /tmp folder. (don't ask)

如果您将 settings.py 更改为将 /tmp 文件夹作为主机,它将起作用:

If you change your settings.py to have a /tmp folder as a Host it will work:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'postgres',
        # 'HOST': '/opt/bitnami/postgresql',
        'HOST': '/tmp/',
        'PORT': '5432',
        'USER': 'postgres',
        'PASSWORD': '1234'
    }
}

另一种选择是创建符号链接:

Another option is to create a symlink:

sudo ln -s /tmp/.s.PGSQL.5432 /opt/bitnami/postgresql/.s.PGSQL.5432

但我还没有测试过.

这篇关于无法连接到 postgresql 服务器 django Lightsail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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