Reputation: 343
I have a Django app running on hosting server. I am using postgres database which is running on different server. The app is working properly in my local machine but in hosting server, the app is running but any functionality is not working which is associated with database. For example, user can not authenticated while login even the username and password is correct. I am receiving a error saying "could not connect to server: Connection refused Is the server running on host xxx.xxx.xxx.xxx and accepting TCP/IP connections on port 5432?" My settings for database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'DB_NAME',
'USER': 'USER',
'PASSWORD': '*****',
'HOST': 'IP_ADDRESS',
'PORT': 'PORT',
}
}
N:B I have given permission to the postgres database. I can access the db from local machine
Upvotes: 2
Views: 2384
Reputation: 123
Try with following database configuration snippet in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '******',
'USER': '****',
'PASSWORD': '****',
'HOST': '***.***.***.***',
'PORT': '5432'
},
}
Replace *** with your database credentials
Make sure you have already installed psycopg2
through package manager like pip
listen_addresses = “localhost”
to “ * ”
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
host all all ::/0 md5
# Allow replication connections from localhost, by a user with the
host replication all 0.0.0.0/0 md5
host replication all ::/0 md5
Upvotes: 2