PostgreSQL connection refused in Django - solutions

Answered
Jan 05, 2026 1517 views 1 answers
43

My Django app cannot connect to PostgreSQL. I get "connection refused" error. PostgreSQL is installed and running.

F
Asked by fatima_dev
Silver 169 rep

1 Answer

9

This is usually a configuration issue. Here's how to fix it:

Check PostgreSQL is listening

# Check PostgreSQL status
sudo systemctl status postgresql
# Check listening ports
sudo netstat -tlnp | grep postgres

Configure pg_hba.conf

# Edit pg_hba.conf
sudo nano /etc/postgresql/14/main/pg_hba.conf
# Add or modify:
local   all   all   md5
host    all   all   127.0.0.1/32   md5

Django settings

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'your_db',
        'USER': 'your_user',
        'PASSWORD': 'your_password',
        'HOST': 'localhost',  # or '127.0.0.1'
        'PORT': '5432',
    }
}
O
Answered by omar_linux 1 week, 2 days ago
Platinum 593 rep

Your Answer

You need to be logged in to answer questions.

Log In to Answer