2

I have a virtual machine running Ubuntu Server and I want to set a connection using Django in my pc and a postgre's database in Ubuntu Server. This is my first time developing a database in server and I don't know if this is the correct way.



I get this:

connection = Database.connect(**conn_params) File "....\ProyectoFinalDjango\entorno_virtual\lib\site-packages\psycopg2_init_.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError: connection to server at "192.168.1.3", port 5432 failed: Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections?



I have this in my postgresql.conf file:

Connection Settings  
listen_addresses = "*"          # what IP address(es) to listen on;
                                # comma-separated list of addresses;
                                # defaults to 'localhost'; use '*' for all
                                # (change requires restart)
port = 5432                     # (change requires restart)
max_connections = 100           # (change requires restart)


This is my pg_hba.conf file:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             all                     md5

host    all             postgres        all                     md5
# IPv6 local connections:
host    all             all             ::1/128                     md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5


This is my settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'redsocial',
        'USER': 'postgres',
        'PASSWORD': 'abcd',
        'HOST': '192.168.1.3',
        'PORT': '5432',
    }
}


I have tried restart PostgreSQL but it doesn't work and it is running in port 5432

$ sudo netstat -nl | grep postgres
unix  2      [ ACC ]     STREAM     LISTENING     38188    /var/run/postgresql/.s.PGSQL.5432


I can do a ping with it and connect using cmd in Windows, but I can't stablish a connection with Django.

Br0k3nS0u1
  • 51
  • 5

0 Answers0