What do I do to fix my PostgreSQL database connection problem in Django?

247 Views Asked by At

I am trying to connect my Django project to a PostgreSQL database I created on AWS but I keep getting this error message each time I run py manage.py runserver.
Here is the error message:

django.db.utils.OperationalError: connection to server at "database-1.ce7oz69tjzjc.us-east-1.rds.amazonaws.com" (52.3.150.111), port 5432 failed: Connection timed out (0x0000274C/10060)
        Is the server running on that host and accepting TCP/IP connections?

I followed the tutorial on w3school and followed all instructions. I created a PostgreSQL database then I updated my settings with the following:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'codekeen',
        'USER': 'baseuser',
        'PASSWORD': 'database',
        'HOST': 'database-1.ce7oz69tjzjc.us-east-1.rds.amazonaws.com',
        'PORT': '5432'
    }
}

as I was told to, but I keep getting the error each time try migrating or running the server. What do I do to fix this?

1

There are 1 best solutions below

1
flopit goes On

First of all, make sure that postgresql is up and running. You can check with systemctl status postgresql-xx where xx is your postgresql version. After that,You need to allow TCP/IP connections to be able to connect postgresql database. Open the postgresql.conf file

vim /etc/postgresql/8.2/main/postgresql.conf

or

vim /var/lib/pgsql/data/postgresql.conf

And set the listen addresses to "*" or IP addresses.

listen_addresses='*'

or

listen_addresses='xxx.xx.x.x'