Could NOT connect t...
 
Share:
Notifications
Clear all

Could NOT connect to PostgreSQL server Django LightSail


Neha
 Neha
(@asha)
Member Admin
Joined: 1 year ago
Posts: 27
Topic starter  

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

its my list of databases:

                                  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)

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'
    }
}

Quote
Topic Tags
myTechMint
(@mytechmint)
Member Moderator
Joined: 1 year ago
Posts: 29
 

There is 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.

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'
    }
}

Neha liked
ReplyQuote