PostgreSQL connection refused in Django - solutions
Answered
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
Platinum
•
593 rep
Your Answer
You need to be logged in to answer questions.
Log In to Answer