1

The problem is that I can't connect to localhost database (5432 port), I'm really green on this Postgresql and I still don't understand these databases and how they do work. My code for connection :

import psycopg2
try:
    connection = psycopg2.connect(user = "sysadmin",
                                  password = "pynative@#29",
                                  host = "127.0.0.1",
                                  port = "5432",
                                  database = "postgres_db")
    cursor = connection.cursor()
    # Print PostgreSQL Connection properties
    print ( connection.get_dsn_parameters(),"\n")
    # Print PostgreSQL version
    cursor.execute("SELECT version();")
    record = cursor.fetchone()
    print("You are connected to - ", record,"\n")
except (Exception, psycopg2.Error) as error :
    print ("Error while connecting to PostgreSQL", error)
finally:
    #closing database connection.
        if(connection):
            cursor.close()
            connection.close()
            print("PostgreSQL connection is closed")

Also I did some port forwarding on my localhost rooter.

Port Forwarding photo

And I used the 'nmap' software for ports that are running as i understand? The results I got are here NMAP

DzITC
  • 869
  • 1
  • 9
  • 23

0 Answers0