Forums

OperationalError: Could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

When I try to deploy my first website on Pythonanywhere, Im getting this error after I followed carefully all the steps. I didnt had any previous errors before, everything went well till this moment.

From what I read on another topics, it's related with my database(postgreSQL) of my project, but no clear explanation about how to solve it.

My settings file looks like this:

ALLOWED_HOSTS = ['mywebsite.pythonanywhere.com']

DATABASES = { 'default': {

    'ENGINE': 'django.db.backends.postgresql',

    'NAME': 'db.portfolio',

    'USER': 'postgres',

    'PASSWORD': '*******',

    'HOST': 'localhost',

   'PORT': '5432',
}

}

(I already tried to change 'localhost' to 'mywebsite.pythonanywhere.com' and '127.0.0.1' but the error remains). Did someone had the same issue or have any ideas how to connect my database to pythonanywhere?

Thanks!

Hi, you need a paid account to use Postgres on PythonAnywhere. You can read more here https://help.pythonanywhere.com/pages/Postgres/

Thank you pafk! Do you know if I change my database from postgreSQL to sqlite3, it will works or I still need to have a paid account for this case?

Yes, you can use either SQLite or MySQL on free account.