0

When I`m trying to connect Django Server to PostgreSQL db there is an error: " port 5433 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? "

I`m using Windows 10, Pycharm, Debian

Settings in Django:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'ps_store_db',
        'USER': 'zesshi',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '5433',
    }
}

Tried to check connection with DBeaver and all`s good there, but still cant connect with Django

My firewall is off, i was trying to change from 5432 to 5433

Dbeaver connection

Dbeaver connection 2

Zesshi
  • 435
  • 12

2 Answers2

0

Try restarting/reinstalling postgres. Most likely DBeaver has blocked the port that's why you are not able to connect from django. (Sorry for posting answer, i am unable to comment yet)

Sourabh Burse
  • 359
  • 2
  • 7
  • This is a useless comment and/or answer. DBeaver has nothing to do with the port that the Postgres server is listening on, it just another client like Django. – Adrian Klaver Dec 02 '22 at 19:44
  • I might be wrong but this looks like a similar case: https://stackoverflow.com/questions/37307346/is-the-server-running-on-host-localhost-1-and-accepting-tcp-ip-connections – Sourabh Burse Dec 02 '22 at 19:49
  • That question and answer have nothing to do with DBeaver, it is a server issue. – Adrian Klaver Dec 02 '22 at 19:52
  • I download DBeaver after this problem to check if connection is normal – Zesshi Dec 02 '22 at 19:53
  • Go inside bin folder in C drive where Postgres is installed. run following command in git bash or Command prompt: `pg_ctl.exe restart -D ""` Ex: `pg_ctl.exe restart -D "C:\Program Files\PostgreSQL\9.6\data"` Another way: type "services.msc" in run popup(windows + R). This will show all services running Select Postgres service from list and click on start/stop/restart. – Sourabh Burse Dec 02 '22 at 20:06
  • I tried this way as well mate, restarting still cant help – Zesshi Dec 02 '22 at 20:41
0

The default port of the PG database is 5432. If you need to change this port, you need to edit the postgresql.conf file and restart the database service before the client can access it. You also need to check the pg_hba.conf file. The recommended configuration is as follows:

host all all 0.0.0.0/0 md5
dogs Cute
  • 564
  • 3
  • 9
  • I would not call that a recommended configuration as that opens the server to connections from anywhere to any database in the cluster and from any database user and that is dangerous. – Adrian Klaver Dec 03 '22 at 16:47
  • @AdrianKlaver IP and database can be fixed for finer access control – dogs Cute Dec 03 '22 at 21:57