PostgreSQL external db in Django

3

I have a Django project and I use a postgresql database in local and it goes perfectly with the module psycopg2, now, I put an external database and when I do a migrate it gives the following error.

django.db.utils.OperationalError: FATAL:  no pg_hba.conf entry for host "local-IP", user "postgres", database "chewbacca_db", SSL on
FATAL:  no pg_hba.conf entry for host "local-IP", user "postgres", database "my_db", SSL off

and in my project django I have it like that ... as always

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'my_db',
        'USER': 'postgres',
        'PASSWORD': 'password',
        'HOST': 'external-server-IP',
        'PORT': '5432'
    }
}

I do not understand why I get the IP address of the local server in the error ... if in settings.py there is no such IP anywhere.

SOLUTION:

The postgresql.conf file has been modified by changing listenaddresses='localhost' by listenaddresses='*' and in the file pg_hba.conf has been added in the section of IPv4 host all all 0.0.0.0/0 md5 immediately followed by a restart of the service sudo service postgresql restart and voli.

    
asked by RuralGalaxy 10.05.2016 в 13:47
source

1 answer

2

You have to check several things:

  • That the server where the database is hosted does not have an active firewall or that if it has an open port 5432 (or whatever is configured, the 5432 is the default port).
  • That in the pg_hba.conf file there is an entry for the IP where the program is in python. There are many possibilities (it can be enabled for one or more users or all, for one or more databases or all, for certain IP or IP ranges.) After modifying pg_hba.conf, you must restart the postgresql
  • answered by 11.05.2016 / 02:40
    source