Search code examples
pythondjangopostgresqldjango-database

django connect remote postgresql


Trying to connect to a remote server, serving my posgresql

My settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydatabase',
        'USER': 'mydatabaseuser',
        'PASSWORD': 'mypassword',
        'HOST': 'ubuntu@username.host.com',
        'PORT': '5432',
    }
}

Getting error:

django.db.utils.OperationalError: could not translate host name "ubuntu@hostname.host.com" to address: Name or service not known

Where the hostname and host is of course not hostname and host, just using for this example.


Solution

  • For the host, you have to pass the ip address or the domain name of your postgresql host instance.

    'HOST': 'host.com'
    

    or

    'HOST': '<ip_address>'